mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
<BR>Patch for Dave Daoust
<BR>Modified Scanner Performance by <BR>1. Moved ScannerContext sentinal to ContextStack <BR>2. Delay Stringizing macro parameter until needed <BR>3. Removed the sentinal from the scanner constructor
This commit is contained in:
parent
181f9ff6b7
commit
0ce4a707ab
7 changed files with 1583 additions and 1595 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.eclipse.cdt.core.parser;
|
|||
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 @@ public interface IScanner extends IFilenameProvider {
|
|||
* @return
|
||||
*/
|
||||
public boolean isOnTopContext();
|
||||
public void setScannerContext(IScannerContext context);
|
||||
|
||||
}
|
||||
|
|
|
@ -13,16 +13,12 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
|
||||
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 @@ import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
|||
*/
|
||||
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;
|
||||
|
||||
public ContextStack( Scanner s, IParserLogService l ) {
|
||||
scanner = s;
|
||||
log = l;
|
||||
private IScannerContext [] cs = new IScannerContext[current_size];;
|
||||
private int cs_pos = 0;
|
||||
|
||||
|
||||
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 void updateContext(Reader reader, String filename, ContextKind type, IASTInclusion inclusion, ISourceElementRequestor requestor) throws ContextException {
|
||||
public ContextStack( IScanner scanner, IParserLogService l ) {
|
||||
log = l;
|
||||
this.scanner = scanner;
|
||||
cs_push(sentinel);
|
||||
scanner.setScannerContext(sentinel);
|
||||
}
|
||||
|
||||
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 @@ public class ContextStack {
|
|||
|
||||
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 )
|
||||
if( context.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 )
|
||||
{
|
||||
defines.remove( currentContext.getFilename() );
|
||||
TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, context.getFilename(), null, null); //$NON-NLS-1$
|
||||
context.getExtension().exitScope( requestor );
|
||||
}
|
||||
|
||||
undoStack.addFirst( currentContext );
|
||||
|
||||
if (contextStack.isEmpty()) {
|
||||
currentContext = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
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 @@ public class ContextStack {
|
|||
*/
|
||||
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;
|
||||
return getMostRelevantFileContext().getLine();
|
||||
}
|
||||
|
||||
public int getTopFileLineNumber()
|
||||
{
|
||||
return topContext.getLine();
|
||||
}
|
||||
|
||||
public Scanner getScanner()
|
||||
{
|
||||
return scanner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
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 @@ import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
|||
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 interface IScannerContext {
|
|||
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 );
|
||||
|
|
|
@ -30,7 +30,7 @@ public class LimitedScannerContext
|
|||
* @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;
|
||||
|
|
|
@ -80,6 +80,11 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
((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 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
{
|
||||
int c;
|
||||
try {
|
||||
c = scannerData.getContextStack().getCurrentContext().read();
|
||||
c = currentContext.read();
|
||||
}
|
||||
catch (IOException e) {
|
||||
c = NOCHAR;
|
||||
|
@ -857,22 +837,16 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
protected void consumeUntilOutOfMacroExpansion() throws ScannerException
|
||||
{
|
||||
while( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
|
||||
while( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
|
||||
getChar();
|
||||
}
|
||||
|
||||
|
@ -933,7 +907,7 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
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 class Scanner implements IScanner {
|
|||
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
|
||||
|
@ -2511,10 +2485,11 @@ public class Scanner implements IScanner {
|
|||
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);
|
||||
|
||||
|
@ -2686,7 +2661,7 @@ public class Scanner implements IScanner {
|
|||
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
|
||||
|
@ -2718,16 +2693,13 @@ public class Scanner implements IScanner {
|
|||
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);
|
||||
|
@ -2826,7 +2798,7 @@ public class Scanner implements IScanner {
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -2959,7 +2931,7 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
handleProblem( e.getId(), scannerData.getContextStack().getCurrentContext().getFilename(), getCurrentOffset(), false, true );
|
||||
handleProblem( e.getId(), currentContext.getFilename(), getCurrentOffset(), false, true );
|
||||
consumeUntilOutOfMacroExpansion();
|
||||
return;
|
||||
}
|
||||
|
@ -2990,7 +2962,7 @@ public class Scanner implements IScanner {
|
|||
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
|
||||
|
@ -3025,6 +2997,8 @@ public class Scanner implements IScanner {
|
|||
} 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 ){
|
||||
|
@ -3109,7 +3083,7 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
handleProblem( e.getId(), scannerData.getContextStack().getCurrentContext().getFilename(), getCurrentOffset(), false, true );
|
||||
handleProblem( e.getId(), currentContext.getFilename(), getCurrentOffset(), false, true );
|
||||
consumeUntilOutOfMacroExpansion();
|
||||
return;
|
||||
}
|
||||
|
@ -3199,7 +3173,7 @@ public class Scanner implements IScanner {
|
|||
* @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()
|
||||
*/
|
||||
|
@ -3215,8 +3189,8 @@ public class Scanner implements IScanner {
|
|||
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();
|
||||
|
|
|
@ -23,12 +23,12 @@ public class ScannerContext implements IScannerContext
|
|||
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 @@ public class ScannerContext implements IScannerContext
|
|||
/* (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 @@ public class ScannerContext implements IScannerContext
|
|||
* Returns the kind.
|
||||
* @return int
|
||||
*/
|
||||
public ContextKind getKind() {
|
||||
public int getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ public class ScannerContext implements IScannerContext
|
|||
* Sets the kind.
|
||||
* @param kind The kind to set
|
||||
*/
|
||||
public void setKind(ContextKind kind) {
|
||||
public void setKind(int kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
|
Loading…
Add table
Reference in a new issue