[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-patch] More performance modifications to the Scanner
|
Here is an updated patch with comments
from JohnC included. (I removed an unnecessary scanner context creation
....)
-
Dave
Modified
Scanner Performance by
1. Moved ScannerContext sentinal to ContextStack
2. Delay Stringizing macro parameter until
needed
3. Removed the sentinal from the scanner constructor
Effect on #include <windows.h>
total
bytes objs time(ms)
tokens
orig
59905960
1455079 1593
83812
move
sentinel 53824616
1262428 1462
83812
delay
stringizing 40868312
950355 1322
83812
remove
sentinal
38598848 910909
1312 83812
David Daoust/Ottawa/IBM@IBMCA
Sent by: cdt-patch-admin@xxxxxxxxxxx
04/14/2004 06:58 AM
Please respond to
cdt-patch |
|
To
| cdt-patch@xxxxxxxxxxx
|
cc
|
|
Subject
| Re: [cdt-patch] More performance
modifications to the Scanner |
|
Here is the patch without the complete delete and re-add of the Changelog....
(The patch seemed a lot larger than I expected).
- Dave
David Daoust/Ottawa/IBM@IBMCA
Sent by: cdt-patch-admin@xxxxxxxxxxx
04/13/2004 08:48 PM
Please respond to
cdt-patch |
|
To
| cdt-patch@xxxxxxxxxxx
|
cc
|
|
Subject
| [cdt-patch] More performance
modifications to the Scanner |
|
Here is a patch to reduce the number of objects created by the scanner
and speed up the overall operation..
On my test of #include <windows.h> the object count dropped from
total bytes objs
time(ms)
orig 59905960 1455079
1593
new 40868312 950355
1322
- Dave
[attachment "scannerSpeedUp.txt" deleted by David Daoust/Ottawa/IBM]
Index: parser/ChangeLog-parser
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog-parser,v
retrieving revision 1.124
diff -u -r1.124 ChangeLog-parser
--- parser/ChangeLog-parser 15 Apr 2004 22:38:38 -0000 1.124
+++ parser/ChangeLog-parser 16 Apr 2004 13:54:23 -0000
@@ -1,3 +1,17 @@
+2004-04-15 David Daoust
+ Modified Scanner Performance by
+ 1. Moved ScannerContext sentinal to ContextStack
+ 2. Delay Stringizing macro parameter until needed
+ 3. Removed the sentinal from the scanner constructor
+
+ Effect on #include <windows.h>
+
+ total bytes objs time(ms)tokens
+ orig 59905960 1455079 1593 83812
+ move sentinel 53824616 1262428 1462 83812
+ delay stringizing 40868312 950355 1322 83812
+ remove sentinal 38598848 910909 1312 83812
+
2004-04-15 Andrew Niefer
fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=58492
Index: parser/org/eclipse/cdt/core/parser/IScanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java,v
retrieving revision 1.22
diff -u -r1.22 IScanner.java
--- parser/org/eclipse/cdt/core/parser/IScanner.java 3 Mar 2004 15:59:51 -0000 1.22
+++ parser/org/eclipse/cdt/core/parser/IScanner.java 16 Apr 2004 13:54:24 -0000
@@ -3,6 +3,7 @@
import java.util.Map;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
+import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
/**
* @author jcamelon
@@ -48,5 +49,6 @@
* @return
*/
public boolean isOnTopContext();
+ public void setScannerContext(IScannerContext context);
}
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java,v
retrieving revision 1.6
diff -u -r1.6 ContextStack.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java 6 Apr 2004 21:31:15 -0000 1.6
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java 16 Apr 2004 13:54:28 -0000
@@ -13,16 +13,12 @@
import java.io.IOException;
import java.io.Reader;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Set;
-import java.util.Stack;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
-import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext.ContextKind;
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
/**
@@ -33,34 +29,85 @@
*/
public class ContextStack {
+ private static class SentinelContext implements IScannerContext {
+ public int read() throws IOException { return '\n'; }
+ public String getFilename() { return ""; }
+ public int getMacroOffset() { return -1; }
+ public int getMacroLength() { return -1; }
+ public int getOffset() { return 0; }
+ public int getRelativeOffset() { return 0; }
+ public Reader getReader() { return null; }
+ public void pushUndo(int undo) { }
+ public int getKind() { return IScannerContext.ContextKind.SENTINEL; }
+ public void setKind(int kind) { }
+ public IASTInclusion getExtension() { return null; }
+ public void setExtension(IASTInclusion ext) { }
+ public int getLine() { return -1; }
+ public int undoStackSize() { return 0; }
+ public int popUndo() { return '\n'; }
+ }
private final IParserLogService log;
- private Scanner scanner;
+ private int current_size = 8;
+
+ private IScannerContext [] cs = new IScannerContext[current_size];;
+ private int cs_pos = 0;
+
- public ContextStack( Scanner s, IParserLogService l ) {
- scanner = s;
+ private static IScannerContext sentinel = new SentinelContext();
+
+ private IScanner scanner;
+
+ private final void cs_push(IScannerContext c) {
+ try {
+ cs[cs_pos++] = c;;
+ }
+ catch (ArrayIndexOutOfBoundsException a)
+ {
+ int new_size = current_size*2;
+ IScannerContext [] new_cs = new IScannerContext[new_size];
+
+ for (int i = 0; i < current_size; i++) {
+ new_cs[i] = cs[i];
+ }
+
+ new_cs[current_size] = c;
+ current_size = new_size;
+ cs = new_cs;
+ }
+ scanner.setScannerContext(c);
+ }
+ private final IScannerContext cs_pop() {
+ IScannerContext context = cs[--cs_pos];
+ scanner.setScannerContext((cs_pos == 0) ? sentinel : cs[cs_pos -1]);
+ return context;
+ }
+
+ public ContextStack( IScanner scanner, IParserLogService l ) {
log = l;
+ this.scanner = scanner;
+ cs_push(sentinel);
+ scanner.setScannerContext(sentinel);
}
- public void updateContext(Reader reader, String filename, ContextKind type, IASTInclusion inclusion, ISourceElementRequestor requestor) throws ContextException {
+ public void updateContext(Reader reader, String filename, int type, IASTInclusion inclusion, ISourceElementRequestor requestor) throws ContextException {
updateContext(reader, filename, type, inclusion, requestor, -1, -1);
}
- public void updateContext(Reader reader, String filename, ContextKind type, IASTInclusion inclusion, ISourceElementRequestor requestor, int macroOffset, int macroLength) throws ContextException
+ public void updateContext(Reader reader, String filename, int type, IASTInclusion inclusion, ISourceElementRequestor requestor, int macroOffset, int macroLength) throws ContextException
{
int startLine = 1;
// If we expand a macro within a macro, then keep offsets of the top-level one,
// as only the top level macro identifier is properly positioned
if (type == IScannerContext.ContextKind.MACROEXPANSION) {
- if (currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION) {
- macroOffset = currentContext.getMacroOffset();
- macroLength = currentContext.getMacroLength();
+ if (getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION) {
+ macroOffset = getCurrentContext().getMacroOffset();
+ macroLength = getCurrentContext().getMacroLength();
}
- startLine = currentContext.getLine();
+ startLine = getCurrentContext().getLine();
}
- undoStack.clear();
IScannerContext context = new ScannerContext( reader, filename, type, null, macroOffset, macroLength, startLine );
context.setExtension(inclusion);
push( context, requestor );
@@ -68,70 +115,45 @@
protected void push( IScannerContext context, ISourceElementRequestor requestor ) throws ContextException
{
- if( context.getKind() == IScannerContext.ContextKind.INCLUSION )
- {
- if( !inclusions.add( context.getFilename() ) )
+ if( context.getKind() == IScannerContext.ContextKind.INCLUSION ) {
+ if( isCircularInclusion( context.getFilename() ) )
throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION );
TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getFilename(), null, null ); //$NON-NLS-1$
context.getExtension().enterScope( requestor );
-
- } else if( context.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
- {
- if( !defines.add( context.getFilename() ) )
- throw new ContextException( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN );
- }
- if( currentContext != null )
- contextStack.push(currentContext);
+ }
- currentContext = context;
- if( context.getKind() == IScannerContext.ContextKind.TOP )
- topContext = context;
+// This could be replaced with a check for shouldExpandMacro -- but it is called by
+// the scanner before this point
+// else if( context.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
+// {
+// if( !defines.add( context.getFilename() ) )
+// throw new ContextException( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN );
+// }
+ cs_push(context);
}
public boolean rollbackContext(ISourceElementRequestor requestor) {
+ IScannerContext context = getCurrentContext();
try {
- currentContext.getReader().close();
+ context.getReader().close();
} catch (IOException ie) {
TraceUtil.outputTrace( log, "ContextStack : Error closing reader "); //$NON-NLS-1$
}
- if( currentContext.getKind() == IScannerContext.ContextKind.INCLUSION )
- {
- TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, currentContext.getFilename(), null, null); //$NON-NLS-1$
- inclusions.remove( currentContext.getFilename() );
- currentContext.getExtension().exitScope( requestor );
- } else if( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
+ if( context.getKind() == IScannerContext.ContextKind.INCLUSION )
{
- defines.remove( currentContext.getFilename() );
- }
-
- undoStack.addFirst( currentContext );
-
- if (contextStack.isEmpty()) {
- currentContext = null;
- return false;
+ TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, context.getFilename(), null, null); //$NON-NLS-1$
+ context.getExtension().exitScope( requestor );
}
-
- currentContext = (ScannerContext) contextStack.pop();
- return true;
+ cs_pop();
+ return cs_pos != 0;
}
- public void undoRollback( IScannerContext undoTo, ISourceElementRequestor requestor ) throws ContextException {
- if( currentContext == undoTo ){
- return;
- }
-
- int size = undoStack.size();
- if( size > 0 )
- {
- for( int i = size; i > 0; i-- )
- {
- push( (IScannerContext) undoStack.removeFirst(), requestor );
-
- if( currentContext == undoTo )
- break;
- }
+ public void undoRollback( IScannerContext undoTo, ISourceElementRequestor requestor ) {
+ while (getCurrentContext() != undoTo ) {
+ //cs_pos++;
+ scanner.setScannerContext(cs[cs_pos++]);
}
}
@@ -147,58 +169,43 @@
*/
protected boolean shouldExpandDefinition( String symbol )
{
- return !defines.contains( symbol );
+ for(int i = cs_pos-1; i >= 0; i--)
+ if (cs[i].getKind() == IScannerContext.ContextKind.MACROEXPANSION
+ && cs[i].getFilename().equals(symbol))
+ return false;
+ return true;
}
- public IScannerContext getCurrentContext(){
- return currentContext;
+ protected boolean isCircularInclusion( String symbol )
+ {
+ for(int i = cs_pos-1; i >= 0; i--)
+ if (cs[i].getKind() == IScannerContext.ContextKind.INCLUSION &&
+ cs[i].getFilename().equals(symbol))
+ return true;
+ return false;
}
- private IScannerContext currentContext, topContext;
- private Stack contextStack = new Stack();
- private LinkedList undoStack = new LinkedList();
- private Set inclusions = new HashSet();
- private Set defines = new HashSet();
-
- /**
- * @return
- */
- public IScannerContext getTopContext() {
- return topContext;
+ public final IScannerContext getCurrentContext(){
+ //return (cs_pos == 0) ? sentinel : cs[cs_pos -1];
+ return cs[cs_pos -1];
}
public IScannerContext getMostRelevantFileContext()
{
- if( currentContext != null )
+ IScannerContext context = sentinel;
+ for( int i = cs_pos - 1; i >= 0; --i )
{
- if( currentContext.getKind() == IScannerContext.ContextKind.TOP ) return currentContext;
- if( currentContext.getKind() == IScannerContext.ContextKind.INCLUSION ) return currentContext;
- }
-
- IScannerContext context = null;
- for( int i = contextStack.size() - 1; i >= 0; --i )
- {
- context = (IScannerContext)contextStack.get(i);
- if( context.getKind() == IScannerContext.ContextKind.INCLUSION || context.getKind() == IScannerContext.ContextKind.TOP )
+ context = cs[i];
+ if( context.getKind() == IScannerContext.ContextKind.INCLUSION
+ || context.getKind() == IScannerContext.ContextKind.TOP )
break;
- if( i == 0 ) context = null;
}
-
return context;
}
public int getCurrentLineNumber()
{
- return getMostRelevantFileContext() != null ? getMostRelevantFileContext().getLine() : -1;
- }
-
- public int getTopFileLineNumber()
- {
- return topContext.getLine();
- }
-
- public Scanner getScanner()
- {
- return scanner;
+ return getMostRelevantFileContext().getLine();
}
+
}
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/IScannerContext.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IScannerContext.java,v
retrieving revision 1.1
diff -u -r1.1 IScannerContext.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/IScannerContext.java 22 Jan 2004 20:15:26 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/IScannerContext.java 16 Apr 2004 13:54:28 -0000
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.io.Reader;
-import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
/**
* @author jcamelon
@@ -11,20 +10,12 @@
public interface IScannerContext {
- public static class ContextKind extends Enum
+ public static class ContextKind
{
- public static ContextKind SENTINEL = new ContextKind( 0 );
- public static ContextKind TOP = new ContextKind( 1 );
- public static ContextKind INCLUSION = new ContextKind( 2 );
- public static ContextKind MACROEXPANSION = new ContextKind( 3 );
-
- /**
- * @param enumValue
- */
- protected ContextKind(int enumValue) {
- super(enumValue);
- //
- }
+ public static int SENTINEL = 0;
+ public static int TOP = 1;
+ public static int INCLUSION = 2;
+ public static int MACROEXPANSION = 3;
}
/**
@@ -67,8 +58,8 @@
public int popUndo();
public void pushUndo(int undo);
- public ContextKind getKind();
- public void setKind( ContextKind kind );
+ public int getKind();
+ public void setKind( int kind );
public IASTInclusion getExtension();
public void setExtension( IASTInclusion ext );
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/LimitedScannerContext.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LimitedScannerContext.java,v
retrieving revision 1.2
diff -u -r1.2 LimitedScannerContext.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/LimitedScannerContext.java 30 Jan 2004 18:28:07 -0000 1.2
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/LimitedScannerContext.java 16 Apr 2004 13:54:28 -0000
@@ -30,7 +30,7 @@
* @param object
* @param offsetLimit
*/
- public LimitedScannerContext(Scanner scanner, Reader reader, String string, ContextKind kind, int offsetLimit) {
+ public LimitedScannerContext(Scanner scanner, Reader reader, String string, int kind, int offsetLimit) {
super( reader, string, kind, null );
this.scanner = scanner;
limit = offsetLimit;
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java,v
retrieving revision 1.36
diff -u -r1.36 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java 15 Apr 2004 01:47:57 -0000 1.36
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java 16 Apr 2004 13:54:30 -0000
@@ -80,6 +80,11 @@
private static final int NO_OFFSET_LIMIT = -1;
private int offsetLimit = NO_OFFSET_LIMIT;
private boolean limitReached = false;
+ private IScannerContext currentContext;
+
+ public void setScannerContext(IScannerContext context) {
+ currentContext = context;
+ }
protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error ) throws ScannerException
{
@@ -117,18 +122,6 @@
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, List workingCopies ) {
@@ -140,19 +133,6 @@
((GCCScannerExtension)scannerExtension).setScannerData( scannerData );
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
- // assert false
- }
-
TraceUtil.outputTrace(log, "Scanner constructed with the following configuration:"); //$NON-NLS-1$
TraceUtil.outputTrace(log, "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$
@@ -546,7 +526,7 @@
}
else // local inclusion
{
- duple = ScannerUtility.createReaderDuple( new File( scannerData.getContextStack().getCurrentContext().getFilename() ).getParentFile().getAbsolutePath(), fileName, scannerData.getClientRequestor(), scannerData.getWorkingCopies() );
+ duple = ScannerUtility.createReaderDuple( new File( currentContext.getFilename() ).getParentFile().getAbsolutePath(), fileName, scannerData.getClientRequestor(), scannerData.getWorkingCopies() );
if( duple != null )
break totalLoop;
useIncludePaths = true;
@@ -599,7 +579,7 @@
File includeFile = null;
if( !useIncludePaths ) { // local inclusion is checked first
- String currentFilename = scannerData.getContextStack().getCurrentContext().getFilename();
+ String currentFilename = currentContext.getFilename();
File currentIncludeFile = new File( currentFilename );
String parentDirectory = currentIncludeFile.getParentFile().getAbsolutePath();
currentIncludeFile = null;
@@ -723,9 +703,9 @@
private int getChar( boolean insideString ) throws ScannerException {
int c = NOCHAR;
- lastContext = scannerData.getContextStack().getCurrentContext();
+ lastContext = currentContext;
- if (lastContext == null)
+ if (lastContext.getKind() == IScannerContext.ContextKind.SENTINEL)
// past the end of file
return c;
@@ -845,7 +825,7 @@
{
int c;
try {
- c = scannerData.getContextStack().getCurrentContext().read();
+ c = currentContext.read();
}
catch (IOException e) {
c = NOCHAR;
@@ -857,22 +837,16 @@
if (scannerData.getContextStack().rollbackContext(scannerData.getClientRequestor()) == false)
return NOCHAR;
- if (scannerData.getContextStack().getCurrentContext().undoStackSize() != 0 )
- return scannerData.getContextStack().getCurrentContext().popUndo();
+ if (currentContext.undoStackSize() != 0 )
+ return currentContext.popUndo();
return readFromStream();
}
final void ungetChar(int c) throws ScannerException{
- scannerData.getContextStack().getCurrentContext().pushUndo(c);
- try
- {
- scannerData.getContextStack().undoRollback( lastContext, scannerData.getClientRequestor() );
- }
- catch (ContextException e)
- {
- handleProblem( e.getId(), scannerData.getContextStack().getCurrentContext().getFilename(), getCurrentOffset(), false, true );
- }
+ currentContext.pushUndo(c);
+ scannerData.getContextStack().undoRollback( lastContext, scannerData.getClientRequestor() );
+
}
protected boolean lookAheadForTokenPasting() throws ScannerException
@@ -898,7 +872,7 @@
protected void consumeUntilOutOfMacroExpansion() throws ScannerException
{
- while( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
+ while( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
getChar();
}
@@ -933,7 +907,7 @@
}
catch (ContextException e)
{
- handleProblem( e.getId(), scannerData.getContextStack().getCurrentContext().getFilename(), getCurrentOffset(), false, true );
+ handleProblem( e.getId(), currentContext.getFilename(), getCurrentOffset(), false, true );
}
storageBuffer = null;
return true;
@@ -1172,7 +1146,7 @@
public IToken processPreprocessor() throws ScannerException, EndOfFileException
{
int c;
- int beginningOffset = scannerData.getContextStack().getCurrentContext().getOffset() - 1;
+ int beginningOffset = currentContext.getOffset() - 1;
int beginningLine = scannerData.getContextStack().getCurrentLineNumber();
// we are allowed arbitrary whitespace after the '#' and before the rest of the text
@@ -1393,7 +1367,11 @@
handleInvalidCompletion();
return null;
}
- handleProblem( IProblem.PREPROCESSOR_POUND_ERROR, getRestOfPreprocessorLine(), beginningOffset, false, true );
+ String restOfErrorLine = getRestOfPreprocessorLine();
+ if( isLimitReached() )
+ handleInvalidCompletion();
+
+ handleProblem( IProblem.PREPROCESSOR_POUND_ERROR, restOfErrorLine, beginningOffset, false, true );
return null;
case PreprocessorDirectives.PRAGMA :
@@ -2507,10 +2485,11 @@
c = getChar();
}
- if (c == NOCHAR && !isLimitReached() )
- handleProblem( IProblem.SCANNER_UNEXPECTED_EOF, null, getCurrentOffset(), false, true );
- else if( c== NOCHAR ) // limit reached
- handleInvalidCompletion();
+ if ( state != 2)
+ if (c == NOCHAR && !isLimitReached() )
+ handleProblem( IProblem.SCANNER_UNEXPECTED_EOF, null, getCurrentOffset(), false, true );
+ else if( c== NOCHAR ) // limit reached
+ handleInvalidCompletion();
ungetChar(c);
@@ -2522,6 +2501,9 @@
int baseOffset = lastContext.getOffset() - lastContext.undoStackSize();
int nameLine = scannerData.getContextStack().getCurrentLineNumber();
String includeLine = getRestOfPreprocessorLine();
+ if( isLimitReached() )
+ handleInvalidCompletion();
+
int endLine = scannerData.getContextStack().getCurrentLineNumber();
ScannerUtility.InclusionDirective directive = null;
@@ -2679,7 +2661,7 @@
protected void poundDefine(int beginning, int beginningLine ) throws ScannerException, EndOfFileException {
// definition
String key = getNextIdentifier();
- int offset = scannerData.getContextStack().getCurrentContext().getOffset() - key.length() - scannerData.getContextStack().getCurrentContext().undoStackSize();
+ int offset = currentContext.getOffset() - key.length() - currentContext.undoStackSize();
int nameLine = scannerData.getContextStack().getCurrentLineNumber();
// store the previous definition to check against later
@@ -2711,16 +2693,13 @@
handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, potentialErrorMessage.toString(), beginning, false, true);
return;
}
- } else if( c == '\r' || c == '\n' ){
+ } else if( c == '\r' || c == '\n' || c == NOCHAR ){
StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
potentialErrorMessage.append( buffer );
potentialErrorMessage.append( '\\');
potentialErrorMessage.append( (char)c );
handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, potentialErrorMessage.toString(), beginning, false, true );
return;
- } else if( c == NOCHAR ){
- handleProblem( IProblem.SCANNER_UNEXPECTED_EOF, null, beginning, false, true );
- return;
}
buffer.append((char) c);
@@ -2819,7 +2798,7 @@
try
{
- scannerData.getASTFactory().createMacro( key, beginning, beginningLine, offset, offset + key.length(), nameLine, scannerData.getContextStack().getCurrentContext().getOffset(), scannerData.getContextStack().getCurrentLineNumber(), descriptor ).acceptElement( scannerData.getClientRequestor() );
+ scannerData.getASTFactory().createMacro( key, beginning, beginningLine, offset, offset + key.length(), nameLine, currentContext.getOffset(), scannerData.getContextStack().getCurrentLineNumber(), descriptor ).acceptElement( scannerData.getClientRequestor() );
}
catch (Exception e)
{
@@ -2952,7 +2931,7 @@
}
catch (ContextException e)
{
- handleProblem( e.getId(), scannerData.getContextStack().getCurrentContext().getFilename(), getCurrentOffset(), false, true );
+ handleProblem( e.getId(), currentContext.getFilename(), getCurrentOffset(), false, true );
consumeUntilOutOfMacroExpansion();
return;
}
@@ -2983,7 +2962,7 @@
String betweenTheBrackets = buffer.toString().trim();
Vector parameterValues = getMacroParameters(betweenTheBrackets, false);
- Vector parameterValuesForStringizing = getMacroParameters(betweenTheBrackets, true);
+ Vector parameterValuesForStringizing = null;
SimpleToken t = null;
// create a string that represents what needs to be tokenized
@@ -3018,6 +2997,8 @@
} else if (t.getType() == tPOUND) {
//next token should be a parameter which needs to be turned into
//a string literal
+ if( parameterValuesForStringizing == null)
+ parameterValuesForStringizing = getMacroParameters(betweenTheBrackets, true);
t = (SimpleToken) tokens.get( ++i );
int index = parameterNames.indexOf(t.getImage());
if( index == -1 ){
@@ -3102,7 +3083,7 @@
}
catch (ContextException e)
{
- handleProblem( e.getId(), scannerData.getContextStack().getCurrentContext().getFilename(), getCurrentOffset(), false, true );
+ handleProblem( e.getId(), currentContext.getFilename(), getCurrentOffset(), false, true );
consumeUntilOutOfMacroExpansion();
return;
}
@@ -3192,7 +3173,7 @@
* @see org.eclipse.cdt.core.parser.IScanner#isOnTopContext()
*/
public boolean isOnTopContext() {
- return ( scannerData.getContextStack().getCurrentContext() == scannerData.getContextStack().getTopContext() );
+ return ( currentContext.getKind() == IScannerContext.ContextKind.TOP );
} /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFilename()
*/
@@ -3208,8 +3189,8 @@
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append( "Scanner @"); //$NON-NLS-1$
- if( scannerData.getContextStack().getCurrentContext() != null )
- buffer.append( scannerData.getContextStack().getCurrentContext().toString());
+ if( currentContext != null )
+ buffer.append( currentContext.toString());
else
buffer.append( "EOF"); //$NON-NLS-1$
return buffer.toString();
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java,v
retrieving revision 1.3
diff -u -r1.3 ScannerContext.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java 12 Apr 2004 15:37:39 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java 16 Apr 2004 13:54:30 -0000
@@ -23,12 +23,12 @@
private int macroLength = -1;
private int line = 1;
private int offset;
- private ContextKind kind;
+ private int kind;
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion, int, int, int)
*/
- public ScannerContext(Reader r, String f, ContextKind k, IASTInclusion i, int mO, int mL, int l)
+ public ScannerContext(Reader r, String f, int k, IASTInclusion i, int mO, int mL, int l)
{
reader = r;
filename = f;
@@ -43,7 +43,7 @@
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion)
*/
- public ScannerContext(Reader r, String f, ContextKind k, IASTInclusion i)
+ public ScannerContext(Reader r, String f, int k, IASTInclusion i)
{
this(r, f, k, i, -1, -1, 1);
}
@@ -151,7 +151,7 @@
* Returns the kind.
* @return int
*/
- public ContextKind getKind() {
+ public int getKind() {
return kind;
}
@@ -159,7 +159,7 @@
* Sets the kind.
* @param kind The kind to set
*/
- public void setKind(ContextKind kind) {
+ public void setKind(int kind) {
this.kind = kind;
}
/* (non-Javadoc)