mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 11:55:40 +02:00
Added other preprocesser to LocationMap.
This commit is contained in:
parent
88562cda49
commit
a74c7f1bf4
5 changed files with 439 additions and 65 deletions
|
@ -2444,13 +2444,13 @@ abstract class BaseScanner implements IScanner {
|
||||||
handlePPDefine(pos, startingLineNumber);
|
handlePPDefine(pos, startingLineNumber);
|
||||||
return;
|
return;
|
||||||
case ppUndef:
|
case ppUndef:
|
||||||
handlePPUndef();
|
handlePPUndef(pos);
|
||||||
return;
|
return;
|
||||||
case ppIfdef:
|
case ppIfdef:
|
||||||
handlePPIfdef(true);
|
handlePPIfdef(pos, true);
|
||||||
return;
|
return;
|
||||||
case ppIfndef:
|
case ppIfndef:
|
||||||
handlePPIfdef(false);
|
handlePPIfdef(pos, false);
|
||||||
return;
|
return;
|
||||||
case ppIf:
|
case ppIf:
|
||||||
start = bufferPos[bufferStackPos] + 1;
|
start = bufferPos[bufferStackPos] + 1;
|
||||||
|
@ -2466,13 +2466,19 @@ abstract class BaseScanner implements IScanner {
|
||||||
skipOverConditionalCode(true);
|
skipOverConditionalCode(true);
|
||||||
if (isLimitReached())
|
if (isLimitReached())
|
||||||
handleInvalidCompletion();
|
handleInvalidCompletion();
|
||||||
|
processIf( pos, bufferPos[bufferStackPos], true );
|
||||||
}
|
}
|
||||||
|
processIf( pos, bufferPos[bufferStackPos], false );
|
||||||
return;
|
return;
|
||||||
case ppElse:
|
case ppElse:
|
||||||
case ppElif:
|
case ppElif:
|
||||||
// Condition must have been true, skip over the rest
|
// Condition must have been true, skip over the rest
|
||||||
|
|
||||||
if (branchState(type == ppElse ? BRANCH_ELSE : BRANCH_ELIF)) {
|
if (branchState(type == ppElse ? BRANCH_ELSE : BRANCH_ELIF)) {
|
||||||
|
if( type == ppElse )
|
||||||
|
processElse( pos, bufferPos[bufferStackPos], false );
|
||||||
|
else
|
||||||
|
processElsif( pos, bufferPos[bufferStackPos], false );
|
||||||
skipToNewLine();
|
skipToNewLine();
|
||||||
skipOverConditionalCode(false);
|
skipOverConditionalCode(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2495,12 +2501,17 @@ abstract class BaseScanner implements IScanner {
|
||||||
len = bufferPos[bufferStackPos] - start;
|
len = bufferPos[bufferStackPos] - start;
|
||||||
handleProblem(IProblem.PREPROCESSOR_POUND_ERROR, start,
|
handleProblem(IProblem.PREPROCESSOR_POUND_ERROR, start,
|
||||||
CharArrayUtils.extract(buffer, start, len));
|
CharArrayUtils.extract(buffer, start, len));
|
||||||
|
processError( pos, pos + len );
|
||||||
break;
|
break;
|
||||||
case ppEndif:
|
case ppEndif:
|
||||||
if (!branchState(BRANCH_END))
|
if (!branchState(BRANCH_END))
|
||||||
handleProblem(IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
|
handleProblem(IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
|
||||||
start, ppKeywords.findKey(buffer, start, len));
|
start, ppKeywords.findKey(buffer, start, len));
|
||||||
|
processEndif( pos, bufferPos[bufferStackPos ] );
|
||||||
break;
|
break;
|
||||||
|
case ppPragma:
|
||||||
|
skipToNewLine();
|
||||||
|
processPragma( pos, bufferPos[bufferStackPos ]);
|
||||||
default:
|
default:
|
||||||
problem = true;
|
problem = true;
|
||||||
break;
|
break;
|
||||||
|
@ -2517,6 +2528,33 @@ abstract class BaseScanner implements IScanner {
|
||||||
skipToNewLine();
|
skipToNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param startPos
|
||||||
|
* @param endPos
|
||||||
|
*/
|
||||||
|
protected abstract void processPragma(int startPos, int endPos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pos
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
|
protected abstract void processEndif(int pos, int i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param startPos
|
||||||
|
* @param endPos
|
||||||
|
*/
|
||||||
|
protected abstract void processError(int startPos, int endPos);
|
||||||
|
protected abstract void processElsif(int startPos, int endPos, boolean taken);
|
||||||
|
protected abstract void processElse(int startPos, int endPos, boolean taken);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pos
|
||||||
|
* @param i
|
||||||
|
* @param b
|
||||||
|
*/
|
||||||
|
protected abstract void processIf(int startPos, int endPos, boolean taken );
|
||||||
|
|
||||||
protected void handlePPInclude(int pos2, boolean include_next, int startingLineNumber) {
|
protected void handlePPInclude(int pos2, boolean include_next, int startingLineNumber) {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
int limit = bufferLimit[bufferStackPos];
|
int limit = bufferLimit[bufferStackPos];
|
||||||
|
@ -3026,7 +3064,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
return CharArrayUtils.trim(result);
|
return CharArrayUtils.trim(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handlePPUndef() throws EndOfFileException {
|
protected void handlePPUndef(int pos) throws EndOfFileException {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
int limit = bufferLimit[bufferStackPos];
|
int limit = bufferLimit[bufferStackPos];
|
||||||
|
|
||||||
|
@ -3063,11 +3101,18 @@ abstract class BaseScanner implements IScanner {
|
||||||
handleCompletionOnDefinition(new String(buffer, idstart, idlen));
|
handleCompletionOnDefinition(new String(buffer, idstart, idlen));
|
||||||
|
|
||||||
skipToNewLine();
|
skipToNewLine();
|
||||||
|
processUndef( pos, bufferPos[bufferStackPos] );
|
||||||
|
|
||||||
definitions.remove(buffer, idstart, idlen);
|
definitions.remove(buffer, idstart, idlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handlePPIfdef(boolean positive) throws EndOfFileException {
|
/**
|
||||||
|
* @param pos
|
||||||
|
* @param endPos
|
||||||
|
*/
|
||||||
|
protected abstract void processUndef(int pos, int endPos);
|
||||||
|
|
||||||
|
protected void handlePPIfdef(int pos, boolean positive) throws EndOfFileException {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
int limit = bufferLimit[bufferStackPos];
|
int limit = bufferLimit[bufferStackPos];
|
||||||
|
|
||||||
|
@ -3114,16 +3159,19 @@ abstract class BaseScanner implements IScanner {
|
||||||
branchState(BRANCH_IF);
|
branchState(BRANCH_IF);
|
||||||
|
|
||||||
if ((definitions.get(buffer, idstart, idlen) != null) == positive) {
|
if ((definitions.get(buffer, idstart, idlen) != null) == positive) {
|
||||||
// continue on
|
processIfdef( pos, bufferPos[bufferStackPos], positive, true );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processIfdef( pos, bufferPos[bufferStackPos], positive, false );
|
||||||
// skip over this group
|
// skip over this group
|
||||||
skipOverConditionalCode(true);
|
skipOverConditionalCode(true);
|
||||||
if (isLimitReached())
|
if (isLimitReached())
|
||||||
handleInvalidCompletion();
|
handleInvalidCompletion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void processIfdef(int startPos, int endPos, boolean positive, boolean taken);
|
||||||
|
|
||||||
// checkelse - if potential for more, otherwise skip to endif
|
// checkelse - if potential for more, otherwise skip to endif
|
||||||
protected void skipOverConditionalCode(boolean checkelse) {
|
protected void skipOverConditionalCode(boolean checkelse) {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
|
@ -3139,6 +3187,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
char c = buffer[bufferPos[bufferStackPos]];
|
char c = buffer[bufferPos[bufferStackPos]];
|
||||||
if (c == '#') {
|
if (c == '#') {
|
||||||
|
int startPos = bufferPos[bufferStackPos];
|
||||||
skipOverWhiteSpace();
|
skipOverWhiteSpace();
|
||||||
|
|
||||||
// find the directive
|
// find the directive
|
||||||
|
@ -3166,13 +3215,22 @@ abstract class BaseScanner implements IScanner {
|
||||||
case ppIf:
|
case ppIf:
|
||||||
++nesting;
|
++nesting;
|
||||||
branchState(BRANCH_IF);
|
branchState(BRANCH_IF);
|
||||||
|
skipToNewLine();
|
||||||
|
if( type == ppIfdef )
|
||||||
|
processIfdef( startPos, bufferPos[bufferStackPos], true, false );
|
||||||
|
else if( type == ppIfndef )
|
||||||
|
processIfdef( startPos, bufferPos[bufferStackPos], false, false );
|
||||||
|
else
|
||||||
|
processIf( startPos, bufferPos[bufferStackPos], false );
|
||||||
break;
|
break;
|
||||||
case ppElse:
|
case ppElse:
|
||||||
if (branchState(BRANCH_ELSE)) {
|
if (branchState(BRANCH_ELSE)) {
|
||||||
|
skipToNewLine();
|
||||||
if (checkelse && nesting == 0) {
|
if (checkelse && nesting == 0) {
|
||||||
skipToNewLine();
|
processElse( startPos, bufferPos[ bufferStackPos], true );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
processElse( startPos, bufferPos[ bufferStackPos], false );
|
||||||
} else {
|
} else {
|
||||||
//problem, ignore this one.
|
//problem, ignore this one.
|
||||||
handleProblem(
|
handleProblem(
|
||||||
|
@ -3192,8 +3250,17 @@ abstract class BaseScanner implements IScanner {
|
||||||
len, definitions,
|
len, definitions,
|
||||||
getLineNumber(bufferPos[bufferStackPos]),
|
getLineNumber(bufferPos[bufferStackPos]),
|
||||||
getCurrentFilename()) != 0)
|
getCurrentFilename()) != 0)
|
||||||
|
{
|
||||||
// condition passed, we're good
|
// condition passed, we're good
|
||||||
|
processElsif( start, bufferPos[bufferStackPos], true);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
processElsif( start, bufferPos[bufferStackPos], false );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
skipToNewLine();
|
||||||
|
processElsif( start, bufferPos[bufferStackPos], false );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//problem, ignore this one.
|
//problem, ignore this one.
|
||||||
|
@ -3205,6 +3272,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
break;
|
break;
|
||||||
case ppEndif:
|
case ppEndif:
|
||||||
if (branchState(BRANCH_END)) {
|
if (branchState(BRANCH_END)) {
|
||||||
|
processEndif( startPos, bufferPos[ bufferStackPos ]);
|
||||||
if (nesting > 0) {
|
if (nesting > 0) {
|
||||||
--nesting;
|
--nesting;
|
||||||
} else {
|
} else {
|
||||||
|
@ -4375,6 +4443,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
protected static final int ppUndef = 8;
|
protected static final int ppUndef = 8;
|
||||||
protected static final int ppError = 9;
|
protected static final int ppError = 9;
|
||||||
protected static final int ppInclude_next = 10;
|
protected static final int ppInclude_next = 10;
|
||||||
|
protected static final int ppPragma = 11;
|
||||||
|
|
||||||
protected static final char[] TAB = { '\t' };
|
protected static final char[] TAB = { '\t' };
|
||||||
protected static final char[] SPACE = { ' ' };
|
protected static final char[] SPACE = { ' ' };
|
||||||
|
|
|
@ -276,4 +276,64 @@ public class DOMScanner extends BaseScanner {
|
||||||
super.throwEOF();
|
super.throwEOF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -38,13 +38,14 @@ public interface IScannerPreprocessorLog {
|
||||||
int nameOffset, int nameEndOffset, int endOffset);
|
int nameOffset, int nameEndOffset, int endOffset);
|
||||||
|
|
||||||
public void encounterPoundIf(int startOffset, int endOffset, boolean taken);
|
public void encounterPoundIf(int startOffset, int endOffset, boolean taken);
|
||||||
public void encounterPoundPragma(int startOffset, int endOffset);
|
|
||||||
public void encounterPoundError(int startOffset, int endOffset);
|
|
||||||
public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken);
|
public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken);
|
||||||
public void encounterPoundUndef(int startOffset, int endOffset);
|
public void encounterPoundIfndef( int startOffset, int endOffset, boolean taken );
|
||||||
public void encounterPoundElse(int startOffset, int endOffset);
|
public void encounterPoundElse(int startOffset, int endOffset, boolean taken );
|
||||||
public void encounterPoundElif(int startOffset, int endOffset, boolean taken);
|
public void encounterPoundElif(int startOffset, int endOffset, boolean taken);
|
||||||
public void encounterPoundEndIf(int startOffset, int endOffset);
|
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 );
|
||||||
}
|
}
|
|
@ -40,7 +40,148 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
protected static class _InclusionStatement extends ScannerASTNode implements
|
protected static class _Endif extends _Context implements
|
||||||
|
_IPreprocessorDirective{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Endif(_CompositeContext parent, int startOffset, int endOffset) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class _Elif extends _Context implements
|
||||||
|
_IPreprocessorDirective {
|
||||||
|
|
||||||
|
public final boolean taken;
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Elif(_CompositeContext parent, int startOffset, int endOffset, boolean taken ) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
this.taken = taken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class _Ifdef extends _Context implements
|
||||||
|
_IPreprocessorDirective {
|
||||||
|
|
||||||
|
public final boolean taken;
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Ifdef(_CompositeContext parent, int startOffset, int endOffset, boolean taken) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
this.taken = taken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class _Ifndef extends _Context implements
|
||||||
|
_IPreprocessorDirective {
|
||||||
|
|
||||||
|
public final boolean taken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Ifndef(_CompositeContext parent, int startOffset, int endOffset, boolean taken ) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
this.taken = taken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class _Error extends _Context implements
|
||||||
|
_IPreprocessorDirective {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Error(_CompositeContext parent, int startOffset, int endOffset) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class _Pragma extends _Context implements
|
||||||
|
_IPreprocessorDirective {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Pragma(_CompositeContext parent, int startOffset, int endOffset) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected class _If extends _Context implements _IPreprocessorDirective {
|
||||||
|
|
||||||
|
public final boolean taken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _If(_CompositeContext parent, int startOffset, int endOffset, boolean taken) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
this.taken = taken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class _Else extends _Context implements
|
||||||
|
_IPreprocessorDirective {
|
||||||
|
|
||||||
|
public final boolean taken;
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Else(_CompositeContext parent, int startOffset, int endOffset, boolean taken) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
this.taken = taken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
protected static class ASTInclusionStatement extends ScannerASTNode implements
|
||||||
IASTPreprocessorIncludeStatement {
|
IASTPreprocessorIncludeStatement {
|
||||||
|
|
||||||
private final char[] path;
|
private final char[] path;
|
||||||
|
@ -48,7 +189,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
/**
|
/**
|
||||||
* @param cs
|
* @param cs
|
||||||
*/
|
*/
|
||||||
public _InclusionStatement(char[] cs) {
|
public ASTInclusionStatement(char[] cs) {
|
||||||
this.path = cs;
|
this.path = cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +301,25 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ScannerASTNode extends ASTNode {
|
public static interface _IPreprocessorDirective
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class _Undef extends _Context implements _IPreprocessorDirective
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param parent
|
||||||
|
* @param startOffset
|
||||||
|
* @param endOffset
|
||||||
|
*/
|
||||||
|
public _Undef(_CompositeContext parent, int startOffset, int endOffset) {
|
||||||
|
super(parent, startOffset, endOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class ScannerASTNode extends ASTNode {
|
||||||
private IASTNode parent;
|
private IASTNode parent;
|
||||||
private ASTNodeProperty property;
|
private ASTNodeProperty property;
|
||||||
|
|
||||||
|
@ -436,7 +595,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _Inclusion extends _CompositeContext {
|
protected static class _Inclusion extends _CompositeContext implements _IPreprocessorDirective {
|
||||||
public final CodeReader reader;
|
public final CodeReader reader;
|
||||||
|
|
||||||
public _Inclusion(_CompositeContext parent, CodeReader reader,
|
public _Inclusion(_CompositeContext parent, CodeReader reader,
|
||||||
|
@ -481,7 +640,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
public final int nameOffset;
|
public final int nameOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _ObjectMacroDefinition extends _MacroDefinition {
|
protected static class _ObjectMacroDefinition extends _MacroDefinition implements _IPreprocessorDirective {
|
||||||
/**
|
/**
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param startOffset
|
* @param startOffset
|
||||||
|
@ -498,7 +657,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class _FunctionMacroDefinition extends _MacroDefinition {
|
protected static class _FunctionMacroDefinition extends _MacroDefinition implements _IPreprocessorDirective {
|
||||||
|
|
||||||
public final char[][] parms;
|
public final char[][] parms;
|
||||||
|
|
||||||
|
@ -552,14 +711,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
||||||
*/
|
*/
|
||||||
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
||||||
List contexts = new ArrayList(8);
|
int size = collectContexts(V_MACRODEFS, tu, null, 0);
|
||||||
LocationMap.collectContexts(V_MACRODEFS, tu, contexts);
|
if( size == 0 ) return EMPTY_MACRO_DEFINITIONS_ARRAY;
|
||||||
if (contexts.isEmpty())
|
_Context [] contexts = new _Context[size];
|
||||||
return EMPTY_MACRO_DEFINITIONS_ARRAY;
|
collectContexts(V_MACRODEFS, tu, contexts, 0);
|
||||||
|
|
||||||
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts
|
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts
|
||||||
.size()];
|
.length];
|
||||||
for (int i = 0; i < contexts.size(); ++i)
|
for (int i = 0; i < contexts.length; ++i)
|
||||||
result[i] = createASTMacroDefinition((_MacroDefinition) contexts.get(i));
|
result[i] = createASTMacroDefinition((_MacroDefinition) contexts[i]);
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -603,16 +763,16 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*
|
*
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives()
|
||||||
*/
|
*/
|
||||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||||
List contexts = new ArrayList(8);
|
int size = collectContexts(V_INCLUSIONS, tu, null, 0);
|
||||||
collectContexts(V_INCLUSIONS, tu, contexts);
|
if (size == 0 )
|
||||||
if (contexts.isEmpty())
|
|
||||||
return EMPTY_INCLUDES_ARRAY;
|
return EMPTY_INCLUDES_ARRAY;
|
||||||
IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[contexts
|
_Context [] contexts = new _Context[size];
|
||||||
.size()];
|
collectContexts(V_INCLUSIONS, tu, contexts, 0);
|
||||||
for (int i = 0; i < contexts.size(); ++i) {
|
IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[size];
|
||||||
_Inclusion inc = ((_Inclusion) contexts.get(i));
|
for (int i = 0; i < size; ++i) {
|
||||||
result[i] = new _InclusionStatement(inc.reader.filename);
|
_Inclusion inc = ((_Inclusion) contexts[i]);
|
||||||
|
result[i] = new ASTInclusionStatement(inc.reader.filename);
|
||||||
((ScannerASTNode) result[i]).setOffsetAndLength(
|
((ScannerASTNode) result[i]).setOffsetAndLength(
|
||||||
inc.context_directive_start, inc.context_directive_end
|
inc.context_directive_start, inc.context_directive_end
|
||||||
- inc.context_directive_start);
|
- inc.context_directive_start);
|
||||||
|
@ -877,7 +1037,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundIf(int startOffset, int endOffset, boolean taken) {
|
public void encounterPoundIf(int startOffset, int endOffset, boolean taken) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _If( currentContext, startOffset, endOffset, taken ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,8 +1048,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundPragma(int startOffset, int endOffset) {
|
public void encounterPoundPragma(int startOffset, int endOffset) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Pragma( currentContext, startOffset, endOffset ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -899,8 +1058,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundError(int startOffset, int endOffset) {
|
public void encounterPoundError(int startOffset, int endOffset) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Error( currentContext, startOffset, endOffset ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -910,8 +1068,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken) {
|
public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Ifdef( currentContext, startOffset, endOffset, taken ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -921,8 +1078,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundUndef(int startOffset, int endOffset) {
|
public void encounterPoundUndef(int startOffset, int endOffset) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Undef( currentContext, startOffset, endOffset ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -931,9 +1087,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElse(int,
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElse(int,
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundElse(int startOffset, int endOffset) {
|
public void encounterPoundElse(int startOffset, int endOffset, boolean taken) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Else( currentContext, startOffset, endOffset, taken ));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -943,7 +1098,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundElif(int startOffset, int endOffset, boolean taken) {
|
public void encounterPoundElif(int startOffset, int endOffset, boolean taken) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Elif( currentContext, startOffset, endOffset, taken ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -954,8 +1109,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void encounterPoundEndIf(int startOffset, int endOffset) {
|
public void encounterPoundEndIf(int startOffset, int endOffset) {
|
||||||
// TODO Auto-generated method stub
|
currentContext.addSubContext( new _Endif( currentContext, startOffset, endOffset) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -982,13 +1136,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems()
|
||||||
*/
|
*/
|
||||||
public IASTProblem[] getScannerProblems() {
|
public IASTProblem[] getScannerProblems() {
|
||||||
List contexts = new ArrayList(8);
|
int size = LocationMap.collectContexts(V_PROBLEMS, tu, null, 0);
|
||||||
LocationMap.collectContexts(V_PROBLEMS, tu, contexts);
|
if( size == 0 ) return EMPTY_PROBLEMS_ARRAY;
|
||||||
if (contexts.isEmpty())
|
_Context [] contexts = new _Context[size];
|
||||||
return EMPTY_PROBLEMS_ARRAY;
|
LocationMap.collectContexts(V_PROBLEMS, tu, contexts, 0);
|
||||||
IASTProblem[] result = new IASTProblem[contexts.size()];
|
IASTProblem[] result = new IASTProblem[size];
|
||||||
for (int i = 0; i < contexts.size(); ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
result[i] = ((_Problem) contexts.get(i)).problem;
|
result[i] = ((_Problem) contexts[i]).problem;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1003,37 +1157,69 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
_Problem pr = new _Problem(currentContext, p.getOffset(), p.getOffset()
|
_Problem pr = new _Problem(currentContext, p.getOffset(), p.getOffset()
|
||||||
+ p.getLength(), problem);
|
+ p.getLength(), problem);
|
||||||
pr.context_ends = p.getOffset() + p.getLength();
|
pr.context_ends = p.getOffset() + p.getLength();
|
||||||
|
currentContext.addSubContext( pr );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final int V_ALL = 1;
|
protected static final int V_ALL = 1;
|
||||||
protected static final int V_INCLUSIONS = 2;
|
protected static final int V_INCLUSIONS = 2;
|
||||||
protected static final int V_PROBLEMS = 3;
|
protected static final int V_PROBLEMS = 3;
|
||||||
protected static final int V_MACRODEFS = 4;
|
protected static final int V_MACRODEFS = 4;
|
||||||
|
protected static final int V_PREPROCESSOR = 5;
|
||||||
private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
|
private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
|
||||||
|
|
||||||
protected static void collectContexts(int key, _Context source, List result) {
|
protected static int collectContexts(int key, _Context source, _Context[] result, int s ) {
|
||||||
|
int startAt = s;
|
||||||
|
int count = 0;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case V_ALL:
|
case V_ALL:
|
||||||
result.add(source);
|
if( result != null )
|
||||||
|
result[startAt++] = source;
|
||||||
|
++count;
|
||||||
break;
|
break;
|
||||||
case V_INCLUSIONS:
|
case V_INCLUSIONS:
|
||||||
if (source instanceof _Inclusion)
|
if (source instanceof _Inclusion)
|
||||||
result.add(source);
|
{
|
||||||
|
if( result != null )
|
||||||
|
result[startAt++] = source;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case V_PROBLEMS:
|
case V_PROBLEMS:
|
||||||
if (source instanceof _Problem)
|
if (source instanceof _Problem)
|
||||||
result.add(source);
|
{
|
||||||
|
|
||||||
|
if( result != null )
|
||||||
|
result[startAt++] = source;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case V_MACRODEFS:
|
case V_MACRODEFS:
|
||||||
if (source instanceof _MacroDefinition)
|
if (source instanceof _MacroDefinition)
|
||||||
result.add(source);
|
{
|
||||||
|
if( result != null )
|
||||||
|
result[startAt++] = source;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case V_PREPROCESSOR:
|
||||||
|
if( source instanceof _IPreprocessorDirective )
|
||||||
|
{
|
||||||
|
if( result != null )
|
||||||
|
result[startAt++] = source;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (source instanceof _CompositeContext) {
|
if (source instanceof _CompositeContext) {
|
||||||
List l = ((_CompositeContext) source).getSubContexts();
|
List l = ((_CompositeContext) source).getSubContexts();
|
||||||
for (int i = 0; i < l.size(); ++i)
|
for (int i = 0; i < l.size(); ++i)
|
||||||
collectContexts(key, (_Context) l.get(i), result);
|
{
|
||||||
|
int value = collectContexts(key, (_Context) l.get(i), result, startAt);
|
||||||
|
count += value;
|
||||||
|
startAt += value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -1050,11 +1236,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
char [] name = ((IASTFileLocation)nodeLocation).getFileName().toCharArray();
|
char [] name = ((IASTFileLocation)nodeLocation).getFileName().toCharArray();
|
||||||
if( readerCompatable( nodeLocation, tu.reader, name ) )
|
if( readerCompatable( nodeLocation, tu.reader, name ) )
|
||||||
return CharArrayUtils.extract( tu.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() );
|
return CharArrayUtils.extract( tu.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() );
|
||||||
List inclusions = new ArrayList();
|
|
||||||
collectContexts( V_INCLUSIONS, tu, inclusions );
|
int size = collectContexts( V_INCLUSIONS, tu, null, 0 );
|
||||||
for( int i = 0; i < inclusions.size(); ++i )
|
if( size == 0 ) return EMPTY_CHAR_ARRAY;
|
||||||
|
_Context [] inclusions = new _Context[size];
|
||||||
|
collectContexts( V_INCLUSIONS, tu, inclusions, 0 );
|
||||||
|
for( int i = 0; i < size; ++i )
|
||||||
{
|
{
|
||||||
_Inclusion inc = (_Inclusion) inclusions.get(i);
|
_Inclusion inc = (_Inclusion) inclusions[i];
|
||||||
if( readerCompatable( nodeLocation, inc.reader, name ) )
|
if( readerCompatable( nodeLocation, inc.reader, name ) )
|
||||||
return CharArrayUtils.extract( inc.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() );
|
return CharArrayUtils.extract( inc.reader.buffer, nodeLocation.getNodeOffset(), nodeLocation.getNodeLength() );
|
||||||
}
|
}
|
||||||
|
@ -1081,4 +1270,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfndef(int, int, boolean)
|
||||||
|
*/
|
||||||
|
public void encounterPoundIfndef(int startOffset, int endOffset, boolean taken) {
|
||||||
|
currentContext.addSubContext( new _Ifndef( currentContext, startOffset, endOffset, taken ) );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -254,4 +254,52 @@ public class Scanner2 extends BaseScanner {
|
||||||
return super.popContext();
|
return super.popContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIf(int, int, boolean)
|
||||||
|
*/
|
||||||
|
protected void processIf(int startPos, int endPos, boolean 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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElse(int, int, boolean)
|
||||||
|
*/
|
||||||
|
protected void processElse(int startPos, int endPos, boolean taken) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processUndef(int, int)
|
||||||
|
*/
|
||||||
|
protected void processUndef(int pos, int endPos) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processError(int, int)
|
||||||
|
*/
|
||||||
|
protected void processError(int startPos, int endPos) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processEndif(int, int)
|
||||||
|
*/
|
||||||
|
protected void processEndif(int pos, int i) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processPragma(int, int)
|
||||||
|
*/
|
||||||
|
protected void processPragma(int startPos, int endPos) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue