1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 01:05:38 +02:00
This commit is contained in:
John Camelon 2005-02-11 20:02:02 +00:00
parent 0c4f633ecc
commit d77e74d43e
4 changed files with 4613 additions and 4394 deletions

View file

@ -30,321 +30,363 @@ import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
*/
public class DOMScanner extends BaseScanner {
protected final ICodeReaderFactory codeReaderFactory;
protected int [] bufferDelta = new int[ bufferInitialSize ];
protected final ICodeReaderFactory codeReaderFactory;
private static class DOMInclusion {
public final char[] pt;
public final int o;
protected int[] bufferDelta = new int[bufferInitialSize];
/**
*
*/
public DOMInclusion(char[] path, int offset) {
this.pt = path;
this.o = offset;
}
}
private static class DOMInclusion {
public final char[] pt;
/**
* @param reader
* @param info
* @param parserMode
* @param language
* @param log
* @param readerFactory
* TODO
* @param requestor
*/
public DOMScanner(CodeReader reader, IScannerInfo info,
ParserMode parserMode, ParserLanguage language, IParserLogService log,
IScannerExtensionConfiguration configuration,
ICodeReaderFactory readerFactory) {
super(reader, info, parserMode, language, log, configuration);
this.expressionEvaluator = new ExpressionEvaluator(null, null);
this.codeReaderFactory = readerFactory;
postConstructorSetup(reader, info);
}
public final int o;
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/
public ILocationResolver getLocationResolver() {
if (locationMap instanceof ILocationResolver)
return (ILocationResolver) locationMap;
return null;
}
/**
*
*/
public DOMInclusion(char[] path, int offset) {
this.pt = path;
this.o = offset;
}
}
final IScannerPreprocessorLog locationMap = new LocationMap();
/**
* @param reader
* @param info
* @param parserMode
* @param language
* @param log
* @param readerFactory
* TODO
* @param requestor
*/
public DOMScanner(CodeReader reader, IScannerInfo info,
ParserMode parserMode, ParserLanguage language,
IParserLogService log,
IScannerExtensionConfiguration configuration,
ICodeReaderFactory readerFactory) {
super(reader, info, parserMode, language, log, configuration);
this.expressionEvaluator = new ExpressionEvaluator(null, null);
this.codeReaderFactory = readerFactory;
postConstructorSetup(reader, info);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/
public void setASTFactory(IASTFactory f) {
// do nothing
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/
public ILocationResolver getLocationResolver() {
if (locationMap instanceof ILocationResolver)
return (ILocationResolver) locationMap;
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createInclusionConstruct(char[],
* char[], boolean, int, int, int, int, int, int, int, boolean)
*/
protected Object createInclusionConstruct(char[] fileName,
char[] filenamePath, boolean local, int startOffset,
int startingLineNumber, int nameOffset, int nameEndOffset,
int nameLine, int endOffset, int endLine, boolean isForced) {
return new DOMInclusion(filenamePath, resolveOffset(startOffset));
}
final IScannerPreprocessorLog locationMap = new LocationMap();
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processMacro(char[],
* int, int, int, int, int, int, int)
*/
protected void processMacro(char[] name, int startingOffset,
int startingLineNumber, int idstart, int idend, int nameLine,
int textEnd, int endingLine, IMacro macro) {
if (macro instanceof FunctionStyleMacro)
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
resolveOffset( startingOffset ), resolveOffset( idstart ), resolveOffset( idend ), resolveOffset( textEnd) );
else if (macro instanceof ObjectStyleMacro)
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
resolveOffset( startingOffset ), resolveOffset( idstart ), resolveOffset( idend ), resolveOffset( textEnd ) );
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/
public void setASTFactory(IASTFactory f) {
// do nothing
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createInclusionConstruct(char[],
* char[], boolean, int, int, int, int, int, int, int, boolean)
*/
protected Object createInclusionConstruct(char[] fileName,
char[] filenamePath, boolean local, int startOffset,
int startingLineNumber, int nameOffset, int nameEndOffset,
int nameLine, int endOffset, int endLine, boolean isForced) {
return new DOMInclusion(filenamePath, resolveOffset(startOffset));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/
protected CodeReader createReaderDuple(String finalPath) {
return codeReaderFactory.createCodeReaderForInclusion(finalPath);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processMacro(char[],
* int, int, int, int, int, int, int)
*/
protected void processMacro(char[] name, int startingOffset,
int startingLineNumber, int idstart, int idend, int nameLine,
int textEnd, int endingLine, IMacro macro) {
if (macro instanceof FunctionStyleMacro)
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
resolveOffset(startingOffset), resolveOffset(idstart),
resolveOffset(idend), resolveOffset(textEnd));
else if (macro instanceof ObjectStyleMacro)
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
resolveOffset(startingOffset), resolveOffset(idstart),
resolveOffset(idend), resolveOffset(textEnd));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
* java.lang.Object)
*/
protected void pushContext(char[] buffer, Object data) {
if( bufferStackPos + 1 == bufferDelta.length )
{
int size = bufferDelta.length * 2;
int[] oldBufferDelta = bufferDelta;
bufferDelta = new int[size];
System.arraycopy(oldBufferDelta, 0, bufferDelta, 0, oldBufferDelta.length);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/
protected CodeReader createReaderDuple(String finalPath) {
return codeReaderFactory.createCodeReaderForInclusion(finalPath);
}
if (data instanceof InclusionData) {
if (log.isTracing()) {
StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$
b.append(((InclusionData) data).reader.filename);
log.traceLog(b.toString());
}
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
locationMap.startInclusion(((InclusionData)data).reader, inc.o, resolveOffset( getCurrentOffset() ));
bufferDelta[bufferStackPos + 1 ] = 0;
}
super.pushContext(buffer, data);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
* java.lang.Object)
*/
protected void pushContext(char[] buffer, Object data) {
if (bufferStackPos + 1 == bufferDelta.length) {
int size = bufferDelta.length * 2;
int[] oldBufferDelta = bufferDelta;
bufferDelta = new int[size];
System.arraycopy(oldBufferDelta, 0, bufferDelta, 0,
oldBufferDelta.length);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/
protected Object popContext() {
//TODO calibrate offsets
Object result = super.popContext();
if (result instanceof CodeReader) {
locationMap.endTranslationUnit( bufferDelta[0] + ((CodeReader)result).buffer.length );
}
if (result instanceof InclusionData) {
CodeReader codeReader = ((InclusionData) result).reader;
if (log.isTracing()) {
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
buffer.append(codeReader.filename);
log.traceLog(buffer.toString());
}
if (data instanceof InclusionData) {
locationMap.endInclusion(getGlobalCounter( bufferStackPos + 1 ) + bufferPos[ bufferStackPos + 1 ]);
bufferDelta[ bufferStackPos ] += bufferDelta[ bufferStackPos + 1 ] + codeReader.buffer.length;
}
return result;
}
protected int getGlobalCounter( int value )
{
if( value < 0 ) return 0;
int result = bufferDelta[ value ];
for( int i = value - 1; i >= 0; --i )
result += bufferPos[ i ] + bufferDelta[ i ];
return result;
}
protected int getGlobalCounter()
{
return getGlobalCounter( bufferStackPos );
}
if (log.isTracing()) {
StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$
b.append(((InclusionData) data).reader.filename);
log.traceLog(b.toString());
}
/**
* @return
*/
protected IToken newToken(int signal) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new SimpleExpansionToken(signal,
resolveOffset(data.startOffset), data.endOffset
- data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
return new SimpleToken(signal,
resolveOffset(bufferPos[bufferStackPos] + 1), getCurrentFilename(),
getLineNumber(bufferPos[bufferStackPos] + 1));
}
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
locationMap.startInclusion(((InclusionData) data).reader, inc.o,
resolveOffset(getCurrentOffset()));
bufferDelta[bufferStackPos + 1] = 0;
}
super.pushContext(buffer, data);
}
protected IToken newToken(int signal, char[] buffer) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new ImagedExpansionToken(signal, buffer,
resolveOffset(data.startOffset), data.endOffset
- data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
IToken i = new ImagedToken(signal, buffer,
resolveOffset(bufferPos[bufferStackPos] + 1), EMPTY_CHAR_ARRAY,
getLineNumber(bufferPos[bufferStackPos] + 1));
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
&& signal != IToken.tLSTRING)
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some
// point
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/
protected Object popContext() {
//TODO calibrate offsets
Object result = super.popContext();
if (result instanceof CodeReader) {
locationMap.endTranslationUnit(bufferDelta[0]
+ ((CodeReader) result).buffer.length);
}
if (result instanceof InclusionData) {
CodeReader codeReader = ((InclusionData) result).reader;
if (log.isTracing()) {
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
buffer.append(codeReader.filename);
log.traceLog(buffer.toString());
}
return i;
}
locationMap.endInclusion(getGlobalCounter(bufferStackPos + 1)
+ bufferPos[bufferStackPos + 1]);
bufferDelta[bufferStackPos] += bufferDelta[bufferStackPos + 1]
+ codeReader.buffer.length;
}
return result;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/
protected void quickParsePushPopInclusion(Object inclusion) {
//do nothing
}
protected int getGlobalCounter(int value) {
if (value < 0)
return 0;
int result = bufferDelta[value];
for (int i = value - 1; i >= 0; --i)
result += bufferPos[i] + bufferDelta[i];
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
* int, char[])
*/
protected void handleProblem(int id, int offset, char[] arg) {
IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
int o = resolveOffset(offset);
((ScannerASTProblem) problem).setOffsetAndLength(o,
resolveOffset(getCurrentOffset() + 1) - o);
locationMap.encounterProblem(problem);
}
return result;
/**
* @param offset
* @return
*/
private int resolveOffset(int offset) {
return getGlobalCounter() + offset;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader,
* org.eclipse.cdt.core.parser.IScannerInfo)
*/
protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
super.postConstructorSetup(reader, info);
locationMap.startTranslationUnit(getMainReader());
}
protected int getGlobalCounter() {
return getGlobalCounter(bufferStackPos);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIfdef(int, int, boolean, boolean)
*/
protected void processIfdef(int startPos, int endPos, boolean positive, boolean taken) {
if( positive )
locationMap.encounterPoundIfdef( resolveOffset(startPos), resolveOffset(endPos), taken );
else
locationMap.encounterPoundIfndef( resolveOffset(startPos), resolveOffset(endPos), taken );
}
/**
* @return
*/
protected IToken newToken(int signal) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new SimpleExpansionToken(signal,
resolveOffset(data.startOffset), data.endOffset
- data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
return new SimpleToken(signal,
resolveOffset(bufferPos[bufferStackPos] + 1),
getCurrentFilename(),
getLineNumber(bufferPos[bufferStackPos] + 1));
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIf(int, int, boolean)
*/
protected void processIf(int startPos, int endPos, boolean taken) {
locationMap.encounterPoundIf( resolveOffset( startPos ), resolveOffset( endPos ), taken );
}
protected IToken newToken(int signal, char[] buffer) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new ImagedExpansionToken(signal, buffer,
resolveOffset(data.startOffset), data.endOffset
- data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
IToken i = new ImagedToken(signal, buffer,
resolveOffset(bufferPos[bufferStackPos] + 1), EMPTY_CHAR_ARRAY,
getLineNumber(bufferPos[bufferStackPos] + 1));
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
&& signal != IToken.tLSTRING)
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some
// point
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElsif(int, int, boolean)
*/
protected void processElsif(int startPos, int endPos, boolean taken) {
locationMap.encounterPoundElif( resolveOffset( startPos ), resolveOffset( endPos ), taken );
}
return i;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElse(int, int, boolean)
*/
protected void processElse(int startPos, int endPos, boolean taken) {
locationMap.encounterPoundElse( resolveOffset( startPos ), resolveOffset( endPos ), taken );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/
protected void quickParsePushPopInclusion(Object inclusion) {
//do nothing
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processUndef(int, int)
*/
protected void processUndef(int pos, int endPos) {
locationMap.encounterPoundUndef( resolveOffset( pos ), resolveOffset( endPos ));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
* int, char[])
*/
protected void handleProblem(int id, int offset, char[] arg) {
IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
int o = resolveOffset(offset);
((ScannerASTProblem) problem).setOffsetAndLength(o,
resolveOffset(getCurrentOffset() + 1) - o);
locationMap.encounterProblem(problem);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processError(int, int)
*/
protected void processError(int startPos, int endPos) {
locationMap.encounterPoundError( resolveOffset( startPos), resolveOffset( endPos ));
}
/**
* @param offset
* @return
*/
private int resolveOffset(int offset) {
return getGlobalCounter() + offset;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processEndif(int, int)
*/
protected void processEndif(int startPos , int endPos ) {
locationMap.encounterPoundEndIf( resolveOffset( startPos ), resolveOffset( endPos ));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader,
* org.eclipse.cdt.core.parser.IScannerInfo)
*/
protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
super.postConstructorSetup(reader, info);
locationMap.startTranslationUnit(getMainReader());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processPragma(int, int)
*/
protected void processPragma(int startPos, int endPos) {
locationMap.encounterPoundPragma( resolveOffset( startPos ), resolveOffset(endPos));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIfdef(int,
* int, boolean, boolean)
*/
protected void processIfdef(int startPos, int endPos, boolean positive,
boolean taken) {
if (positive)
locationMap.encounterPoundIfdef(resolveOffset(startPos),
resolveOffset(endPos), taken);
else
locationMap.encounterPoundIfndef(resolveOffset(startPos),
resolveOffset(endPos), taken);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIf(int,
* int, boolean)
*/
protected void processIf(int startPos, int endPos, boolean taken) {
locationMap.encounterPoundIf(resolveOffset(startPos),
resolveOffset(endPos), taken);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElsif(int,
* int, boolean)
*/
protected void processElsif(int startPos, int endPos, boolean taken) {
locationMap.encounterPoundElif(resolveOffset(startPos),
resolveOffset(endPos), taken);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElse(int,
* int, boolean)
*/
protected void processElse(int startPos, int endPos, boolean taken) {
locationMap.encounterPoundElse(resolveOffset(startPos),
resolveOffset(endPos), taken);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processUndef(int,
* int)
*/
protected void processUndef(int pos, int endPos) {
locationMap.encounterPoundUndef(resolveOffset(pos),
resolveOffset(endPos));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processError(int,
* int)
*/
protected void processError(int startPos, int endPos) {
locationMap.encounterPoundError(resolveOffset(startPos),
resolveOffset(endPos));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processEndif(int,
* int)
*/
protected void processEndif(int startPos, int endPos) {
locationMap.encounterPoundEndIf(resolveOffset(startPos),
resolveOffset(endPos));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processPragma(int,
* int)
*/
protected void processPragma(int startPos, int endPos) {
locationMap.encounterPoundPragma(resolveOffset(startPos),
resolveOffset(endPos));
}
}

View file

@ -18,34 +18,49 @@ import org.eclipse.cdt.core.parser.CodeReader;
*/
public interface IScannerPreprocessorLog {
public void startTranslationUnit( CodeReader tu_reader );
public void startTranslationUnit(CodeReader tu_reader);
public void endTranslationUnit(int offset);
public void startInclusion(CodeReader reader, int offset, int endOffset);
public void endInclusion(int offset);
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
int offset);
public void exitObjectStyleMacroExpansion(char[] name, int offset);
public void enterFunctionStyleExpansion(char[] name, char[][] parameters,
char[] expansion, int offset);
public void exitFunctionStyleExpansion(char[] name, int offset);
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset);
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset);
public void encounterPoundIf(int startOffset, int endOffset, boolean taken);
public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken);
public void encounterPoundIfndef( int startOffset, int endOffset, boolean taken );
public void encounterPoundElse(int startOffset, int endOffset, boolean taken );
public void encounterPoundIfdef(int startOffset, int endOffset,
boolean taken);
public void encounterPoundIfndef(int startOffset, int endOffset,
boolean taken);
public void encounterPoundElse(int startOffset, int endOffset, boolean taken);
public void encounterPoundElif(int startOffset, int endOffset, boolean taken);
public void encounterPoundEndIf(int startOffset, int endOffset);
public void encounterPoundPragma(int startOffset, int endOffset);
public void encounterPoundError(int startOffset, int endOffset);
public void encounterPoundUndef(int startOffset, int endOffset);
public void encounterProblem( IASTProblem problem );
public void encounterProblem(IASTProblem problem);
}

View file

@ -53,6 +53,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorEndifStatement {
}
/**
* @author jcamelon
*/
@ -60,12 +61,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorElifStatement {
private final boolean taken;
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
*/
public boolean taken() {
return taken;
}
/**
* @param taken
*/
@ -74,13 +79,17 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
static class ASTElse extends ScannerASTNode implements
IASTPreprocessorElseStatement {
private final boolean taken;
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
*/
public boolean taken() {
@ -95,20 +104,24 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
static class ASTIfndef extends ScannerASTNode implements IASTPreprocessorIfndefStatement {
static class ASTIfndef extends ScannerASTNode implements
IASTPreprocessorIfndefStatement {
private final boolean taken;
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
*/
public boolean taken() {
return taken;
}
/**
* @param taken
*/
@ -117,6 +130,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
@ -124,7 +138,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorIfdefStatement {
private final boolean taken;
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
*/
public boolean taken() {
@ -139,6 +156,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
@ -146,7 +164,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorIfStatement {
private final boolean taken;
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
*/
public boolean taken() {
@ -161,6 +182,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
}
/**
* @author jcamelon
*/
@ -168,6 +190,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorErrorStatement {
}
/**
* @author jcamelon
*/
@ -175,6 +198,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorPragmaStatement {
}
/**
* @author jcamelon
*/
@ -182,6 +206,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorUndefStatement {
}
/**
* @author jcamelon
*/
@ -886,9 +911,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_MACRO_DEFINITIONS_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_INCLUDES_ARRAY = new IASTPreprocessorIncludeStatement[0];
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_ARRAY = new IASTPreprocessorStatement[0];
/*
@ -956,9 +985,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_Context[] contexts = new _Context[size];
collectContexts(V_INCLUSIONS, tu, contexts, 0);
IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[size];
for (int i = 0; i < size; ++i)
for (int i = 0; i < size; ++i)
result[i] = createASTInclusion(((_Inclusion) contexts[i]));
return result;
}
@ -969,8 +998,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) {
IASTPreprocessorIncludeStatement result = new ASTInclusionStatement(
inc.reader.filename);
((ScannerASTNode) result).setOffsetAndLength(inc.context_directive_start,
inc.context_directive_end - inc.context_directive_start);
((ScannerASTNode) result).setOffsetAndLength(
inc.context_directive_start, inc.context_directive_end
- inc.context_directive_start);
((ASTInclusionStatement) result).startOffset = inc.context_directive_end;
((ASTInclusionStatement) result).endOffset = inc.context_ends;
return result;
@ -988,32 +1018,31 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
_Context[] contexts = new _Context[size];
collectContexts(V_PREPROCESSOR, tu, contexts, 0);
IASTPreprocessorStatement[] result = new IASTPreprocessorStatement[size];
for (int i = 0; i < size; ++i)
{
if( contexts[i] instanceof _Inclusion )
for (int i = 0; i < size; ++i) {
if (contexts[i] instanceof _Inclusion)
result[i] = createASTInclusion(((_Inclusion) contexts[i]));
else if( contexts[i] instanceof _MacroDefinition )
result[i] = createASTMacroDefinition( (_MacroDefinition) contexts[i] );
else if ( contexts[i] instanceof _Undef )
result[i] = createASTUndef( (_Undef)contexts[i] );
else if ( contexts[i] instanceof _Pragma )
result[i] = createASTPragma( (_Pragma)contexts[i]);
else if ( contexts[i] instanceof _Error )
result[i] = createASTError( (_Error)contexts[i] );
else if ( contexts[i] instanceof _If )
result[i] = createASTIf( (_If)contexts[i] );
else if( contexts[i] instanceof _Ifdef )
result[i] = createASTIfdef( (_Ifdef)contexts[i] );
else if( contexts[i] instanceof _Ifndef )
result[i] = createASTIfndef( (_Ifndef)contexts[i]);
else if( contexts[i] instanceof _Else )
result[i] = createASTElse( (_Else)contexts[i] );
else if ( contexts[i] instanceof _Elif )
result[i] = createASTElif( (_Elif)contexts[i] );
else if( contexts[i] instanceof _Endif )
result[i] = createASTEndif( (_Endif)contexts[i ]);
else if (contexts[i] instanceof _MacroDefinition)
result[i] = createASTMacroDefinition((_MacroDefinition) contexts[i]);
else if (contexts[i] instanceof _Undef)
result[i] = createASTUndef((_Undef) contexts[i]);
else if (contexts[i] instanceof _Pragma)
result[i] = createASTPragma((_Pragma) contexts[i]);
else if (contexts[i] instanceof _Error)
result[i] = createASTError((_Error) contexts[i]);
else if (contexts[i] instanceof _If)
result[i] = createASTIf((_If) contexts[i]);
else if (contexts[i] instanceof _Ifdef)
result[i] = createASTIfdef((_Ifdef) contexts[i]);
else if (contexts[i] instanceof _Ifndef)
result[i] = createASTIfndef((_Ifndef) contexts[i]);
else if (contexts[i] instanceof _Else)
result[i] = createASTElse((_Else) contexts[i]);
else if (contexts[i] instanceof _Elif)
result[i] = createASTElif((_Elif) contexts[i]);
else if (contexts[i] instanceof _Endif)
result[i] = createASTEndif((_Endif) contexts[i]);
}
return result;
}
@ -1023,7 +1052,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTEndif(_Endif endif) {
IASTPreprocessorEndifStatement result = new ASTEndif();
((ASTNode)result).setOffsetAndLength( endif.context_directive_start, endif.context_directive_end - endif.context_directive_start );
((ASTNode) result).setOffsetAndLength(endif.context_directive_start,
endif.context_directive_end - endif.context_directive_start);
return result;
}
@ -1033,7 +1063,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTElif(_Elif elif) {
IASTPreprocessorElifStatement result = new ASTElif(elif.taken);
((ASTNode)result).setOffsetAndLength( elif.context_directive_start, elif.context_directive_end - elif.context_directive_start);
((ASTNode) result).setOffsetAndLength(elif.context_directive_start,
elif.context_directive_end - elif.context_directive_start);
return result;
}
@ -1043,7 +1074,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTElse(_Else e) {
IASTPreprocessorElseStatement result = new ASTElse(e.taken);
((ASTNode)result).setOffsetAndLength( e.context_directive_start, e.context_directive_end- e.context_directive_start );
((ASTNode) result).setOffsetAndLength(e.context_directive_start,
e.context_directive_end - e.context_directive_start);
return result;
}
@ -1053,7 +1085,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTIfndef(_Ifndef ifndef) {
IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken);
((ASTNode)result).setOffsetAndLength( ifndef.context_directive_start, ifndef.context_directive_end - ifndef.context_directive_start );
((ASTNode) result).setOffsetAndLength(ifndef.context_directive_start,
ifndef.context_directive_end - ifndef.context_directive_start);
return result;
}
@ -1063,7 +1096,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTIfdef(_Ifdef ifdef) {
IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken);
((ASTNode)result).setOffsetAndLength( ifdef.context_directive_start, ifdef.context_directive_end - ifdef.context_directive_start);
((ASTNode) result).setOffsetAndLength(ifdef.context_directive_start,
ifdef.context_directive_end - ifdef.context_directive_start);
return result;
}
@ -1071,9 +1105,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param if1
* @return
*/
private IASTPreprocessorStatement createASTIf(_If i ) {
private IASTPreprocessorStatement createASTIf(_If i) {
IASTPreprocessorIfStatement result = new ASTIf(i.taken);
((ASTNode)result).setOffsetAndLength( i.context_directive_start, i.context_directive_end - - i.context_directive_start );
((ASTNode) result).setOffsetAndLength(i.context_directive_start,
i.context_directive_end - -i.context_directive_start);
return result;
}
@ -1083,7 +1118,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTError(_Error error) {
IASTPreprocessorErrorStatement result = new ASTError();
((ASTNode)result).setOffsetAndLength( error.context_directive_start, error.context_directive_end - error.context_directive_start);
((ASTNode) result).setOffsetAndLength(error.context_directive_start,
error.context_directive_end - error.context_directive_start);
return result;
}
@ -1102,7 +1138,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/
private IASTPreprocessorStatement createASTUndef(_Undef undef) {
IASTPreprocessorUndefStatement result = new ASTUndef();
((ASTNode)result).setOffsetAndLength( undef.context_directive_start, undef.context_directive_end - undef.context_directive_start );
((ASTNode) result).setOffsetAndLength(undef.context_directive_start,
undef.context_directive_end - undef.context_directive_start);
return result;
}