1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-08-06 20:14:16 -07:00
parent 71d5459a41
commit 60de352b8e

View file

@ -6,10 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
@ -63,11 +63,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
public static final String PROP_VALUE = "CPreprocessor"; //$NON-NLS-1$ public static final String PROP_VALUE = "CPreprocessor"; //$NON-NLS-1$
public static final int tDEFINED= IToken.FIRST_RESERVED_PREPROCESSOR; public static final int tDEFINED= IToken.FIRST_RESERVED_PREPROCESSOR;
public static final int tEXPANDED_IDENTIFIER= IToken.FIRST_RESERVED_PREPROCESSOR+1; public static final int tEXPANDED_IDENTIFIER= IToken.FIRST_RESERVED_PREPROCESSOR + 1;
public static final int tSCOPE_MARKER= IToken.FIRST_RESERVED_PREPROCESSOR+2; public static final int tSCOPE_MARKER= IToken.FIRST_RESERVED_PREPROCESSOR + 2;
public static final int tSPACE= IToken.FIRST_RESERVED_PREPROCESSOR+3; public static final int tSPACE= IToken.FIRST_RESERVED_PREPROCESSOR + 3;
public static final int tNOSPACE= IToken.FIRST_RESERVED_PREPROCESSOR+4; public static final int tNOSPACE= IToken.FIRST_RESERVED_PREPROCESSOR + 4;
public static final int tMACRO_PARAMETER= IToken.FIRST_RESERVED_PREPROCESSOR+5; public static final int tMACRO_PARAMETER= IToken.FIRST_RESERVED_PREPROCESSOR + 5;
private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE; private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
private static final int ORIGIN_INACTIVE_CODE = OffsetLimitReachedException.ORIGIN_INACTIVE_CODE; private static final int ORIGIN_INACTIVE_CODE = OffsetLimitReachedException.ORIGIN_INACTIVE_CODE;
@ -81,7 +81,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro("__cplusplus".toCharArray(), ONE); //$NON-NLS-1$ private static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro("__cplusplus".toCharArray(), ONE); //$NON-NLS-1$
private static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro("__STDC__".toCharArray(), ONE); //$NON-NLS-1$ private static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro("__STDC__".toCharArray(), ONE); //$NON-NLS-1$
private static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro("__STDC_HOSTED__".toCharArray(), ONE); //$NON-NLS-1$ private static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro("__STDC_HOSTED__".toCharArray(), ONE); //$NON-NLS-1$
private static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro("__STDC_VERSION__".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ private static final ObjectStyleMacro __STDC_VERSION__ =
new ObjectStyleMacro("__STDC_VERSION__".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
private static final DynamicMacro __FILE__= new FileMacro("__FILE__".toCharArray()); //$NON-NLS-1$ private static final DynamicMacro __FILE__= new FileMacro("__FILE__".toCharArray()); //$NON-NLS-1$
private static final DynamicMacro __DATE__= new DateMacro("__DATE__".toCharArray()); //$NON-NLS-1$ private static final DynamicMacro __DATE__= new DateMacro("__DATE__".toCharArray()); //$NON-NLS-1$
@ -108,7 +109,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
}; };
private static class IncludeResolution {String fLocation; boolean fHeuristic;} private static class IncludeResolution {
String fLocation;
boolean fHeuristic;
}
final private IIncludeFileTester<IncludeResolution> createPathTester= new IIncludeFileTester<IncludeResolution>() { final private IIncludeFileTester<IncludeResolution> createPathTester= new IIncludeFileTester<IncludeResolution>() {
public IncludeResolution checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) { public IncludeResolution checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) {
if (fFileContentProvider.getInclusionExists(path)) { if (fFileContentProvider.getInclusionExists(path)) {
@ -123,9 +128,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private final class TokenSequence implements ITokenSequence { private final class TokenSequence implements ITokenSequence {
private final boolean fStopAtNewline; private final boolean fStopAtNewline;
TokenSequence(boolean stopAtNewline) { TokenSequence(boolean stopAtNewline) {
fStopAtNewline= stopAtNewline; fStopAtNewline= stopAtNewline;
} }
public Token nextToken() throws OffsetLimitReachedException { public Token nextToken() throws OffsetLimitReachedException {
final Lexer lexer= fCurrentContext.getLexer(); final Lexer lexer= fCurrentContext.getLexer();
Token t= lexer.nextToken(); Token t= lexer.nextToken();
@ -138,9 +145,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return t; return t;
} }
public int getLastEndOffset() { public int getLastEndOffset() {
return fCurrentContext.getLexer().getLastEndOffset(); return fCurrentContext.getLexer().getLastEndOffset();
} }
public Token currentToken() { public Token currentToken() {
Token t= fCurrentContext.currentLexerToken(); Token t= fCurrentContext.currentLexerToken();
if (fStopAtNewline && t.getType() == Lexer.tNEWLINE) if (fStopAtNewline && t.getType() == Lexer.tNEWLINE)
@ -149,6 +158,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return t; return t;
} }
} }
TokenSequence fInputToMacroExpansion= new TokenSequence(false); TokenSequence fInputToMacroExpansion= new TokenSequence(false);
TokenSequence fLineInputToMacroExpansion= new TokenSequence(true); TokenSequence fLineInputToMacroExpansion= new TokenSequence(true);
@ -191,9 +201,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private InternalFileContent fRootContent; private InternalFileContent fRootContent;
public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language,
public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, IParserLogService log, IParserLogService log, IScannerExtensionConfiguration configuration,
IScannerExtensionConfiguration configuration, IncludeFileContentProvider readerFactory) { IncludeFileContentProvider readerFactory) {
if (readerFactory instanceof InternalFileContentProvider) { if (readerFactory instanceof InternalFileContentProvider) {
fFileContentProvider= (InternalFileContentProvider) readerFactory; fFileContentProvider= (InternalFileContentProvider) readerFactory;
} else if (readerFactory == null) { } else if (readerFactory == null) {
@ -320,7 +330,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return ScannerUtility.createReconciledPath(directory.getAbsolutePath(), inlcudePath); return ScannerUtility.createReconciledPath(directory.getAbsolutePath(), inlcudePath);
} }
private void setupMacroDictionary(IScannerExtensionConfiguration config, IScannerInfo info, ParserLanguage lang) { private void setupMacroDictionary(IScannerExtensionConfiguration config, IScannerInfo info,
ParserLanguage lang) {
// built in macros // built in macros
fMacroDictionary.put(__CDT_PARSER__.getNameCharArray(), __CDT_PARSER__); fMacroDictionary.put(__CDT_PARSER__.getNameCharArray(), __CDT_PARSER__);
fMacroDictionary.put(__STDC__.getNameCharArray(), __STDC__); fMacroDictionary.put(__STDC__.getNameCharArray(), __STDC__);
@ -530,7 +541,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
Token t4= fetchToken(); Token t4= fetchToken();
end= t4.getEndOffset(); end= t4.getEndOffset();
if (t4.getType() == IToken.tRPAREN) { if (t4.getType() == IToken.tRPAREN) {
fLocationMap.encounterPragmaOperator(t1.getOffset(), t3.getOffset(), t3.getEndOffset(), t4.getEndOffset()); fLocationMap.encounterPragmaOperator(t1.getOffset(), t3.getOffset(),
t3.getEndOffset(), t4.getEndOffset());
return; return;
} else { } else {
end= t3.getEndOffset(); end= t3.getEndOffset();
@ -549,7 +561,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
end= t1.getEndOffset(); end= t1.getEndOffset();
pushbackToken(t2); pushbackToken(t2);
} }
fLocationMap.encounterProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, t1.getCharImage(), t1.getOffset(), end); fLocationMap.encounterProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, t1.getCharImage(),
t1.getOffset(), end);
} }
/** /**
@ -591,7 +604,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
case IToken.tUTF32STRING: case IToken.tUTF32STRING:
StringType st = StringType.fromToken(tt1); StringType st = StringType.fromToken(tt1);
Token t2; Token t2;
StringBuffer buf= null; StringBuilder buf= null;
int endOffset= 0; int endOffset= 0;
loop: while (true) { loop: while (true) {
t2= fetchToken(); t2= fetchToken();
@ -603,7 +616,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
case IToken.tUTF32STRING: case IToken.tUTF32STRING:
st = StringType.max(st, StringType.fromToken(tt2)); st = StringType.max(st, StringType.fromToken(tt2));
if (buf == null) { if (buf == null) {
buf= new StringBuffer(); buf= new StringBuilder();
appendStringContent(buf, t1); appendStringContent(buf, t1);
} }
appendStringContent(buf, t2); appendStringContent(buf, t2);
@ -671,7 +684,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return fCurrentContext.getCodeBranchNesting(); return fCurrentContext.getCodeBranchNesting();
} }
private void appendStringContent(StringBuffer buf, Token t1) { private void appendStringContent(StringBuilder buf, Token t1) {
final char[] image= t1.getCharImage(); final char[] image= t1.getCharImage();
final int length= image.length; final int length= image.length;
int start = 1; int start = 1;
@ -689,7 +702,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
} }
Token internalFetchToken(final ScannerContext uptoEndOfCtx, int options, boolean withinExpansion) throws OffsetLimitReachedException { Token internalFetchToken(final ScannerContext uptoEndOfCtx, int options, boolean withinExpansion)
throws OffsetLimitReachedException {
Token ppToken= fCurrentContext.currentLexerToken(); Token ppToken= fCurrentContext.currentLexerToken();
while (true) { while (true) {
switch (ppToken.getType()) { switch (ppToken.getType()) {
@ -890,7 +904,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
continue loop; continue loop;
} }
} }
for (int i=0; i<fAdditionalNumericLiteralSuffixes.length; i++) { for (int i= 0; i < fAdditionalNumericLiteralSuffixes.length; i++) {
if (fAdditionalNumericLiteralSuffixes[i] == c) { if (fAdditionalNumericLiteralSuffixes[i] == c) {
continue loop; continue loop;
} }
@ -934,7 +948,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// Check to see if we find a match in the current directory // Check to see if we find a match in the current directory
final File currentDir= new File(currentFile).getParentFile(); final File currentDir= new File(currentFile).getParentFile();
if (currentDir != null) { if (currentDir != null) {
final String fileLocation = ScannerUtility.createReconciledPath(currentDir.getAbsolutePath(), includeDirective); final String fileLocation = ScannerUtility.createReconciledPath(
currentDir.getAbsolutePath(), includeDirective);
reader = tester.checkFile(fileLocation, false, null); reader = tester.checkFile(fileLocation, false, null);
if (reader != null) { if (reader != null) {
return reader; return reader;
@ -994,7 +1009,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
@Override @Override
public String toString() { public String toString() {
StringBuffer buffer = new StringBuffer("Scanner @ file:"); //$NON-NLS-1$ StringBuilder buffer = new StringBuilder("Scanner @ file:"); //$NON-NLS-1$
buffer.append(fCurrentContext.toString()); buffer.append(fCurrentContext.toString());
buffer.append(" line: "); //$NON-NLS-1$ buffer.append(" line: "); //$NON-NLS-1$
buffer.append(fLocationMap.getCurrentLineNumber(fCurrentContext.currentLexerToken().getOffset())); buffer.append(fLocationMap.getCurrentLineNumber(fCurrentContext.currentLexerToken().getOffset()));
@ -1008,7 +1023,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// this is an undef // this is an undef
fMacroDictionary.remove(macro.getNameCharArray()); fMacroDictionary.remove(macro.getNameCharArray());
} else { } else {
PreprocessorMacro result= MacroDefinitionParser.parseMacroDefinition(macro.getNameCharArray(), macro.getParameterList(), expansionImage); PreprocessorMacro result= MacroDefinitionParser.parseMacroDefinition(
macro.getNameCharArray(), macro.getParameterList(), expansionImage);
final IASTFileLocation loc= macro.getFileLocation(); final IASTFileLocation loc= macro.getFileLocation();
fLocationMap.registerMacroFromIndex(result, loc, -1); fLocationMap.registerMacroFromIndex(result, loc, -1);
fMacroDictionary.put(result.getNameCharArray(), result); fMacroDictionary.put(result.getNameCharArray(), result);
@ -1034,7 +1050,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
* Assumes that the pound token has not yet been consumed * Assumes that the pound token has not yet been consumed
* @since 5.0 * @since 5.0
*/ */
private void executeDirective(final Lexer lexer, final int startOffset, boolean withinExpansion) throws OffsetLimitReachedException { private void executeDirective(final Lexer lexer, final int startOffset, boolean withinExpansion)
throws OffsetLimitReachedException {
final Token ident= lexer.nextToken(); final Token ident= lexer.nextToken();
switch (ident.getType()) { switch (ident.getType()) {
case IToken.tCOMPLETION: case IToken.tCOMPLETION:
@ -1067,10 +1084,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
switch (type) { switch (type) {
case IPreprocessorDirective.ppImport: case IPreprocessorDirective.ppImport:
case IPreprocessorDirective.ppInclude: case IPreprocessorDirective.ppInclude:
executeInclude(lexer, startOffset, false, fCurrentContext.getCodeState() == CodeState.eActive, withinExpansion); executeInclude(lexer, startOffset, false, fCurrentContext.getCodeState() == CodeState.eActive,
withinExpansion);
break; break;
case IPreprocessorDirective.ppInclude_next: case IPreprocessorDirective.ppInclude_next:
executeInclude(lexer, startOffset, true, fCurrentContext.getCodeState() == CodeState.eActive, withinExpansion); executeInclude(lexer, startOffset, true, fCurrentContext.getCodeState() == CodeState.eActive,
withinExpansion);
break; break;
case IPreprocessorDirective.ppDefine: case IPreprocessorDirective.ppDefine:
CodeState state= fCurrentContext.getCodeState(); CodeState state= fCurrentContext.getCodeState();
@ -1149,7 +1168,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
default: default:
int endOffset= lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); int endOffset= lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
if (fCurrentContext.getCodeState() == CodeState.eActive) { if (fCurrentContext.getCodeState() == CodeState.eActive) {
handleProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, ident.getCharImage(), startOffset, endOffset); handleProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, ident.getCharImage(),
startOffset, endOffset);
} }
break; break;
} }
@ -1163,7 +1183,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return fAllIncludedFiles.contains(location); return fAllIncludedFiles.contains(location);
} }
private void executeInclude(final Lexer lexer, int poundOffset, boolean include_next, boolean active, boolean withinExpansion) throws OffsetLimitReachedException { private void executeInclude(final Lexer lexer, int poundOffset, boolean include_next,
boolean active, boolean withinExpansion) throws OffsetLimitReachedException {
if (withinExpansion) { if (withinExpansion) {
final char[] name= lexer.currentToken().getCharImage(); final char[] name= lexer.currentToken().getCharImage();
final int endOffset = lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); final int endOffset = lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
@ -1207,7 +1228,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
case IToken.tLT: case IToken.tLT:
userInclude= false; userInclude= false;
boolean complete= false; boolean complete= false;
StringBuffer buf= new StringBuffer(); StringBuilder buf= new StringBuilder();
t= (Token) t.getNext(); t= (Token) t.getNext();
while (t != null) { while (t != null) {
if (t.getType() == IToken.tGT) { if (t.getType() == IToken.tGT) {
@ -1292,7 +1313,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
if (!reported) { if (!reported) {
fLocationMap.encounterPoundInclude(poundOffset, nameOffsets[0], nameOffsets[1], condEndOffset, headerName, path, userInclude, active, isHeuristic); fLocationMap.encounterPoundInclude(poundOffset, nameOffsets[0], nameOffsets[1],
condEndOffset, headerName, path, userInclude, active, isHeuristic);
} }
} }
@ -1304,7 +1326,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
fLocationMap.skippedFile(fLocationMap.getSequenceNumberForOffset(offset), fi); fLocationMap.skippedFile(fLocationMap.getSequenceNumberForOffset(offset), fi);
} }
private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim, int[] offsets) { private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim,
int[] offsets) {
char[] headerName; char[] headerName;
int start= 0; int start= 0;
int length= image.length; int length= image.length;
@ -1334,7 +1357,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
private void executeDefine(final Lexer lexer, int startOffset, boolean isActive) throws OffsetLimitReachedException { private void executeDefine(final Lexer lexer, int startOffset, boolean isActive)
throws OffsetLimitReachedException {
try { try {
ObjectStyleMacro macrodef = fMacroDefinitionParser.parseMacroDefinition(lexer, this); ObjectStyleMacro macrodef = fMacroDefinitionParser.parseMacroDefinition(lexer, this);
if (isActive) if (isActive)
@ -1349,7 +1373,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
} }
private void executeUndefine(Lexer lexer, int startOffset, boolean isActive) throws OffsetLimitReachedException { private void executeUndefine(Lexer lexer, int startOffset, boolean isActive)
throws OffsetLimitReachedException {
final Token name= lexer.nextToken(); final Token name= lexer.nextToken();
final int tt= name.getType(); final int tt= name.getType();
if (tt != IToken.tIDENTIFIER) { if (tt != IToken.tIDENTIFIER) {
@ -1357,7 +1382,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
throw new OffsetLimitReachedException(ORIGIN_PREPROCESSOR_DIRECTIVE, name); throw new OffsetLimitReachedException(ORIGIN_PREPROCESSOR_DIRECTIVE, name);
} }
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
handleProblem(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, name.getCharImage(), startOffset, name.getEndOffset()); handleProblem(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, name.getCharImage(), startOffset,
name.getEndOffset());
return; return;
} }
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
@ -1369,10 +1395,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} else { } else {
definition= fMacroDictionary.get(namechars); definition= fMacroDictionary.get(namechars);
} }
fLocationMap.encounterPoundUndef(definition, startOffset, name.getOffset(), name.getEndOffset(), endOffset, namechars, isActive); fLocationMap.encounterPoundUndef(definition, startOffset, name.getOffset(),
name.getEndOffset(), endOffset, namechars, isActive);
} }
private CodeState executeIfdef(Lexer lexer, int offset, boolean isIfndef, boolean withinExpansion) throws OffsetLimitReachedException { private CodeState executeIfdef(Lexer lexer, int offset, boolean isIfndef,
boolean withinExpansion) throws OffsetLimitReachedException {
final Token name= lexer.nextToken(); final Token name= lexer.nextToken();
lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
final int tt= name.getType(); final int tt= name.getType();
@ -1413,7 +1441,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return fCurrentContext.setBranchState(conditional, isTaken, withinExpansion, offset); return fCurrentContext.setBranchState(conditional, isTaken, withinExpansion, offset);
} }
private CodeState executeIf(Lexer lexer, int startOffset, boolean isElif, boolean withinExpansion) throws OffsetLimitReachedException { private CodeState executeIf(Lexer lexer, int startOffset, boolean isElif,
boolean withinExpansion) throws OffsetLimitReachedException {
Conditional cond= fCurrentContext.newBranch(isElif ? BranchKind.eElif : BranchKind.eIf, withinExpansion); Conditional cond= fCurrentContext.newBranch(isElif ? BranchKind.eElif : BranchKind.eIf, withinExpansion);
if (cond == null) { if (cond == null) {
char[] name= lexer.currentToken().getCharImage(); char[] name= lexer.currentToken().getCharImage();
@ -1476,7 +1505,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return fCurrentContext.setBranchState(cond, isTaken, withinExpansion, startOffset); return fCurrentContext.setBranchState(cond, isTaken, withinExpansion, startOffset);
} }
private CodeState executeEndif(Lexer lexer, int startOffset, boolean withinExpansion) throws OffsetLimitReachedException { private CodeState executeEndif(Lexer lexer, int startOffset, boolean withinExpansion)
throws OffsetLimitReachedException {
final int endOffset= lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); final int endOffset= lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
final Conditional cond= fCurrentContext.newBranch(BranchKind.eEnd, withinExpansion); final Conditional cond= fCurrentContext.newBranch(BranchKind.eEnd, withinExpansion);
if (cond == null) { if (cond == null) {
@ -1496,7 +1526,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
* converted to the defined-token and its argument is not macro expanded. * converted to the defined-token and its argument is not macro expanded.
* Returns the end-offset of the last token that was consumed. * Returns the end-offset of the last token that was consumed.
*/ */
private int getTokensWithinPPDirective(boolean isCondition, TokenList result, boolean withinExpansion) throws OffsetLimitReachedException { private int getTokensWithinPPDirective(boolean isCondition, TokenList result,
boolean withinExpansion) throws OffsetLimitReachedException {
final ScannerContext scannerCtx= fCurrentContext; final ScannerContext scannerCtx= fCurrentContext;
scannerCtx.clearInactiveCodeMarkerToken(); scannerCtx.clearInactiveCodeMarkerToken();
int options= STOP_AT_NL; int options= STOP_AT_NL;
@ -1530,14 +1561,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return scannerCtx.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE); return scannerCtx.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
} }
private void skipOverConditionalCode(final Lexer lexer, boolean withinExpansion) throws OffsetLimitReachedException { private void skipOverConditionalCode(final Lexer lexer, boolean withinExpansion)
throws OffsetLimitReachedException {
CodeState state= CodeState.eSkipInactive; CodeState state= CodeState.eSkipInactive;
while (state == CodeState.eSkipInactive) { while (state == CodeState.eSkipInactive) {
state= skipBranch(lexer, withinExpansion); state= skipBranch(lexer, withinExpansion);
} }
} }
private CodeState skipBranch(final Lexer lexer, boolean withinExpansion) throws OffsetLimitReachedException { private CodeState skipBranch(final Lexer lexer, boolean withinExpansion)
throws OffsetLimitReachedException {
while (true) { while (true) {
final Token pound = lexer.nextDirective(); final Token pound = lexer.nextDirective();
int tt = pound.getType(); int tt = pound.getType();
@ -1603,7 +1636,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
* @param isPPCondition whether the expansion is inside of a preprocessor condition. This * @param isPPCondition whether the expansion is inside of a preprocessor condition. This
* implies a specific handling for the defined token. * implies a specific handling for the defined token.
*/ */
private boolean expandMacro(final Token identifier, Lexer lexer, int options, boolean withinExpansion) throws OffsetLimitReachedException { private boolean expandMacro(final Token identifier, Lexer lexer, int options,
boolean withinExpansion) throws OffsetLimitReachedException {
final char[] name= identifier.getCharImage(); final char[] name= identifier.getCharImage();
PreprocessorMacro macro= fMacroDictionary.get(name); PreprocessorMacro macro= fMacroDictionary.get(name);
if (macro == null) { if (macro == null) {
@ -1625,13 +1659,15 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
final ITokenSequence input= stopAtNewline ? fLineInputToMacroExpansion : fInputToMacroExpansion; final ITokenSequence input= stopAtNewline ? fLineInputToMacroExpansion : fInputToMacroExpansion;
final MacroExpander expander = withinExpansion ? new MacroExpander(this, fMacroDictionary, final MacroExpander expander = withinExpansion ? new MacroExpander(this, fMacroDictionary,
fLocationMap, fLexOptions) : fMacroExpander; fLocationMap, fLexOptions) : fMacroExpander;
TokenList replacement= expander.expand(input, (options & PROTECT_DEFINED) != 0, macro, identifier, contentAssist); TokenList replacement= expander.expand(input, (options & PROTECT_DEFINED) != 0, macro,
identifier, contentAssist);
final IASTName[] expansions= expander.clearImplicitExpansions(); final IASTName[] expansions= expander.clearImplicitExpansions();
final ImageLocationInfo[] ili= expander.clearImageLocationInfos(); final ImageLocationInfo[] ili= expander.clearImageLocationInfos();
final Token last= replacement.last(); final Token last= replacement.last();
final int length= last == null ? 0 : last.getEndOffset(); final int length= last == null ? 0 : last.getEndOffset();
ILocationCtx ctx= fLocationMap.pushMacroExpansion( ILocationCtx ctx= fLocationMap.pushMacroExpansion(
identifier.getOffset(), identifier.getEndOffset(), lexer.getLastEndOffset(), length, macro, expansions, ili); identifier.getOffset(), identifier.getEndOffset(), lexer.getLastEndOffset(), length,
macro, expansions, ili);
fCurrentContext= new ScannerContext(ctx, fCurrentContext, replacement); fCurrentContext= new ScannerContext(ctx, fCurrentContext, replacement);
return true; return true;
} }