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

Further footprint optimization in parser and scanner.

This commit is contained in:
John Camelon 2004-05-28 03:25:16 +00:00
parent fb764be87a
commit cf2a2a38e8
21 changed files with 231 additions and 213 deletions

View file

@ -13,7 +13,6 @@ import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -2039,28 +2038,28 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( macros.hasNext() ); assertFalse( macros.hasNext() );
assertEquals( swap.getName(), "SWAP"); //$NON-NLS-1$ assertEquals( swap.getName(), "SWAP"); //$NON-NLS-1$
assertEquals( swap.getMacroType(), IMacroDescriptor.MacroType.FUNCTION_LIKE ); assertEquals( swap.getMacroType(), IMacroDescriptor.MacroType.FUNCTION_LIKE );
List params = swap.getParameters(); String [] params = swap.getParameters();
assertEquals( params.size(), 2 ); assertEquals( params.length, 2 );
assertEquals( params.get(0), "x"); //$NON-NLS-1$ assertEquals( params[0], "x"); //$NON-NLS-1$
assertEquals( params.get(1), "y"); //$NON-NLS-1$ assertEquals( params[1], "y"); //$NON-NLS-1$
assertEquals( swap.getCompleteSignature().trim(), "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); //$NON-NLS-1$ String completeSignature = swap.getCompleteSignature().trim();
assertEquals( completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); //$NON-NLS-1$
assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); //$NON-NLS-1$ assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); //$NON-NLS-1$
Iterator tokens = swap.getTokenizedExpansion().iterator(); IToken [] tokens = swap.getTokenizedExpansion();
validateToken( (IToken)tokens.next(), IToken.tLBRACE); validateToken( tokens[0], IToken.tLBRACE);
validateIdentifier( (IToken)tokens.next(), "x"); //$NON-NLS-1$ validateIdentifier( tokens[1], "x"); //$NON-NLS-1$
validateToken( (IToken) tokens.next(), IToken.tBITORASSIGN ); validateToken( tokens[2], IToken.tBITORASSIGN );
validateIdentifier( (IToken) tokens.next(), "y"); //$NON-NLS-1$ validateIdentifier( tokens[3], "y"); //$NON-NLS-1$
validateToken( (IToken) tokens.next(), IToken.tSEMI ); validateToken( tokens[4], IToken.tSEMI );
validateIdentifier( (IToken) tokens.next(), "y"); //$NON-NLS-1$ validateIdentifier( tokens[5], "y"); //$NON-NLS-1$
validateToken( (IToken) tokens.next(), IToken.tBITORASSIGN ); validateToken( tokens[6], IToken.tBITORASSIGN );
validateIdentifier( (IToken)tokens.next(), "x"); //$NON-NLS-1$ validateIdentifier( tokens[7], "x"); //$NON-NLS-1$
validateToken( (IToken) tokens.next(), IToken.tSEMI ); validateToken( tokens[8], IToken.tSEMI );
validateIdentifier( (IToken)tokens.next(), "x"); //$NON-NLS-1$ validateIdentifier( tokens[9], "x"); //$NON-NLS-1$
validateToken( (IToken) tokens.next(), IToken.tBITORASSIGN ); validateToken( tokens[10], IToken.tBITORASSIGN );
validateIdentifier( (IToken) tokens.next(), "y"); //$NON-NLS-1$ validateIdentifier( tokens[11], "y"); //$NON-NLS-1$
validateToken( (IToken) tokens.next(), IToken.tSEMI ); validateToken( tokens[12], IToken.tSEMI );
validateToken( (IToken) tokens.next(), IToken.tRBRACE ); validateToken( tokens[13], IToken.tRBRACE );
assertFalse( tokens.hasNext() );
} }
/** /**
* @param token * @param token

View file

@ -26,7 +26,6 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException; import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
/** /**
* @author jcamelon * @author jcamelon
@ -688,19 +687,19 @@ public class ScannerTestCase extends BaseScannerTest
IMacroDescriptor descriptor= IMacroDescriptor descriptor=
scanner.getDefinition("GO"); //$NON-NLS-1$ scanner.getDefinition("GO"); //$NON-NLS-1$
List parms= descriptor.getParameters(); String [] parms= descriptor.getParameters();
assertNotNull(parms); assertNotNull(parms);
assertTrue(parms.size() == 1); assertTrue(parms.length == 1);
String parm1= (String) parms.get(0); String parm1= parms[0];
assertTrue(parm1.equals("x")); //$NON-NLS-1$ assertTrue(parm1.equals("x")); //$NON-NLS-1$
List expansion= descriptor.getTokenizedExpansion(); IToken [] expansion= descriptor.getTokenizedExpansion();
assertNotNull(parms); assertNotNull(parms);
assertTrue(expansion.size() == 3); assertTrue(expansion.length == 3);
assertTrue(((SimpleToken) expansion.get(0)).getType() == IToken.tIDENTIFIER); assertTrue((expansion[0]).getType() == IToken.tIDENTIFIER);
assertTrue(((SimpleToken) expansion.get(0)).getImage().equals("x")); //$NON-NLS-1$ assertTrue((expansion[0]).getImage().equals("x")); //$NON-NLS-1$
assertTrue(((SimpleToken) expansion.get(1)).getType() == IToken.tPLUS); assertTrue((expansion[1]).getType() == IToken.tPLUS);
assertTrue(((SimpleToken) expansion.get(2)).getType() == IToken.tINTEGER); assertTrue((expansion[2]).getType() == IToken.tINTEGER);
assertTrue(((SimpleToken) expansion.get(2)).getImage().equals("1")); //$NON-NLS-1$ assertTrue((expansion[2]).getImage().equals("1")); //$NON-NLS-1$
validateIdentifier("y"); //$NON-NLS-1$ validateIdentifier("y"); //$NON-NLS-1$
validateToken(IToken.tASSIGN); validateToken(IToken.tASSIGN);
@ -737,13 +736,13 @@ public class ScannerTestCase extends BaseScannerTest
validateEOF(); validateEOF();
IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$ IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$
List params= macro.getParameters(); String [] params= macro.getParameters();
assertNotNull(params); assertNotNull(params);
assertTrue(params.size() == 7); assertTrue(params.length == 7);
List tokens= macro.getTokenizedExpansion(); IToken [] tokens= macro.getTokenizedExpansion();
assertNotNull(tokens); assertNotNull(tokens);
assertTrue(tokens.size() == 15); assertTrue(tokens.length == 15);
initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$ initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$
validateIdentifier("printf"); //$NON-NLS-1$ validateIdentifier("printf"); //$NON-NLS-1$
@ -1090,9 +1089,9 @@ public class ScannerTestCase extends BaseScannerTest
validateEOF(); validateEOF();
IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$ IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$
assertNotNull( macro ); assertNotNull( macro );
assertEquals( macro.getParameters().size(), 1 ); assertEquals( macro.getParameters().length, 1 );
assertEquals( (String)macro.getParameters().get(0), "Y" ); //$NON-NLS-1$ assertEquals( macro.getParameters()[0], "Y" ); //$NON-NLS-1$
assertEquals( macro.getTokenizedExpansion().size(), 0 ); assertEquals( macro.getTokenizedExpansion().length, 0 );
} }
public void testBug36047() throws Exception public void testBug36047() throws Exception

View file

@ -10,7 +10,6 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.util.List;
/** /**
* @author jcamelon * @author jcamelon
* *
@ -42,10 +41,10 @@ public interface IMacroDescriptor {
public MacroType getMacroType(); public MacroType getMacroType();
// parameters for macros of type FUNCTION_LIKE // parameters for macros of type FUNCTION_LIKE
public List getParameters(); public String[] getParameters();
// the RHS side of the macro separated into ITokens // the RHS side of the macro separated into ITokens
public List getTokenizedExpansion(); public IToken[] getTokenizedExpansion();
// the symbol name // the symbol name
public String getName(); public String getName();

View file

@ -9,7 +9,6 @@
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.ast; package org.eclipse.cdt.core.parser.ast;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -154,7 +153,7 @@ public interface IASTFactory
boolean isLong, boolean isLong,
boolean isSigned, boolean isSigned,
boolean isUnsigned, boolean isUnsigned,
boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms ) throws ASTSemanticException; boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map map ) throws ASTSemanticException;
public IASTFunction createFunction( public IASTFunction createFunction(
IASTScope scope, IASTScope scope,

View file

@ -10,7 +10,6 @@
package org.eclipse.cdt.core.parser.extension; package org.eclipse.cdt.core.parser.extension;
import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -62,7 +61,7 @@ public interface IASTFactoryExtension {
boolean isShort, boolean isShort,
boolean isLong, boolean isLong,
boolean isSigned, boolean isSigned,
boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms ); boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms );
public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind ); public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind );
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms ); public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms );

View file

@ -14,6 +14,7 @@ import java.util.Collections;
import java.util.Hashtable; import java.util.Hashtable;
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.BacktrackException; import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
@ -338,10 +339,10 @@ public class DeclarationWrapper implements IDeclaratorOwner
public List createASTNodes(IASTFactory astFactoryToWorkWith) throws ASTSemanticException, BacktrackException public List createASTNodes(IASTFactory astFactoryToWorkWith) throws ASTSemanticException, BacktrackException
{ {
this.astFactory = astFactoryToWorkWith; this.astFactory = astFactoryToWorkWith;
Iterator i = declarators.iterator(); if( declarators.isEmpty() ) return Collections.EMPTY_LIST;
List l = new ArrayList(); List l = new ArrayList(declarators.size());
while (i.hasNext()) for( int i = 0; i < declarators.size(); ++i )
l.add(createASTNode((Declarator)i.next())); l.add(createASTNode((Declarator)declarators.get(i)));
return l; return l;
} }
/** /**
@ -538,11 +539,11 @@ public class DeclarationWrapper implements IDeclaratorOwner
private List createParameterList(List currentParameters) throws ASTSemanticException private List createParameterList(List currentParameters) throws ASTSemanticException
{ {
List result = new ArrayList(); if( currentParameters.isEmpty() ) return Collections.EMPTY_LIST;
Iterator i = currentParameters.iterator(); List result = new ArrayList(currentParameters.size());
while (i.hasNext()) for( int i = 0; i < currentParameters.size(); ++i )
{ {
DeclarationWrapper wrapper = (DeclarationWrapper)i.next(); DeclarationWrapper wrapper = (DeclarationWrapper)currentParameters.get(i);
Iterator j = wrapper.getDeclarators(); Iterator j = wrapper.getDeclarators();
while (j.hasNext()) while (j.hasNext())
{ {
@ -555,9 +556,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
wrapper.getTypeSpecifier(), wrapper.getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
null, null, declarator.getName() == null null, null, declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine()));
? "" //$NON-NLS-1$
: declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine()));
} }
} }
return result; return result;
@ -765,16 +764,18 @@ public class DeclarationWrapper implements IDeclaratorOwner
return checkBit( IS_GLOBAL ); return checkBit( IS_GLOBAL );
} }
private Hashtable extensionParameters = new Hashtable(); private Map extensionParameters = Collections.EMPTY_MAP;
/** /**
* @param key * @param key
* @param typeOfExpression * @param typeOfExpression
*/ */
public void setExtensionParameter(String key, Object value) { public void setExtensionParameter(String key, Object value) {
if( extensionParameters == Collections.EMPTY_MAP )
extensionParameters = new Hashtable( 4 );
extensionParameters.put( key, value ); extensionParameters.put( key, value );
} }
public Hashtable getExtensionParameters() public Map getExtensionParameters()
{ {
return extensionParameters; return extensionParameters;
} }

View file

@ -353,7 +353,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
public DeclarationWrapper getDeclarationWrapper() public DeclarationWrapper getDeclarationWrapper()
{ {
Declarator d = this; Declarator d = this;
while( d.getOwner() instanceof IDeclarator ) while( d.getOwner() instanceof Declarator )
d = (Declarator)d.getOwner(); d = (Declarator)d.getOwner();
return (DeclarationWrapper)d.getOwner(); return (DeclarationWrapper)d.getOwner();
} }

View file

@ -680,7 +680,7 @@ public abstract class Parser extends ExpressionParser implements IParser
declarator.getPointerOperators(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
null, null, null, null,
declarator.getName() == null ? "" : declarator.getName(), //$NON-NLS-1$ declarator.getName(),
declarator.getInitializerClause(), declarator.getInitializerClause(),
wrapper.getStartingOffset(), wrapper.getStartingLine(), wrapper.getStartingOffset(), wrapper.getStartingLine(),
declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(),

View file

@ -10,10 +10,10 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast; package org.eclipse.cdt.internal.core.parser.ast;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMacro;
/** /**
@ -133,13 +133,13 @@ public class ASTMacro implements IASTMacro {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/ */
public List getParameters() { public String[] getParameters() {
return innerMacro.getParameters(); return innerMacro.getParameters();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/ */
public List getTokenizedExpansion() { public IToken[] getTokenizedExpansion() {
return innerMacro.getTokenizedExpansion(); return innerMacro.getTokenizedExpansion();
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.parser.ast; package org.eclipse.cdt.internal.core.parser.ast;
import java.util.Collections; import java.util.Collections;
import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -159,7 +158,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean) * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)
*/ */
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(ParserSymbolTable pst, IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms) { public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(ParserSymbolTable pst, IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms) {
if( kind == IASTGCCSimpleTypeSpecifier.Type.TYPEOF ) if( kind == IASTGCCSimpleTypeSpecifier.Type.TYPEOF )
{ {
ASTExpression typeOfExpression = (ASTExpression) extensionParms.get( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION ); ASTExpression typeOfExpression = (ASTExpression) extensionParms.get( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION );

View file

@ -12,10 +12,10 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Stack; import java.util.Stack;
import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.Enum;
@ -1885,7 +1885,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isTypename, boolean isTypename,
boolean isComplex, boolean isComplex,
boolean isImaginary, boolean isImaginary,
boolean isGlobal, Hashtable extensionParms ) throws ASTSemanticException boolean isGlobal, Map extensionParms ) throws ASTSemanticException
{ {
if( extension.overrideCreateSimpleTypeSpecifierMethod( kind )) if( extension.overrideCreateSimpleTypeSpecifierMethod( kind ))
return extension.createSimpleTypeSpecifier(pst, scope, kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary, isGlobal, extensionParms ); return extension.createSimpleTypeSpecifier(pst, scope, kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary, isGlobal, extensionParms );

View file

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.expression; package org.eclipse.cdt.internal.core.parser.ast.expression;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -475,7 +474,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
boolean isTypename, boolean isTypename,
boolean isComplex, boolean isComplex,
boolean isImaginary, boolean isImaginary,
boolean isGlobal, Hashtable extensionParms) boolean isGlobal, Map extensionParms)
throws ASTSemanticException { throws ASTSemanticException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;

View file

@ -10,8 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick; package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -189,7 +189,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple)
*/ */
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms) public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms)
{ {
return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary); return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary);
} }

View file

@ -454,11 +454,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
LookupData data = new LookupData( name ){ LookupData data = new LookupData( name ){
public TypeFilter getFilter() { public TypeFilter getFilter() {
if( t == TypeInfo.t_any ) return ANY_FILTER; if( t == TypeInfo.t_any ) return ANY_FILTER;
else {
if( filter == null ) filter = new TypeFilter( t ); if( filter == null ) filter = new TypeFilter( t );
return filter; return filter;
} }
};
private TypeFilter filter = null; private TypeFilter filter = null;
private final TypeInfo.eType t = type; private final TypeInfo.eType t = type;
}; };
@ -554,7 +552,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
public IParameterizedSymbol lookupMethodForDefinition( String name, final List parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol lookupMethodForDefinition( String name, final List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){ LookupData data = new LookupData( name ){
public List getParameters() { return params; }; public List getParameters() { return params; }
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
}; };
data.qualified = true; data.qualified = true;
@ -642,14 +640,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
LookupData data = new LookupData( name ){ LookupData data = new LookupData( name ){
public TypeFilter getFilter() { public TypeFilter getFilter() {
if( t == TypeInfo.t_any ) return ANY_FILTER; if( t == TypeInfo.t_any ) return ANY_FILTER;
else {
if( filter == null ) if( filter == null )
filter = new TypeFilter( t ); filter = new TypeFilter( t );
return filter; return filter;
}
} }
private TypeFilter filter = null; private TypeFilter filter = null;
private final TypeInfo.eType type = t;
}; };
data.qualified = true; data.qualified = true;
ParserSymbolTable.lookup( data, this ); ParserSymbolTable.lookup( data, this );
@ -776,7 +773,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
*/ */
public IParameterizedSymbol memberFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol memberFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){ LookupData data = new LookupData( name ){
public List getParameters() { return params; }; public List getParameters() { return params; }
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
public TypeFilter getFilter() { return FUNCTION_FILTER; } public TypeFilter getFilter() { return FUNCTION_FILTER; }
}; };
@ -789,7 +786,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
*/ */
public IParameterizedSymbol qualifiedFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol qualifiedFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){ LookupData data = new LookupData( name ){
public List getParameters() { return params; }; public List getParameters() { return params; }
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
public TypeFilter getFilter() { return FUNCTION_FILTER; } public TypeFilter getFilter() { return FUNCTION_FILTER; }
}; };
@ -857,11 +854,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
public Set getAmbiguities(){ return ambiguities; } public Set getAmbiguities(){ return ambiguities; }
public TypeFilter getFilter() { return typeFilter; } public TypeFilter getFilter() { return typeFilter; }
public void addAmbiguity( String name ){ public void addAmbiguity( String n ){
if( ambiguities == Collections.EMPTY_SET ){ if( ambiguities == Collections.EMPTY_SET ){
ambiguities = new HashSet(); ambiguities = new HashSet();
} }
ambiguities.add( name ); ambiguities.add( n );
} }
final private List params = paramList; final private List params = paramList;

View file

@ -1859,7 +1859,7 @@ public class ParserSymbolTable {
} }
if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){ if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
LookupData data = new LookupData( EMPTY_NAME){ LookupData data = new LookupData( EMPTY_NAME){
public List getParameters() { return parameters; }; public List getParameters() { return parameters; }
public TypeFilter getFilter() { return CONSTRUCTOR_FILTER; } public TypeFilter getFilter() { return CONSTRUCTOR_FILTER; }
private List parameters = new ArrayList( 1 ); private List parameters = new ArrayList( 1 );
}; };
@ -1892,7 +1892,7 @@ public class ParserSymbolTable {
if( !name.equals(EMPTY_NAME) ){ if( !name.equals(EMPTY_NAME) ){
LookupData data = new LookupData( "operator " + name ){ //$NON-NLS-1$ LookupData data = new LookupData( "operator " + name ){ //$NON-NLS-1$
public List getParameters() { return Collections.EMPTY_LIST; }; public List getParameters() { return Collections.EMPTY_LIST; }
public TypeFilter getFilter() { return FUNCTION_FILTER; } public TypeFilter getFilter() { return FUNCTION_FILTER; }
}; };
data.forUserDefinedConversion = true; data.forUserDefinedConversion = true;
@ -2040,9 +2040,6 @@ public class ParserSymbolTable {
private IContainerSymbol _compilationUnit; private IContainerSymbol _compilationUnit;
private ParserLanguage _language; private ParserLanguage _language;
private ParserMode _mode; private ParserMode _mode;
// private ArrayList undoList = new ArrayList();
private HashSet markSet = new HashSet();
public void setLanguage( ParserLanguage language ){ public void setLanguage( ParserLanguage language ){
_language = language; _language = language;
} }
@ -2133,7 +2130,7 @@ public class ParserSymbolTable {
//this LookupData //this LookupData
public boolean isPrefixLookup(){ return false;} //prefix lookup public boolean isPrefixLookup(){ return false;} //prefix lookup
public Set getAmbiguities() { return null; } public Set getAmbiguities() { return null; }
public void addAmbiguity(String name) { } public void addAmbiguity(String n ) { }
public List getParameters() { return null; } //parameter info for resolving functions public List getParameters() { return null; } //parameter info for resolving functions
public HashSet getAssociated() { return null; } //associated namespaces for argument dependant lookup public HashSet getAssociated() { return null; } //associated namespaces for argument dependant lookup
public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration

View file

@ -10,10 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken;
/** /**
* @author jcamelon * @author jcamelon
@ -25,6 +23,8 @@ public class DynamicMacroDescriptor implements IMacroDescriptor {
private final String name; private final String name;
private final DynamicMacroEvaluator proxy; private final DynamicMacroEvaluator proxy;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final IToken[] EMPTY_TOKEN_ARRAY = new IToken[0];
public DynamicMacroDescriptor( String name, DynamicMacroEvaluator proxy ) public DynamicMacroDescriptor( String name, DynamicMacroEvaluator proxy )
{ {
@ -41,15 +41,15 @@ public class DynamicMacroDescriptor implements IMacroDescriptor {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/ */
public List getParameters() { public String[] getParameters() {
return Collections.EMPTY_LIST; return EMPTY_STRING_ARRAY;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/ */
public List getTokenizedExpansion() { public IToken[] getTokenizedExpansion() {
return Collections.EMPTY_LIST; return EMPTY_TOKEN_ARRAY;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -10,8 +10,7 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.Iterator; import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -27,7 +26,7 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
* RHS expansion in the macro definition. * RHS expansion in the macro definition.
* @param sig The complete signature of the macro, as a string. * @param sig The complete signature of the macro, as a string.
*/ */
public FunctionMacroDescriptor( String name, List identifiers, List tokens, String expansionSignature ) public FunctionMacroDescriptor( String name, String[] identifiers, IToken[] tokens, String expansionSignature )
{ {
this.name = name; this.name = name;
identifierParameters = identifiers; identifierParameters = identifiers;
@ -36,15 +35,15 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
} }
private String name; private String name;
private List identifierParameters; private String [] identifierParameters;
private List tokenizedExpansion; private IToken [] tokenizedExpansion;
private String expansionSignature; private String expansionSignature;
private Boolean isCircular = null;
/** /**
* Returns the identifiers. * Returns the identifiers.
* @return List * @return List
*/ */
public final List getParameters() { public final String[] getParameters() {
return identifierParameters; return identifierParameters;
} }
@ -52,7 +51,7 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
* Returns the tokens. * Returns the tokens.
* @return List * @return List
*/ */
public final List getTokenizedExpansion() { public final IToken[] getTokenizedExpansion() {
return tokenizedExpansion; return tokenizedExpansion;
} }
@ -71,25 +70,23 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer( 128 ); StringBuffer buffer = new StringBuffer( 128 );
int count = getParameters().size();
int count = identifierParameters.length;
buffer.append( "MacroDescriptor with name=" + getName() + "\n" ); //$NON-NLS-1$//$NON-NLS-2$ buffer.append( "MacroDescriptor with name=" + getName() + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
buffer.append( "Number of parameters = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$ buffer.append( "Number of parameters = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
Iterator iter = getParameters().iterator();
int current = 0;
while( iter.hasNext() )
{
buffer.append( "Parameter #" + current++ + " with name=" + (String) iter.next() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
}
count = getTokenizedExpansion().size(); for( int current = 0; current < count; ++current)
iter = getTokenizedExpansion().iterator(); buffer.append( "Parameter #" + current + " with name=" + identifierParameters[current] + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
count = tokenizedExpansion.length;
buffer.append( "Number of tokens = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$ buffer.append( "Number of tokens = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
current = 0; for( int current = 0; current < count; ++current )
while( iter.hasNext() )
{ {
buffer.append( "Token #" + current++ + " is " + ((IToken)iter.next()).toString() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ buffer.append( "Token #" + current++ + " is " + tokenizedExpansion[current].toString() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
} }
return buffer.toString(); return buffer.toString();
@ -104,13 +101,11 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
StringBuffer fullSignature = new StringBuffer( "#define " ); //$NON-NLS-1$ StringBuffer fullSignature = new StringBuffer( "#define " ); //$NON-NLS-1$
fullSignature.append( name ); fullSignature.append( name );
fullSignature.append( '('); fullSignature.append( '(');
Iterator iter = getParameters().iterator();
int current = 0; for( int current = 0; current < identifierParameters.length; ++current )
while( iter.hasNext() )
{ {
if (current > 0) fullSignature.append(','); if (current > 0) fullSignature.append(',');
fullSignature.append((String)iter.next() ); fullSignature.append(identifierParameters[current] );
current++;
} }
fullSignature.append( ") "); //$NON-NLS-1$ fullSignature.append( ") "); //$NON-NLS-1$
fullSignature.append( expansionSignature ); fullSignature.append( expansionSignature );
@ -126,11 +121,33 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
if( descriptor.getParameters() == null ) return false; if( descriptor.getParameters() == null ) return false;
if( descriptor.getMacroType() != getMacroType() ) return false; if( descriptor.getMacroType() != getMacroType() ) return false;
if( ! name.equals( descriptor.getName() )) return false; if( ! name.equals( descriptor.getName() )) return false;
if( descriptor.getParameters().size() != identifierParameters.size() ) return false; if( descriptor.getParameters().length != identifierParameters.length ) return false;
if( descriptor.getTokenizedExpansion().size() != tokenizedExpansion.size() ) return false; if( descriptor.getTokenizedExpansion().length != tokenizedExpansion.length ) return false;
if( ! (descriptor.getParameters().containsAll( identifierParameters ) )) return false; if( ! equivalentArrayContents( descriptor.getParameters(), getParameters() ) ) return false;
if( ! (descriptor.getTokenizedExpansion().containsAll( tokenizedExpansion ))) return false; if( ! equivalentArrayContents( descriptor.getTokenizedExpansion(), getTokenizedExpansion() ) ) return false;
return true;
}
/**
* @param list1
* @param list2
* @return
*/
private boolean equivalentArrayContents(Object[] list1, Object[] list2 ) {
if( Arrays.equals( list1, list2 )) return true;
// otherwise
topLoop: for( int i = 0; i < list1.length; ++i )
{
Object key = list1[i];
for( int j = 0; j < list2 .length; ++j )
{
if( key.equals( list2 [j]) )
continue topLoop;
}
return false;
}
return true; return true;
} }
@ -152,23 +169,12 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
*/ */
public boolean isCircular() { public boolean isCircular() {
if( isCircular == null ) for( int i = 0; i < tokenizedExpansion.length; ++i )
isCircular = new Boolean( checkIsCircular() );
return isCircular.booleanValue();
}
/**
* @return
*/
protected boolean checkIsCircular() {
Iterator i = getTokenizedExpansion().iterator();
while( i.hasNext() )
{ {
IToken t = (IToken) i.next(); IToken t = tokenizedExpansion[i];
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName())) if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
return true; return true;
} }
return false; return false;
} }
} }

View file

@ -10,12 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -40,15 +37,15 @@ public class GCCScannerExtension implements IScannerExtension {
protected static final ObjectMacroDescriptor STDC_VERSION_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L"); //$NON-NLS-1$ protected static final ObjectMacroDescriptor STDC_VERSION_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L"); //$NON-NLS-1$
protected static final ObjectMacroDescriptor STDC_HOSTED_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0"); //$NON-NLS-1$ protected static final ObjectMacroDescriptor STDC_HOSTED_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0"); //$NON-NLS-1$
protected static final ObjectMacroDescriptor CPLUSPLUS_MACRO = new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1"); //$NON-NLS-1$ protected static final ObjectMacroDescriptor CPLUSPLUS_MACRO = new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1"); //$NON-NLS-1$
private static final List simpleIdentifiersDeclSpec; private static final String [] simpleIdentifiersDeclSpec;
private static final List simpleIdentifiersAttribute; private static final String [] simpleIdentifiersAttribute;
static static
{ {
simpleIdentifiersDeclSpec = new ArrayList( 1 ); simpleIdentifiersDeclSpec = new String[ 1 ];
simpleIdentifiersDeclSpec.add( "x" ); //$NON-NLS-1$ simpleIdentifiersDeclSpec[0]= "x"; //$NON-NLS-1$
simpleIdentifiersAttribute = new ArrayList( 1 ); simpleIdentifiersAttribute = new String[ 1 ];
simpleIdentifiersAttribute.add( "xyz"); //$NON-NLS-1$ simpleIdentifiersAttribute[0] = "xyz"; //$NON-NLS-1$
} }
@ -77,8 +74,10 @@ public class GCCScannerExtension implements IScannerExtension {
private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$ private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$
private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$ private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$
protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, Collections.EMPTY_LIST, "" ); //$NON-NLS-1$ private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0];
protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, Collections.EMPTY_LIST, "" ); //$NON-NLS-1$ protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$ private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$

View file

@ -10,11 +10,6 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -26,8 +21,9 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
private final String expansionSignature; private final String expansionSignature;
private final String name; private final String name;
private final IToken token; private final IToken token;
private Boolean isCircular = null; private IToken[] tokenizedExpansion = null;
private List tokenizedExpansion = null; private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final IToken[] EMPTY_TOKEN_ARRAY = new IToken[0];
public ObjectMacroDescriptor( String name, String expansionSignature ) public ObjectMacroDescriptor( String name, String expansionSignature )
{ {
@ -53,19 +49,19 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/ */
public List getParameters() { public String[] getParameters() {
return Collections.EMPTY_LIST; return EMPTY_STRING_ARRAY ;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion() * @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/ */
public List getTokenizedExpansion() { public IToken[] getTokenizedExpansion() {
if( token == null ) return Collections.EMPTY_LIST; if( token == null ) return EMPTY_TOKEN_ARRAY;
if( tokenizedExpansion == null ) if( tokenizedExpansion == null )
{ {
tokenizedExpansion = new ArrayList(1); tokenizedExpansion = new IToken[1];
tokenizedExpansion.add(token); tokenizedExpansion[0]= token;
} }
return tokenizedExpansion; return tokenizedExpansion;
} }
@ -112,23 +108,13 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
return expansionSignature; return expansionSignature;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
*/
public boolean isCircular() {
if( isCircular == null )
isCircular = new Boolean( checkIsCircular() );
return isCircular.booleanValue();
}
/** /**
* @return * @return
*/ */
protected boolean checkIsCircular() { public boolean isCircular() {
Iterator i = getTokenizedExpansion().iterator(); for( int i = 0; i < getTokenizedExpansion().length; ++i)
while( i.hasNext() )
{ {
IToken t = (IToken) i.next(); IToken t = tokenizedExpansion[i];
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName())) if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
return true; return true;
} }

View file

@ -15,6 +15,7 @@ import java.io.File;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.EmptyStackException; import java.util.EmptyStackException;
@ -305,7 +306,7 @@ public class Scanner implements IScanner {
public void overwriteIncludePath(String [] newIncludePaths) { public void overwriteIncludePath(String [] newIncludePaths) {
if( newIncludePaths == null ) return; if( newIncludePaths == null ) return;
scannerData.setIncludePathNames(new ArrayList()); scannerData.setIncludePathNames(new ArrayList(newIncludePaths.length));
for( int i = 0; i < newIncludePaths.length; ++i ) for( int i = 0; i < newIncludePaths.length; ++i )
{ {
@ -2644,6 +2645,9 @@ public class Scanner implements IScanner {
protected boolean forInclusion = false; protected boolean forInclusion = false;
private final static IParserLogService NULL_LOG_SERVICE = new NullLogService(); private final static IParserLogService NULL_LOG_SERVICE = new NullLogService();
private static final String [] STRING_ARRAY = new String[0]; private static final String [] STRING_ARRAY = new String[0];
private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0];
private static final int START_BUFFER_SIZE = 8;
private IToken[] tokenArrayBuffer = new IToken[START_BUFFER_SIZE];
/** /**
* @param b * @param b
*/ */
@ -2652,12 +2656,12 @@ public class Scanner implements IScanner {
forInclusion = b; forInclusion = b;
} }
protected List tokenizeReplacementString( int beginning, String key, String replacementString, List parameterIdentifiers ) protected IToken[] tokenizeReplacementString( int beginning, String key, String replacementString, String[] parameterIdentifiers )
{ {
if( replacementString.trim().equals( "" ) ) //$NON-NLS-1$ if( replacementString.trim().equals( "" ) ) //$NON-NLS-1$
return Collections.EMPTY_LIST; return EMPTY_TOKEN_ARRAY;
List macroReplacementTokens = new ArrayList(); IToken [] macroReplacementTokens = getTokenBuffer();
int currentIndex = 0;
IScanner helperScanner=null; IScanner helperScanner=null;
try { try {
helperScanner = new Scanner( helperScanner = new Scanner(
@ -2679,18 +2683,24 @@ public class Scanner implements IScanner {
} }
if( t == null ) if( t == null )
return macroReplacementTokens; return EMPTY_TOKEN_ARRAY;
try { try {
while (true) { while (true) {
//each # preprocessing token in the replacement list shall be followed //each # preprocessing token in the replacement list shall be followed
//by a parameter as the next reprocessing token in the list //by a parameter as the next reprocessing token in the list
if( t.getType() == tPOUND ){ if( t.getType() == tPOUND ){
macroReplacementTokens.add( t ); if( currentIndex == macroReplacementTokens.length )
{
IToken [] doubled = new IToken[macroReplacementTokens.length * 2];
System.arraycopy( macroReplacementTokens, 0, doubled, 0, macroReplacementTokens.length );
macroReplacementTokens = doubled;
}
macroReplacementTokens[currentIndex++] = t;
t = helperScanner.nextToken(false); t = helperScanner.nextToken(false);
if( parameterIdentifiers != null ) if( parameterIdentifiers != null )
{ {
int index = parameterIdentifiers.indexOf(t.getImage()); int index = findIndex( parameterIdentifiers, t.getImage());
if (index == -1 ) { if (index == -1 ) {
//not found //not found
@ -2703,13 +2713,19 @@ public class Scanner implements IScanner {
strbuff.append( replacementString ); strbuff.append( replacementString );
handleProblem( IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, strbuff.toString(), handleProblem( IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, strbuff.toString(),
beginning, false, true ); beginning, false, true );
return Collections.EMPTY_LIST; return EMPTY_TOKEN_ARRAY;
} }
} }
} }
} }
macroReplacementTokens.add(t); if( currentIndex == macroReplacementTokens.length )
{
IToken [] doubled = new IToken[macroReplacementTokens.length * 2];
System.arraycopy( macroReplacementTokens, 0, doubled, 0, macroReplacementTokens.length );
macroReplacementTokens = doubled;
}
macroReplacementTokens[currentIndex++] = t;
t = helperScanner.nextToken(false); t = helperScanner.nextToken(false);
} }
} }
@ -2720,7 +2736,17 @@ public class Scanner implements IScanner {
{ {
} }
return macroReplacementTokens; IToken [] result = new IToken[ currentIndex ];
System.arraycopy( macroReplacementTokens, 0, result, 0, currentIndex );
return result;
}
/**
* @return
*/
IToken[] getTokenBuffer() {
Arrays.fill( tokenArrayBuffer, null );
return tokenArrayBuffer;
} }
protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) { protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) {
@ -2788,21 +2814,21 @@ public class Scanner implements IScanner {
// replace StringTokenizer later -- not performant // replace StringTokenizer later -- not performant
StringTokenizer tokenizer = new StringTokenizer(parameters, ","); //$NON-NLS-1$ StringTokenizer tokenizer = new StringTokenizer(parameters, ","); //$NON-NLS-1$
ArrayList parameterIdentifiers = String []parameterIdentifiers = new String[tokenizer.countTokens()];
new ArrayList(tokenizer.countTokens()); int ct = 0;
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
parameterIdentifiers.add(tokenizer.nextToken().trim()); parameterIdentifiers[ ct++ ] = tokenizer.nextToken().trim();
} }
skipOverWhitespace(); skipOverWhitespace();
List macroReplacementTokens = null; IToken [] macroReplacementTokens = null;
String replacementString = getRestOfPreprocessorLine(); String replacementString = getRestOfPreprocessorLine();
// TODO: This tokenization could be done live, instead of using a sub-scanner. // TODO: This tokenization could be done live, instead of using a sub-scanner.
macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$ macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$
tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) : tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) :
Collections.EMPTY_LIST; EMPTY_TOKEN_ARRAY;
descriptor = new FunctionMacroDescriptor( descriptor = new FunctionMacroDescriptor(
key, key,
@ -3059,10 +3085,10 @@ public class Scanner implements IScanner {
// create a string that represents what needs to be tokenized // create a string that represents what needs to be tokenized
List tokens = expansion.getTokenizedExpansion(); IToken [] tokens = expansion.getTokenizedExpansion();
List parameterNames = expansion.getParameters(); String [] parameterNames = expansion.getParameters();
if (parameterNames.size() != parameterValues.size()) if (parameterNames.length != parameterValues.size())
{ {
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, symbol, getCurrentOffset(), false, true ); handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, symbol, getCurrentOffset(), false, true );
consumeUntilOutOfMacroExpansion(); consumeUntilOutOfMacroExpansion();
@ -3071,15 +3097,15 @@ public class Scanner implements IScanner {
strbuff.startString(); strbuff.startString();
int numberOfTokens = tokens.size(); int numberOfTokens = tokens.length;
for (int i = 0; i < numberOfTokens; ++i) { for (int i = 0; i < numberOfTokens; ++i) {
t = (SimpleToken) tokens.get(i); t = (SimpleToken) tokens[i];
if (t.getType() == IToken.tIDENTIFIER) { if (t.getType() == IToken.tIDENTIFIER) {
// is this identifier in the parameterNames // is this identifier in the parameterNames
// list? // list?
int index = parameterNames.indexOf(t.getImage()); int index = findIndex( parameterNames, t.getImage() );
if (index == -1 ) { if (index == -1 ) {
// not found // not found
// just add image to buffer // just add image to buffer
@ -3099,13 +3125,13 @@ public class Scanner implements IScanner {
strbuff.append(cache); strbuff.append(cache);
} }
++i; ++i;
if( tokens.size() == i ){ if( tokens.length == i ){
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true ); handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true );
return; return;
} }
t = (SimpleToken) tokens.get( i ); t = (SimpleToken) tokens[ i ];
int index = parameterNames.indexOf(t.getImage()); int index = findIndex( parameterNames, t.getImage());
if( index == -1 ){ if( index == -1 ){
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true ); handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true );
return; return;
@ -3163,7 +3189,7 @@ public class Scanner implements IScanner {
if( i != numberOfTokens - 1) if( i != numberOfTokens - 1)
{ {
IToken t2 = (IToken) tokens.get(i+1); IToken t2 = tokens[i+1];
if( t2.getType() == tPOUNDPOUND ) { if( t2.getType() == tPOUNDPOUND ) {
pastingNext = true; pastingNext = true;
i++; i++;
@ -3204,6 +3230,19 @@ public class Scanner implements IScanner {
} }
/**
* @param parameterNames
* @param image
* @return
*/
private int findIndex(String[] parameterNames, String image) {
for( int i = 0; i < parameterNames.length; ++i )
if( parameterNames[i].equals( image ) )
return i;
return -1;
}
protected String handleDefinedMacro() throws ScannerException { protected String handleDefinedMacro() throws ScannerException {
int o = getCurrentOffset(); int o = getCurrentOffset();
skipOverWhitespace(); skipOverWhitespace();

View file

@ -12,6 +12,7 @@
import java.io.File; import java.io.File;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
@ -37,7 +38,7 @@ public class ScannerUtility {
String [] segments = originalPath.split( "[/\\\\]" ); //$NON-NLS-1$ String [] segments = originalPath.split( "[/\\\\]" ); //$NON-NLS-1$
if( segments.length == 1 ) return originalPath; if( segments.length == 1 ) return originalPath;
Vector results = new Vector(); Vector results = new Vector(segments.length);
for( int i = 0; i < segments.length; ++i ) for( int i = 0; i < segments.length; ++i )
{ {
String segment = segments[i]; String segment = segments[i];
@ -51,11 +52,10 @@ public class ScannerUtility {
results.add( segment ); results.add( segment );
} }
strbuff.startString(); strbuff.startString();
Iterator i = results.iterator(); for( int i = 0; i < results.size(); ++i )
while( i.hasNext() )
{ {
strbuff.append( (String)i.next() ); strbuff.append( (String)results.elementAt(i) );
if( i.hasNext() ) if( i != results.size() - 1 )
strbuff.append( File.separatorChar ); strbuff.append( File.separatorChar );
} }
return strbuff.toString(); return strbuff.toString();