1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Further performance improvements in Scanner.

This commit is contained in:
John Camelon 2004-03-10 16:53:54 +00:00
parent 3c7584ad4c
commit 9b0029a7dd
4 changed files with 67 additions and 29 deletions

View file

@ -36,7 +36,7 @@ public class PreprocessorConditionalTest extends BaseScannerTest
protected void initializeScanner(String input, Map definitions ) throws Exception protected void initializeScanner(String input, Map definitions ) throws Exception
{ {
scanner= ParserFactory.createScanner( new StringReader(input),"TEXT", new ScannerInfo( definitions, null), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, nullSourceElementRequestor, null ); scanner= ParserFactory.createScanner( new StringReader(input),"TEXT", new ScannerInfo( definitions ), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, nullSourceElementRequestor, null );
} }

View file

@ -1,3 +1,6 @@
2004-03-10 John Camelon
Further performance improvements in Scanner.
2004-03-09 Andrew Niefer 2004-03-09 Andrew Niefer
bug 52948 bug 52948
modified CompleteParseASTFactory.createTypedef() to set the typeSymbol of the typedef symbol modified CompleteParseASTFactory.createTypedef() to set the typeSymbol of the typedef symbol

View file

@ -12,8 +12,6 @@ package org.eclipse.cdt.core.parser;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.IScannerInfo;
/** /**
* @author jcamelon * @author jcamelon
* *
@ -33,6 +31,13 @@ public class ScannerInfo implements IScannerInfo
includePaths = incs; includePaths = incs;
} }
/**
* @param definitions
*/
public ScannerInfo(Map definitions) {
this( definitions, (String [])null);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols() * @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols()
*/ */

View file

@ -16,6 +16,7 @@ import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.EmptyStackException; import java.util.EmptyStackException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
@ -66,6 +67,7 @@ import org.eclipse.cdt.internal.core.parser.token.Token;
public class Scanner implements IScanner { public class Scanner implements IScanner {
private static final NullSourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor();
private final static String SCRATCH = "<scratch>"; //$NON-NLS-1$ private final static String SCRATCH = "<scratch>"; //$NON-NLS-1$
protected final IScannerData scannerData; protected final IScannerData scannerData;
@ -102,6 +104,32 @@ public class Scanner implements IScanner {
throw new ScannerException( problem ); throw new ScannerException( problem );
} }
private Scanner( Reader reader, String filename, Map definitions, List includePaths, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService log, IScannerExtension extension )
{
String [] incs = (String [])includePaths.toArray(STRING_ARRAY);
scannerData = new ScannerData( this, log, requestor, mode, filename, reader, language, new ScannerInfo( definitions, incs ), new ContextStack( this, log ) );
scannerExtension = extension;
if( scannerExtension instanceof GCCScannerExtension )
((GCCScannerExtension)scannerExtension).setScannerData( scannerData );
scannerData.setDefinitions( definitions );
scannerData.setIncludePathNames( includePaths );
scannerData.setASTFactory( ParserFactory.createASTFactory( this, scannerData.getParserMode(), language ) );
try {
//this is a hack to get around a sudden EOF experience
scannerData.getContextStack().push(
new ScannerContext(
new StringReader("\n"), //$NON-NLS-1$
START,
ScannerContext.ContextKind.SENTINEL, null), requestor);
} catch( ContextException ce ) {
//won't happen since we aren't adding an include or a macro
}
}
public Scanner(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension ) { public Scanner(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension ) {
scannerData = new ScannerData( this, log, requestor, parserMode, filename, reader, language, info, new ContextStack( this, log ) ); scannerData = new ScannerData( this, log, requestor, parserMode, filename, reader, language, info, new ContextStack( this, log ) );
@ -121,6 +149,7 @@ public class Scanner implements IScanner {
} catch( ContextException ce ) { } catch( ContextException ce ) {
//won't happen since we aren't adding an include or a macro //won't happen since we aren't adding an include or a macro
// assert false
} }
@ -1925,7 +1954,7 @@ public class Scanner implements IScanner {
if( ! expression.trim().equals("")) //$NON-NLS-1$ if( ! expression.trim().equals("")) //$NON-NLS-1$
{ {
IScanner subScanner = ParserFactory.createScanner( new StringReader(expression), SCRATCH, EMPTY_INFO, ParserMode.QUICK_PARSE, scannerData.getLanguage(), new NullSourceElementRequestor(), new NullLogService()); IScanner subScanner = new Scanner( new StringReader(expression), SCRATCH, EMPTY_MAP, EMPTY_LIST, NULL_REQUESTOR, ParserMode.QUICK_PARSE, scannerData.getLanguage(), NULL_LOG_SERVICE, scannerExtension );
IToken lastToken = null; IToken lastToken = null;
while( true ) while( true )
{ {
@ -2324,19 +2353,19 @@ public class Scanner implements IScanner {
IExpressionParser parser = null; IExpressionParser parser = null;
StringBuffer expressionBuffer = new StringBuffer( expression ); StringBuffer expressionBuffer = new StringBuffer( expression );
expressionBuffer.append( ';'); expressionBuffer.append( ';');
try
{ IScanner trial = new Scanner(
IScanner trial =
ParserFactory.createScanner(
new StringReader(expressionBuffer.toString()), new StringReader(expressionBuffer.toString()),
EXPRESSION, EXPRESSION,
new ScannerInfo( scannerData.getDefinitions(), scannerData.getOriginalConfig().getIncludePaths()), scannerData.getDefinitions(),
ParserMode.QUICK_PARSE, scannerData.getLanguage(), new NullSourceElementRequestor(), nullLogService ); scannerData.getIncludePathNames(),
parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), nullLogService); NULL_REQUESTOR,
} catch( ParserFactoryError pfe ) ParserMode.QUICK_PARSE,
{ scannerData.getLanguage(),
handleInternalError(); NULL_LOG_SERVICE,
} scannerExtension );
parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), NULL_LOG_SERVICE);
try { try {
IASTExpression exp = parser.expression(null); IASTExpression exp = parser.expression(null);
if( exp.evaluateExpression() == 0 ) if( exp.evaluateExpression() == 0 )
@ -2435,10 +2464,10 @@ public class Scanner implements IScanner {
Scanner helperScanner = new Scanner( Scanner helperScanner = new Scanner(
new StringReader(includeLine), new StringReader(includeLine),
null, null,
new ScannerInfo(scannerData.getDefinitions(), scannerData.getOriginalConfig().getIncludePaths()), scannerData.getDefinitions(), scannerData.getIncludePathNames(),
new NullSourceElementRequestor(), NULL_REQUESTOR,
scannerData.getParserMode(), scannerData.getParserMode(),
scannerData.getLanguage(), nullLogService, (IScannerExtension)(scannerExtension.clone()) ); scannerData.getLanguage(), NULL_LOG_SERVICE, (IScannerExtension)(scannerExtension.clone()) );
helperScanner.setForInclusion( true ); helperScanner.setForInclusion( true );
IToken t = null; IToken t = null;
@ -2552,7 +2581,8 @@ public class Scanner implements IScanner {
protected boolean forInclusion = false; protected boolean forInclusion = false;
private final static IParserLogService nullLogService = new NullLogService(); private final static IParserLogService NULL_LOG_SERVICE = new NullLogService();
private static final String [] STRING_ARRAY = new String[0];
/** /**
* @param b * @param b
*/ */
@ -2568,14 +2598,14 @@ public class Scanner implements IScanner {
return macroReplacementTokens; return macroReplacementTokens;
IScanner helperScanner=null; IScanner helperScanner=null;
try { try {
helperScanner = helperScanner = new Scanner(
ParserFactory.createScanner(
new StringReader(replacementString), new StringReader(replacementString),
SCRATCH, SCRATCH,
new ScannerInfo(), EMPTY_MAP, EMPTY_LIST,
NULL_REQUESTOR,
scannerData.getParserMode(), scannerData.getParserMode(),
scannerData.getLanguage(), scannerData.getLanguage(),
new NullSourceElementRequestor(), nullLogService); NULL_LOG_SERVICE, scannerExtension);
} catch (ParserFactoryError e1) { } catch (ParserFactoryError e1) {
} }
helperScanner.setTokenizingMacroReplacementList( true ); helperScanner.setTokenizingMacroReplacementList( true );
@ -2843,7 +2873,7 @@ public class Scanner implements IScanner {
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException { protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( scannerData.getDefinitions(), scannerData.getOriginalConfig().getIncludePaths() ), new NullSourceElementRequestor(), scannerData.getParserMode(), scannerData.getLanguage(), nullLogService, (IScannerExtension)scannerExtension.clone() ); Scanner tokenizer = new Scanner(new StringReader(params), TEXT, scannerData.getDefinitions(), scannerData.getIncludePathNames(), NULL_REQUESTOR, scannerData.getParserMode(), scannerData.getLanguage(), NULL_LOG_SERVICE, (IScannerExtension)scannerExtension.clone() );
tokenizer.setThrowExceptionOnBadCharacterRead(false); tokenizer.setThrowExceptionOnBadCharacterRead(false);
Vector parameterValues = new Vector(); Vector parameterValues = new Vector();
Token t = null; Token t = null;
@ -3155,7 +3185,7 @@ public class Scanner implements IScanner {
* @see org.eclipse.cdt.core.parser.IScanner#getDefinitions() * @see org.eclipse.cdt.core.parser.IScanner#getDefinitions()
*/ */
public Map getDefinitions() { public Map getDefinitions() {
return scannerData.getDefinitions(); return Collections.unmodifiableMap(scannerData.getDefinitions());
} }
/** /**