1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-12-31 16:34:48 -08:00
parent 78f863bc01
commit 76ddab24aa
9 changed files with 167 additions and 172 deletions

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList; import java.util.ArrayList;
@ -45,22 +45,22 @@ public class MacroDefinitionParser {
*/ */
static class TokenParameterReference extends TokenWithImage { static class TokenParameterReference extends TokenWithImage {
private final int fIndex; private final int fIndex;
public TokenParameterReference(int type, int idx, Object source, int offset, int endOffset, char[] name) { public TokenParameterReference(int type, int idx, Object source, int offset, int endOffset, char[] name) {
super(type, source, offset, endOffset, name); super(type, source, offset, endOffset, name);
fIndex= idx; fIndex= idx;
} }
public int getIndex() { public int getIndex() {
return fIndex; return fIndex;
} }
@Override @Override
public String toString() { public String toString() {
return "[" + fIndex + "]"; //$NON-NLS-1$ //$NON-NLS-2$ return "[" + fIndex + "]"; //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
public static char[] getExpansion(AbstractCharArray expansionImage, int offset, int endOffset) { public static char[] getExpansion(AbstractCharArray expansionImage, int offset, int endOffset) {
TokenList tl= new TokenList(); TokenList tl= new TokenList();
Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null); Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null);
@ -83,7 +83,7 @@ public class MacroDefinitionParser {
buf.append(t.getCharImage()); buf.append(t.getCharImage());
endOffset= t.getEndOffset(); endOffset= t.getEndOffset();
} }
final int length= buf.length(); final int length= buf.length();
final char[] expansion= new char[length]; final char[] expansion= new char[length];
buf.getChars(0, length, expansion, 0); buf.getChars(0, length, expansion, 0);
return expansion; return expansion;
@ -93,10 +93,10 @@ public class MacroDefinitionParser {
private int fExpansionOffset; private int fExpansionOffset;
private int fExpansionEndOffset; private int fExpansionEndOffset;
private Token fNameToken; private Token fNameToken;
MacroDefinitionParser() { MacroDefinitionParser() {
} }
/** /**
* In case the name was successfully parsed, the name token is returned. * In case the name was successfully parsed, the name token is returned.
* Otherwise the return value is undefined. * Otherwise the return value is undefined.
@ -105,10 +105,10 @@ public class MacroDefinitionParser {
return fNameToken; return fNameToken;
} }
/** /**
* Parses an entire macro definition. Name must be the next token of the lexer. * Parses an entire macro definition. Name must be the next token of the lexer.
*/ */
public ObjectStyleMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log) public ObjectStyleMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log)
throws OffsetLimitReachedException, InvalidMacroDefinitionException { throws OffsetLimitReachedException, InvalidMacroDefinitionException {
final Token name = parseName(lexer); final Token name = parseName(lexer);
final AbstractCharArray source= lexer.getInput(); final AbstractCharArray source= lexer.getInput();
@ -122,10 +122,10 @@ public class MacroDefinitionParser {
return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, fExpansionOffset, fExpansionEndOffset, replacement, source); return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, fExpansionOffset, fExpansionEndOffset, replacement, source);
} }
/** /**
* Parses a macro definition without the replacement. Name must be the next token of the lexer. * Parses a macro definition without the replacement. Name must be the next token of the lexer.
*/ */
public PreprocessorMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log, final char[] replacement) public PreprocessorMacro parseMacroDefinition(final Lexer lexer, final ILexerLog log, final char[] replacement)
throws InvalidMacroDefinitionException, OffsetLimitReachedException { throws InvalidMacroDefinitionException, OffsetLimitReachedException {
final Token name = parseName(lexer); final Token name = parseName(lexer);
@ -135,14 +135,14 @@ public class MacroDefinitionParser {
if (replacementToken.getType() != IToken.tEND_OF_INPUT) { if (replacementToken.getType() != IToken.tEND_OF_INPUT) {
throw new InvalidMacroDefinitionException(nameChars, replacementToken.getOffset(), replacementToken.getEndOffset()); throw new InvalidMacroDefinitionException(nameChars, replacementToken.getOffset(), replacementToken.getEndOffset());
} }
if (paramList == null) { if (paramList == null) {
return new ObjectStyleMacro(nameChars, replacement); return new ObjectStyleMacro(nameChars, replacement);
} }
return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, replacement); return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, replacement);
} }
/** /**
* Parses a macro definition basically checking for var-args. * Parses a macro definition basically checking for var-args.
*/ */
public static PreprocessorMacro parseMacroDefinition(final char[] name, char[][] paramList, final char[] replacement) { public static PreprocessorMacro parseMacroDefinition(final char[] name, char[][] paramList, final char[] replacement) {
@ -176,8 +176,8 @@ public class MacroDefinitionParser {
} }
} }
} }
if (paramList == null) { if (paramList == null) {
return new ObjectStyleMacro(name, replacement); return new ObjectStyleMacro(name, replacement);
} }
return new FunctionStyleMacro(name, paramList, hasVarargs, replacement); return new FunctionStyleMacro(name, paramList, hasVarargs, replacement);
@ -195,11 +195,11 @@ public class MacroDefinitionParser {
fNameToken= name; fNameToken= name;
return name; return name;
} }
private char[][] parseParamList(Lexer lex, final Token name) throws OffsetLimitReachedException, InvalidMacroDefinitionException { private char[][] parseParamList(Lexer lex, final Token name) throws OffsetLimitReachedException, InvalidMacroDefinitionException {
final Token lparen= lex.nextToken(); final Token lparen= lex.nextToken();
fHasVarArgs= FunctionStyleMacro.NO_VAARGS; fHasVarArgs= FunctionStyleMacro.NO_VAARGS;
if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) { if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) {
return null; return null;
} }
ArrayList<char[]> paramList= new ArrayList<char[]>(); ArrayList<char[]> paramList= new ArrayList<char[]>();
@ -224,7 +224,7 @@ public class MacroDefinitionParser {
paramList.add(Keywords.cVA_ARGS); paramList.add(Keywords.cVA_ARGS);
next= lex.nextToken(); next= lex.nextToken();
break; break;
case IToken.tRPAREN: case IToken.tRPAREN:
if (next == null) { if (next == null) {
next= param; next= param;
@ -255,7 +255,7 @@ public class MacroDefinitionParser {
Token needAnotherToken= null; Token needAnotherToken= null;
Token candidate= lexer.currentToken(); Token candidate= lexer.currentToken();
fExpansionOffset= fExpansionEndOffset= candidate.getOffset(); fExpansionOffset= fExpansionEndOffset= candidate.getOffset();
loop: while(true) { loop: while(true) {
switch (candidate.getType()) { switch (candidate.getType()) {
@ -266,18 +266,16 @@ public class MacroDefinitionParser {
break loop; break loop;
case IToken.tIDENTIFIER: case IToken.tIDENTIFIER:
if (paramList != null) { if (paramList != null) {
// convert the parameters to special tokens // Convert the parameters to special tokens.
final char[] image = candidate.getCharImage(); final char[] image = candidate.getCharImage();
int idx= CharArrayUtils.indexOf(image, paramList); int idx= CharArrayUtils.indexOf(image, paramList);
if (idx >= 0) { if (idx >= 0) {
candidate= new TokenParameterReference(CPreprocessor.tMACRO_PARAMETER, idx, lexer.getSource(), candidate.getOffset(), candidate.getEndOffset(), paramList[idx]); candidate= new TokenParameterReference(CPreprocessor.tMACRO_PARAMETER, idx, lexer.getSource(), candidate.getOffset(), candidate.getEndOffset(), paramList[idx]);
needParam= false; needParam= false;
} } else {
else {
if (needParam) { if (needParam) {
log.handleProblem(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, name, fExpansionOffset, candidate.getEndOffset()); log.handleProblem(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, name, fExpansionOffset, candidate.getEndOffset());
} } else if (CharArrayUtils.equals(Keywords.cVA_ARGS, image)) {
else if (CharArrayUtils.equals(Keywords.cVA_ARGS, image)) {
log.handleProblem(IProblem.PREPROCESSOR_INVALID_VA_ARGS, null, fExpansionOffset, candidate.getEndOffset()); log.handleProblem(IProblem.PREPROCESSOR_INVALID_VA_ARGS, null, fExpansionOffset, candidate.getEndOffset());
} }
needParam= false; needParam= false;

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,9 +35,9 @@ public class MacroExpander {
private static final class AbortMacroExpansionException extends Exception {} private static final class AbortMacroExpansionException extends Exception {}
private static final int ORIGIN = OffsetLimitReachedException.ORIGIN_MACRO_EXPANSION; private static final int ORIGIN = OffsetLimitReachedException.ORIGIN_MACRO_EXPANSION;
private static final TokenList EMPTY_TOKEN_LIST = new TokenList(); private static final TokenList EMPTY_TOKEN_LIST = new TokenList();
/** /**
* Marks the beginning and the end of the scope of a macro expansion. Necessary to properly * Marks the beginning and the end of the scope of a macro expansion. Necessary to properly
* handle recursive expansions and to figure out whether spaces are required during a stringify * handle recursive expansions and to figure out whether spaces are required during a stringify
* operation across such boundaries. * operation across such boundaries.
@ -56,7 +56,7 @@ public class MacroExpander {
public char[] getCharImage() { public char[] getCharImage() {
return CharArrayUtils.EMPTY; return CharArrayUtils.EMPTY;
} }
@Override @Override
public String toString() { public String toString() {
return "{" + (fIsStart ? '+' : '-') + fMacro.getName() + '}'; //$NON-NLS-1$ return "{" + (fIsStart ? '+' : '-') + fMacro.getName() + '}'; //$NON-NLS-1$
@ -70,8 +70,8 @@ public class MacroExpander {
} }
} }
} }
/** /**
* Combines a list of tokens with the preprocessor to form the input for macro expansion. * Combines a list of tokens with the preprocessor to form the input for macro expansion.
*/ */
private class TokenSource extends TokenList { private class TokenSource extends TokenList {
@ -112,7 +112,7 @@ public class MacroExpander {
if (fLexer != null) { if (fLexer != null) {
t= fLexer.currentToken(); t= fLexer.currentToken();
while(t.getType() == Lexer.tNEWLINE) { while (t.getType() == Lexer.tNEWLINE) {
t= fLexer.nextToken(); t= fLexer.nextToken();
} }
return t.getType() == IToken.tLPAREN; return t.getType() == IToken.tLPAREN;
@ -131,14 +131,14 @@ public class MacroExpander {
private boolean fCompletionMode; private boolean fCompletionMode;
private int fStartOffset; private int fStartOffset;
private int fEndOffset; private int fEndOffset;
// for using the expander to track expansions // for using the expander to track expansions
private String fFixedCurrentFilename; private String fFixedCurrentFilename;
private int fFixedLineNumber; private int fFixedLineNumber;
private char[] fFixedInput; private char[] fFixedInput;
private ScannerContext fReportMacros; private ScannerContext fReportMacros;
private boolean fReportUndefined; private boolean fReportUndefined;
public MacroExpander(ILexerLog log, CharArrayMap<PreprocessorMacro> macroDictionary, public MacroExpander(ILexerLog log, CharArrayMap<PreprocessorMacro> macroDictionary,
LocationMap locationMap, LexerOptions lexOptions) { LocationMap locationMap, LexerOptions lexOptions) {
fDictionary= macroDictionary; fDictionary= macroDictionary;
@ -147,10 +147,10 @@ public class MacroExpander {
fLexOptions= lexOptions; fLexOptions= lexOptions;
fLog= log; fLog= log;
} }
/** /**
* Expects that the identifier has been consumed, stores the result in the list provided. * Expects that the identifier has been consumed, stores the result in the list provided.
* @param scannerContext * @param scannerContext
*/ */
public TokenList expand(ITokenSequence lexer, final int ppOptions, public TokenList expand(ITokenSequence lexer, final int ppOptions,
PreprocessorMacro macro, Token identifier, boolean completionMode, PreprocessorMacro macro, Token identifier, boolean completionMode,
@ -162,16 +162,16 @@ public class MacroExpander {
} else { } else {
fReportMacros= null; fReportMacros= null;
} }
fImplicitMacroExpansions.clear(); fImplicitMacroExpansions.clear();
fImageLocationInfos.clear(); fImageLocationInfos.clear();
fStartOffset= identifier.getOffset(); fStartOffset= identifier.getOffset();
fEndOffset= identifier.getEndOffset(); fEndOffset= identifier.getEndOffset();
fCompletionMode= completionMode; fCompletionMode= completionMode;
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden= new IdentityHashMap<PreprocessorMacro, PreprocessorMacro>(); IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden= new IdentityHashMap<PreprocessorMacro, PreprocessorMacro>();
// setup input sequence // setup input sequence
TokenSource input= new TokenSource(lexer); TokenSource input= new TokenSource(lexer);
TokenList firstExpansion= new TokenList(); TokenList firstExpansion= new TokenList();
@ -186,8 +186,8 @@ public class MacroExpander {
result= expandAll(input, forbidden, protectDefined, null); result= expandAll(input, forbidden, protectDefined, null);
} catch (CompletionInMacroExpansionException e) { } catch (CompletionInMacroExpansionException e) {
// For content assist in macro expansions, we return the list of tokens of the // For content assist in macro expansions, we return the list of tokens of the
// parameter at the current cursor position and hope that they make sense if // parameter at the current cursor position and hope that they make sense if
// they are inserted at the position of the expansion. // they are inserted at the position of the expansion.
// For a better solution one would have to perform the expansion with artificial // For a better solution one would have to perform the expansion with artificial
// parameters and then check where the completion token ends up in the expansion. // parameters and then check where the completion token ends up in the expansion.
@ -211,7 +211,7 @@ public class MacroExpander {
fFixedLineNumber= lineNumber; fFixedLineNumber= lineNumber;
fReportMacros= null; fReportMacros= null;
Lexer lexer= new Lexer(fFixedInput, fLexOptions, fLog, this); Lexer lexer= new Lexer(fFixedInput, fLexOptions, fLog, this);
try { try {
tracker.start(fFixedInput); tracker.start(fFixedInput);
Token identifier= lexer.nextToken(); Token identifier= lexer.nextToken();
@ -246,21 +246,21 @@ public class MacroExpander {
} catch (OffsetLimitReachedException e) { } catch (OffsetLimitReachedException e) {
} }
} }
/** /**
* Expects that the identifier of the macro expansion has been consumed. Expands the macro * Expects that the identifier of the macro expansion has been consumed. Expands the macro
* consuming tokens from the input (to read the parameters) and stores the resulting tokens * consuming tokens from the input (to read the parameters) and stores the resulting tokens
* together with boundary markers in the result token list. * together with boundary markers in the result token list.
* @return the last token of the expansion. * @return the last token of the expansion.
* @throws AbortMacroExpansionException * @throws AbortMacroExpansionException
*/ */
private Token expandOne(Token lastConsumed, PreprocessorMacro macro, private Token expandOne(Token lastConsumed, PreprocessorMacro macro,
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden, TokenSource input, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden, TokenSource input,
TokenList result, MacroExpansionTracker tracker) TokenList result, MacroExpansionTracker tracker)
throws OffsetLimitReachedException { throws OffsetLimitReachedException {
if (fReportMacros != null) if (fReportMacros != null)
fReportMacros.significantMacro(macro); fReportMacros.significantMacro(macro);
if (macro.isFunctionStyle()) { if (macro.isFunctionStyle()) {
final int paramCount = macro.getParameterPlaceholderList().length; final int paramCount = macro.getParameterPlaceholderList().length;
final TokenSource[] argInputs= new TokenSource[paramCount]; final TokenSource[] argInputs= new TokenSource[paramCount];
@ -271,13 +271,13 @@ public class MacroExpander {
try { try {
lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker); lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker);
} catch (AbortMacroExpansionException e) { } catch (AbortMacroExpansionException e) {
// ignore this macro expansion // Ignore this macro expansion.
for (TokenSource argInput : argInputs) { for (TokenSource argInput : argInputs) {
executeScopeMarkers(argInput, forbidden); executeScopeMarkers(argInput, forbidden);
if (tracker != null) { if (tracker != null) {
tracker.setExpandedMacroArgument(null); tracker.setExpandedMacroArgument(null);
} }
} }
if (tracker != null) { if (tracker != null) {
if (tracker.isRequestedStep()) { if (tracker.isRequestedStep()) {
tracker.storeFunctionStyleMacroReplacement(macro, new TokenList(), result); tracker.storeFunctionStyleMacroReplacement(macro, new TokenList(), result);
@ -288,7 +288,7 @@ public class MacroExpander {
} }
return null; return null;
} }
TokenList[] clonedArgs= new TokenList[paramCount]; TokenList[] clonedArgs= new TokenList[paramCount];
TokenList[] expandedArgs= new TokenList[paramCount]; TokenList[] expandedArgs= new TokenList[paramCount];
for (int i = 0; i < paramCount; i++) { for (int i = 0; i < paramCount; i++) {
@ -342,11 +342,11 @@ public class MacroExpander {
private void executeScopeMarkers(TokenSource input, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden) { private void executeScopeMarkers(TokenSource input, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden) {
Token t= input.removeFirst(); Token t= input.removeFirst();
while(t != null) { while (t != null) {
if (t.getType() == CPreprocessor.tSCOPE_MARKER) { if (t.getType() == CPreprocessor.tSCOPE_MARKER) {
((ExpansionBoundary) t).execute(forbidden); ((ExpansionBoundary) t).execute(forbidden);
} }
t= input.removeFirst(); t= input.removeFirst();
} }
} }
@ -356,7 +356,7 @@ public class MacroExpander {
boolean protect= false; boolean protect= false;
Token l= null; Token l= null;
Token t= input.removeFirst(); Token t= input.removeFirst();
while(t != null) { while (t != null) {
switch (t.getType()) { switch (t.getType()) {
case CPreprocessor.tSCOPE_MARKER: case CPreprocessor.tSCOPE_MARKER:
((ExpansionBoundary) t).execute(forbidden); ((ExpansionBoundary) t).execute(forbidden);
@ -395,7 +395,7 @@ public class MacroExpander {
addSpacemarker(l, t, replacement); // start expansion addSpacemarker(l, t, replacement); // start expansion
replacement.append(new ExpansionBoundary(macro, true)); replacement.append(new ExpansionBoundary(macro, true));
Token last= expandOne(t, macro, forbidden, input, replacement, tracker); Token last= expandOne(t, macro, forbidden, input, replacement, tracker);
replacement.append(new ExpansionBoundary(macro, false)); replacement.append(new ExpansionBoundary(macro, false));
addSpacemarker(last, input.first(), replacement); // end expansion addSpacemarker(last, input.first(), replacement); // end expansion
@ -404,12 +404,12 @@ public class MacroExpander {
break; break;
case IToken.tLPAREN: case IToken.tLPAREN:
case CPreprocessor.tNOSPACE: case CPreprocessor.tNOSPACE:
case CPreprocessor.tSPACE: case CPreprocessor.tSPACE:
result.append(t); result.append(t);
break; break;
default: default:
protect= false; protect= false;
result.append(t); result.append(t);
break; break;
} }
l= t; l= t;
@ -450,26 +450,26 @@ public class MacroExpander {
} }
target.append(new Token(CPreprocessor.tNOSPACE, null, 0, 0)); target.append(new Token(CPreprocessor.tNOSPACE, null, 0, 0));
} }
/** /**
* Expects that the identifier has been consumed. * Expects that the identifier has been consumed.
*/ */
private Token parseArguments(TokenSource input, FunctionStyleMacro macro, private Token parseArguments(TokenSource input, FunctionStyleMacro macro,
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden,
TokenSource[] result, MacroExpansionTracker tracker) TokenSource[] result, MacroExpansionTracker tracker)
throws OffsetLimitReachedException, AbortMacroExpansionException { throws OffsetLimitReachedException, AbortMacroExpansionException {
final int argCount= macro.getParameterPlaceholderList().length; final int argCount= macro.getParameterPlaceholderList().length;
final boolean hasVarargs= macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS; final boolean hasVarargs= macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS;
final int requiredArgs= hasVarargs ? argCount-1 : argCount; final int requiredArgs= hasVarargs ? argCount - 1 : argCount;
int idx= 0; int idx= 0;
int nesting= -1; int nesting= -1;
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i]= new TokenSource(null); result[i]= new TokenSource(null);
} }
boolean missingRParenthesis= false; boolean missingRParenthesis= false;
boolean tooManyArgs= false; boolean tooManyArgs= false;
boolean isFirstOfArg= true; boolean isFirstOfArg= true;
Token lastToken= null; Token lastToken= null;
TokenList spaceMarkers= new TokenList(); TokenList spaceMarkers= new TokenList();
@ -481,7 +481,7 @@ public class MacroExpander {
} }
if (tracker != null) { if (tracker != null) {
switch (t.getType()) { switch (t.getType()) {
case IToken.tEND_OF_INPUT: case IToken.tEND_OF_INPUT:
case IToken.tCOMPLETION: case IToken.tCOMPLETION:
case CPreprocessor.tSCOPE_MARKER: case CPreprocessor.tSCOPE_MARKER:
case Lexer.tNEWLINE: case Lexer.tNEWLINE:
@ -509,28 +509,28 @@ public class MacroExpander {
throw new CompletionInMacroExpansionException(ORIGIN, t, result[idx]); throw new CompletionInMacroExpansionException(ORIGIN, t, result[idx]);
} }
throw new OffsetLimitReachedException(ORIGIN, t); throw new OffsetLimitReachedException(ORIGIN, t);
case Lexer.tNEWLINE: case Lexer.tNEWLINE:
continue loop; continue loop;
case IToken.tLPAREN: case IToken.tLPAREN:
// the first one sets nesting to zero. // The first one sets nesting to zero.
if (++nesting == 0) { if (++nesting == 0) {
continue; continue;
} }
break; break;
case IToken.tRPAREN: case IToken.tRPAREN:
assert nesting >= 0; assert nesting >= 0;
if (--nesting < 0) { if (--nesting < 0) {
break loop; break loop;
} }
break; break;
case IToken.tCOMMA: case IToken.tCOMMA:
assert nesting >= 0; assert nesting >= 0;
if (nesting == 0) { if (nesting == 0) {
if (idx < argCount-1) { // next argument if (idx < argCount - 1) { // Next argument.
isFirstOfArg= true; isFirstOfArg= true;
spaceMarkers.clear(); spaceMarkers.clear();
idx++; idx++;
@ -541,7 +541,7 @@ public class MacroExpander {
} }
} }
break; break;
case CPreprocessor.tSCOPE_MARKER: case CPreprocessor.tSCOPE_MARKER:
if (argCount == 0) { if (argCount == 0) {
((ExpansionBoundary) t).execute(forbidden); ((ExpansionBoundary) t).execute(forbidden);
@ -549,14 +549,14 @@ public class MacroExpander {
result[idx].append(t); result[idx].append(t);
} }
continue loop; continue loop;
case CPreprocessor.tSPACE: case CPreprocessor.tSPACE:
case CPreprocessor.tNOSPACE: case CPreprocessor.tNOSPACE:
if (!isFirstOfArg) { if (!isFirstOfArg) {
spaceMarkers.append(t); spaceMarkers.append(t);
} }
continue loop; continue loop;
default: default:
assert nesting >= 0; assert nesting >= 0;
} }
@ -573,7 +573,7 @@ public class MacroExpander {
handleProblem(IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST, macro.getNameCharArray()); handleProblem(IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST, macro.getNameCharArray());
throw new AbortMacroExpansionException(); throw new AbortMacroExpansionException();
} }
if (tooManyArgs) { if (tooManyArgs) {
handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, macro.getNameCharArray()); handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, macro.getNameCharArray());
} else if (idx + 1 < requiredArgs) { } else if (idx + 1 < requiredArgs) {
@ -581,18 +581,18 @@ public class MacroExpander {
} }
return lastToken; return lastToken;
} }
private void handleProblem(int problemID, char[] arg) { private void handleProblem(int problemID, char[] arg) {
fLog.handleProblem(problemID, arg, fStartOffset, fEndOffset); fLog.handleProblem(problemID, arg, fStartOffset, fEndOffset);
} }
private void replaceArgs(PreprocessorMacro macro, TokenList[] args, TokenList[] expandedArgs, TokenList result) { private void replaceArgs(PreprocessorMacro macro, TokenList[] args, TokenList[] expandedArgs, TokenList result) {
TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this)); TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this));
Token l= null; Token l= null;
Token n; Token n;
Token pasteArg1= null; Token pasteArg1= null;
for (Token t= replacement.first(); t != null; l=t, t=n) { for (Token t= replacement.first(); t != null; l= t, t= n) {
n= (Token) t.getNext(); n= (Token) t.getNext();
switch (t.getType()) { switch (t.getType()) {
@ -614,7 +614,7 @@ public class MacroExpander {
} }
} }
break; break;
case IToken.tPOUND: case IToken.tPOUND:
addSpacemarker(l, t, result); // start stringify addSpacemarker(l, t, result); // start stringify
StringBuilder buf= new StringBuilder(); StringBuilder buf= new StringBuilder();
@ -628,19 +628,19 @@ public class MacroExpander {
n= (Token) n.getNext(); n= (Token) n.getNext();
} }
buf.append('"'); buf.append('"');
final int length= buf.length(); final int length= buf.length();
final char[] image= new char[length]; final char[] image= new char[length];
buf.getChars(0, length, image, 0); buf.getChars(0, length, image, 0);
Token generated= new TokenWithImage(IToken.tSTRING, null, 0, 0, image); Token generated= new TokenWithImage(IToken.tSTRING, null, 0, 0, image);
if (isKind(n, IToken.tPOUNDPOUND)) { // start token paste, same as start stringify if (isKind(n, IToken.tPOUNDPOUND)) { // start token paste, same as start stringify
pasteArg1= generated; pasteArg1= generated;
} else { } else {
result.append(generated); result.append(generated);
addSpacemarker(t, n, result); // end stringify addSpacemarker(t, n, result); // end stringify
} }
break; break;
case IToken.tPOUNDPOUND: case IToken.tPOUNDPOUND:
Token pasteArg2= null; Token pasteArg2= null;
TokenList rest= null; TokenList rest= null;
@ -664,7 +664,7 @@ public class MacroExpander {
idx= -1; idx= -1;
pasteArg2= n; pasteArg2= n;
} }
t= n; t= n;
n= (Token) n.getNext(); n= (Token) n.getNext();
final boolean pasteNext= isKind(n, IToken.tPOUNDPOUND); final boolean pasteNext= isKind(n, IToken.tPOUNDPOUND);
@ -676,7 +676,7 @@ public class MacroExpander {
generated= pasteArg1; generated= pasteArg1;
if (rest == null) if (rest == null)
rest= new TokenList(); rest= new TokenList();
rest.prepend(pasteArg2); rest.prepend(pasteArg2);
spaceDef0= generated; spaceDef0= generated;
spaceDef1= pasteArg2; spaceDef1= pasteArg2;
@ -707,15 +707,15 @@ public class MacroExpander {
} }
} }
break; break;
case IToken.tCOMMA: case IToken.tCOMMA:
if (isKind(n, IToken.tPOUNDPOUND)) { if (isKind(n, IToken.tPOUNDPOUND)) {
final Token nn= (Token) n.getNext(); final Token nn= (Token) n.getNext();
if (isKind(nn, CPreprocessor.tMACRO_PARAMETER)) { if (isKind(nn, CPreprocessor.tMACRO_PARAMETER)) {
idx= ((TokenParameterReference) nn).getIndex(); idx= ((TokenParameterReference) nn).getIndex();
// check for gcc-extension preventing the paste operation // check for gcc-extension preventing the paste operation
if (idx == args.length-1 && macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS && if (idx == args.length - 1 && macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS &&
!isKind(nn.getNext(), IToken.tPOUNDPOUND)) { !isKind(nn.getNext(), IToken.tPOUNDPOUND)) {
final Token nnn= (Token) nn.getNext(); final Token nnn= (Token) nn.getNext();
TokenList arg= clone(expandedArgs[idx]); TokenList arg= clone(expandedArgs[idx]);
@ -733,14 +733,14 @@ public class MacroExpander {
break; break;
} }
} }
addSpacemarker(l, t, result); addSpacemarker(l, t, result);
pasteArg1= t; pasteArg1= t;
} else { } else {
result.append(t); result.append(t);
} }
break; break;
default: default:
if (isKind(n, IToken.tPOUNDPOUND)) { if (isKind(n, IToken.tPOUNDPOUND)) {
addSpacemarker(l, t, result); // start token paste addSpacemarker(l, t, result); // start token paste
@ -752,7 +752,7 @@ public class MacroExpander {
} }
} }
} }
private boolean isKind(final IToken t, final int kind) { private boolean isKind(final IToken t, final int kind) {
return t != null && t.getType() == kind; return t != null && t.getType() == kind;
} }
@ -760,9 +760,9 @@ public class MacroExpander {
private BitSet getParamUsage(PreprocessorMacro macro) { private BitSet getParamUsage(PreprocessorMacro macro) {
final BitSet result= new BitSet(); final BitSet result= new BitSet();
final TokenList replacement= macro.getTokens(fDefinitionParser, fLexOptions, this); final TokenList replacement= macro.getTokens(fDefinitionParser, fLexOptions, this);
Token l= null; Token l= null;
Token n; Token n;
for (Token t= replacement.first(); t != null; l= t, t= n) { for (Token t= replacement.first(); t != null; l= t, t= n) {
n= (Token) t.getNext(); n= (Token) t.getNext();
switch (t.getType()) { switch (t.getType()) {
@ -773,7 +773,7 @@ public class MacroExpander {
} }
result.set(idx); result.set(idx);
break; break;
case IToken.tPOUND: case IToken.tPOUND:
if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) { if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) {
idx= ((TokenParameterReference) n).getIndex(); idx= ((TokenParameterReference) n).getIndex();
@ -781,7 +781,7 @@ public class MacroExpander {
t= n; n= (Token) n.getNext(); t= n; n= (Token) n.getNext();
} }
break; break;
case IToken.tPOUNDPOUND: case IToken.tPOUNDPOUND:
if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) { if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) {
idx= ((TokenParameterReference) n).getIndex(); idx= ((TokenParameterReference) n).getIndex();
@ -795,17 +795,17 @@ public class MacroExpander {
t= n; n= (Token) n.getNext(); t= n; n= (Token) n.getNext();
} }
break; break;
} }
} }
return result; return result;
} }
private void objStyleTokenPaste(PreprocessorMacro macro, TokenList result) { private void objStyleTokenPaste(PreprocessorMacro macro, TokenList result) {
TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this)); TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this));
Token l= null; Token l= null;
Token n; Token n;
Token pasteArg1= null; Token pasteArg1= null;
for (Token t= replacement.first(); t != null; l= t, t= n) { for (Token t= replacement.first(); t != null; l= t, t= n) {
n= (Token) t.getNext(); n= (Token) t.getNext();
@ -817,7 +817,7 @@ public class MacroExpander {
pasteArg2= n; pasteArg2= n;
n= (Token) n.getNext(); n= (Token) n.getNext();
} }
t= tokenpaste(pasteArg1, pasteArg2, macro); t= tokenpaste(pasteArg1, pasteArg2, macro);
if (t != null) { if (t != null) {
if (isKind(n, IToken.tPOUNDPOUND)) { if (isKind(n, IToken.tPOUNDPOUND)) {
@ -829,7 +829,7 @@ public class MacroExpander {
} }
} }
break; break;
default: default:
if (isKind(n, IToken.tPOUNDPOUND)) { if (isKind(n, IToken.tPOUNDPOUND)) {
addSpacemarker(l, t, result); // start token paste addSpacemarker(l, t, result); // start token paste
@ -910,7 +910,7 @@ public class MacroExpander {
} }
space= false; space= false;
break; break;
case CPreprocessor.tSPACE: case CPreprocessor.tSPACE:
if (!space && l != null && n != null) { if (!space && l != null && n != null) {
buf.append(' '); buf.append(' ');
@ -920,7 +920,7 @@ public class MacroExpander {
case CPreprocessor.tNOSPACE: case CPreprocessor.tNOSPACE:
break; break;
default: default:
buf.append(t.getCharImage()); buf.append(t.getCharImage());
space= false; space= false;
@ -928,7 +928,7 @@ public class MacroExpander {
} }
} }
} }
public IASTName[] clearImplicitExpansions() { public IASTName[] clearImplicitExpansions() {
IASTName[] result= fImplicitMacroExpansions.toArray(new IASTName[fImplicitMacroExpansions.size()]); IASTName[] result= fImplicitMacroExpansions.toArray(new IASTName[fImplicitMacroExpansions.size()]);
fImplicitMacroExpansions.clear(); fImplicitMacroExpansions.clear();
@ -983,7 +983,7 @@ public class MacroExpander {
l= t; l= t;
} }
} }
int getCurrentLineNumber() { int getCurrentLineNumber() {
if (fFixedInput != null) { if (fFixedInput != null) {
return fFixedLineNumber + countNewlines(fFixedInput); return fFixedLineNumber + countNewlines(fFixedInput);

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
@ -30,12 +30,12 @@ public class MacroExpansionStep implements IMacroExpansionStep {
fMacroDefinition= def; fMacroDefinition= def;
fMacroLocation= macroLoc; fMacroLocation= macroLoc;
} }
@Override @Override
public String getCodeBeforeStep() { public String getCodeBeforeStep() {
return fBefore; return fBefore;
} }
@Override @Override
public String getCodeAfterStep() { public String getCodeAfterStep() {
StringBuilder result= new StringBuilder(); StringBuilder result= new StringBuilder();
@ -49,7 +49,7 @@ public class MacroExpansionStep implements IMacroExpansionStep {
result.append(fBefore, offset, fBefore.length()); result.append(fBefore, offset, fBefore.length());
return result.toString(); return result.toString();
} }
@Override @Override
public IMacroBinding getExpandedMacro() { public IMacroBinding getExpandedMacro() {
return fMacroDefinition; return fMacroDefinition;

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,7 +35,7 @@ public class MacroExpansionTracker {
} }
private final int fStepToTrack; private final int fStepToTrack;
private int fStepCount; private int fStepCount;
private String fPreStep; private String fPreStep;
private ReplaceEdit fReplacement; private ReplaceEdit fReplacement;
@ -58,14 +58,14 @@ public class MacroExpansionTracker {
public boolean isDone() { public boolean isDone() {
return fStepCount > fStepToTrack; return fStepCount > fStepToTrack;
} }
/** /**
* Returns whether we are currently looking at the requested step. * Returns whether we are currently looking at the requested step.
*/ */
public boolean isRequestedStep() { public boolean isRequestedStep() {
return fStepCount == fStepToTrack; return fStepCount == fStepToTrack;
} }
/** /**
* Returns the total amount of steps encountered so far. * Returns the total amount of steps encountered so far.
*/ */
@ -79,7 +79,7 @@ public class MacroExpansionTracker {
public String getCodeBeforeStep() { public String getCodeBeforeStep() {
return fPreStep; return fPreStep;
} }
/** /**
* Returns the replacement that represents the change by the step that was tracked. * Returns the replacement that represents the change by the step that was tracked.
*/ */
@ -132,7 +132,7 @@ public class MacroExpansionTracker {
fReplacement= new ReplaceEdit(offset, replace.length(), fReplacementText); fReplacement= new ReplaceEdit(offset, replace.length(), fReplacementText);
} }
} }
/** /**
* There was no macro at the beginning of the input. * There was no macro at the beginning of the input.
*/ */
@ -140,7 +140,7 @@ public class MacroExpansionTracker {
fPreStep= new String(fInput); fPreStep= new String(fInput);
fReplacement= new ReplaceEdit(0, 0, ""); //$NON-NLS-1$ fReplacement= new ReplaceEdit(0, 0, ""); //$NON-NLS-1$
} }
private void toString(TokenList tokenList, char[] rootInput, StringBuilder before, private void toString(TokenList tokenList, char[] rootInput, StringBuilder before,
StringBuilder replace, StringBuilder after) { StringBuilder replace, StringBuilder after) {
StringBuilder buf= before; StringBuilder buf= before;
@ -176,7 +176,7 @@ public class MacroExpansionTracker {
} }
} }
} }
private char[] getInputForSource(Object source, char[] rootInput) { private char[] getInputForSource(Object source, char[] rootInput) {
if (source instanceof MacroExpander) { if (source instanceof MacroExpander) {
return rootInput; return rootInput;
@ -197,7 +197,7 @@ public class MacroExpansionTracker {
public void startFunctionStyleMacro(Token identifier) { public void startFunctionStyleMacro(Token identifier) {
fMacroStack.add(new MacroInfo(identifier)); fMacroStack.add(new MacroInfo(identifier));
} }
/** /**
* All tokens defining a function-style macro expansion are reported. * All tokens defining a function-style macro expansion are reported.
*/ */
@ -235,7 +235,7 @@ public class MacroExpansionTracker {
* Append the current function-style macro with the arguments substituted. * Append the current function-style macro with the arguments substituted.
*/ */
public void appendFunctionStyleMacro(TokenList result) { public void appendFunctionStyleMacro(TokenList result) {
MacroInfo minfo= fMacroStack.getLast(); MacroInfo minfo= fMacroStack.getLast();
boolean active= true; boolean active= true;
int nesting= -1; int nesting= -1;
int pcount= 0; int pcount= 0;
@ -298,7 +298,7 @@ public class MacroExpansionTracker {
result.append(t); result.append(t);
} }
break; break;
default: default:
if (active) { if (active) {
result.append(t); result.append(t);

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Sergey Prigogin (Google) - initial API and implementation * Sergey Prigogin (Google) - initial API and implementation
* *
* Based on lookup3.c, by Bob Jenkins {@link "http://burtleburtle.net/bob/c/lookup3.c"} * Based on lookup3.c, by Bob Jenkins {@link "http://burtleburtle.net/bob/c/lookup3.c"}
* *
@ -44,7 +44,6 @@
* mixing with 12*3 instructions on 3 integers than you can with 3 instructions * mixing with 12*3 instructions on 3 integers than you can with 3 instructions
* on 1 byte), but shoehorning those bytes into integers efficiently is messy. * on 1 byte), but shoehorning those bytes into integers efficiently is messy.
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
/** /**

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -48,7 +48,7 @@ public class Token implements IToken, Cloneable {
@Override @Override
final public int getLength() { final public int getLength() {
return fEndOffset-fOffset; return fEndOffset - fOffset;
} }
@Override @Override
@ -56,7 +56,6 @@ public class Token implements IToken, Cloneable {
return fNextToken; return fNextToken;
} }
@Override @Override
final public void setType(int kind) { final public void setType(int kind) {
fKind= kind; fKind= kind;
@ -73,8 +72,8 @@ public class Token implements IToken, Cloneable {
} }
public void shiftOffset(int shift) { public void shiftOffset(int shift) {
fOffset+= shift; fOffset += shift;
fEndOffset+= shift; fEndOffset += shift;
} }
@Override @Override
@ -86,7 +85,7 @@ public class Token implements IToken, Cloneable {
public String toString() { public String toString() {
return getImage(); return getImage();
} }
@Override @Override
final public boolean isOperator() { final public boolean isOperator() {
return TokenUtil.isOperator(fKind); return TokenUtil.isOperator(fKind);

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
class TokenList { class TokenList {
@ -17,7 +17,8 @@ class TokenList {
final Token removeFirst() { final Token removeFirst() {
final Token first= fFirst; final Token first= fFirst;
if (first == fLast) { if (first == fLast) {
fFirst= fLast= null; fFirst= null;
fLast= null;
return first; return first;
} }
fFirst= (Token) first.getNext(); fFirst= (Token) first.getNext();
@ -26,38 +27,38 @@ class TokenList {
public final void append(Token t) { public final void append(Token t) {
if (fFirst == null) { if (fFirst == null) {
fFirst= fLast= t; fFirst= t;
} fLast= t;
else { } else {
fLast.setNext(t); fLast.setNext(t);
fLast= t; fLast= t;
} }
t.setNext(null); t.setNext(null);
} }
public final void appendAll(TokenList tl) { public final void appendAll(TokenList tl) {
final Token t= tl.first(); final Token t= tl.first();
if (t != null) { if (t != null) {
if (fFirst == null) { if (fFirst == null) {
fFirst= tl.fFirst; fFirst= tl.fFirst;
} } else {
else {
fLast.setNext(tl.fFirst); fLast.setNext(tl.fFirst);
} }
fLast= tl.fLast; fLast= tl.fLast;
} }
tl.fFirst= tl.fLast= null; tl.fFirst= null;
tl.fLast= null;
} }
public final void appendAllButLast(TokenList tl) { public final void appendAllButLast(TokenList tl) {
Token t= tl.first(); Token t= tl.first();
if (t != null) { if (t != null) {
for (Token n= (Token) t.getNext(); n != null; t=n, n= (Token) n.getNext()) { for (Token n= (Token) t.getNext(); n != null; t= n, n= (Token) n.getNext()) {
append(t); append(t);
} }
} }
} }
public final void prepend(Token t) { public final void prepend(Token t) {
final Token first= t; final Token first= t;
if (first != null) { if (first != null) {
@ -81,7 +82,7 @@ class TokenList {
} }
} }
} }
public final TokenList cloneTokens() { public final TokenList cloneTokens() {
TokenList result= new TokenList(); TokenList result= new TokenList();
for (Token t= fFirst; t != null; t= (Token) t.getNext()) { for (Token t= fFirst; t != null; t= (Token) t.getNext()) {
@ -110,8 +111,7 @@ class TokenList {
fLast= null; fLast= null;
} }
} }
} } else {
else {
final Token r= (Token) l.getNext(); final Token r= (Token) l.getNext();
if (r != null) { if (r != null) {
l.setNext(r.getNext()); l.setNext(r.getNext());
@ -124,19 +124,20 @@ class TokenList {
void cutAfter(Token l) { void cutAfter(Token l) {
if (l == null) { if (l == null) {
fFirst= fLast= null; fFirst= null;
} fLast= null;
else { } else {
l.setNext(null); l.setNext(null);
fLast= l; fLast= l;
} }
} }
public void clear() { public void clear() {
fFirst= fLast= null; fFirst= null;
fLast= null;
} }
public boolean isEmpty() { public boolean isEmpty() {
return fFirst==null; return fFirst == null;
} }
} }

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IGCCToken;
@ -20,7 +20,7 @@ public class TokenUtil {
private static final char[] SPACE = {' '}; private static final char[] SPACE = {' '};
private static final char[] IMAGE_POUND_POUND = "##".toCharArray(); //$NON-NLS-1$ private static final char[] IMAGE_POUND_POUND = "##".toCharArray(); //$NON-NLS-1$
private static final char[] IMAGE_POUND = "#".toCharArray(); //$NON-NLS-1$ private static final char[] IMAGE_POUND = "#".toCharArray(); //$NON-NLS-1$
private static final char[] DIGRAPH_LBRACE= "<%".toCharArray(); //$NON-NLS-1$ private static final char[] DIGRAPH_LBRACE= "<%".toCharArray(); //$NON-NLS-1$
private static final char[] DIGRAPH_RBRACE= "%>".toCharArray(); //$NON-NLS-1$ private static final char[] DIGRAPH_RBRACE= "%>".toCharArray(); //$NON-NLS-1$
private static final char[] DIGRAPH_LBRACKET= "<:".toCharArray(); //$NON-NLS-1$ private static final char[] DIGRAPH_LBRACKET= "<:".toCharArray(); //$NON-NLS-1$
@ -40,7 +40,7 @@ public class TokenUtil {
case IToken.tSHIFTL: case IToken.tSHIFTLASSIGN: case IToken.tSHIFTL: case IToken.tSHIFTLASSIGN:
case IToken.tSHIFTR: case IToken.tSHIFTRASSIGN: case IToken.tSHIFTR: case IToken.tSHIFTRASSIGN:
case IToken.tXOR: case IToken.tXORASSIGN: case IToken.tXOR: case IToken.tXORASSIGN:
// logical operations // logical operations
case IToken.tNOT: case IToken.tAND: case IToken.tOR: case IToken.tNOT: case IToken.tAND: case IToken.tOR:
@ -52,25 +52,25 @@ public class TokenUtil {
case IToken.tPLUS: case IToken.tPLUSASSIGN: case IToken.tPLUS: case IToken.tPLUSASSIGN:
case IToken.tSTAR: case IToken.tSTARASSIGN: case IToken.tSTAR: case IToken.tSTARASSIGN:
case IGCCToken.tMAX: case IGCCToken.tMIN: case IGCCToken.tMAX: case IGCCToken.tMIN:
// comparison // comparison
case IToken.tEQUAL: case IToken.tNOTEQUAL: case IToken.tEQUAL: case IToken.tNOTEQUAL:
case IToken.tGT: case IToken.tGTEQUAL: case IToken.tGT: case IToken.tGTEQUAL:
case IToken.tLT: case IToken.tLTEQUAL: case IToken.tLT: case IToken.tLTEQUAL:
// other // other
case IToken.tASSIGN: case IToken.tCOMMA: case IToken.tASSIGN: case IToken.tCOMMA:
return true; return true;
} }
return false; return false;
} }
public static char[] getImage(int type) { public static char[] getImage(int type) {
switch (type) { switch (type) {
case IToken.tPOUND: return IMAGE_POUND; case IToken.tPOUND: return IMAGE_POUND;
case IToken.tPOUNDPOUND: return IMAGE_POUND_POUND; case IToken.tPOUNDPOUND: return IMAGE_POUND_POUND;
case IToken.tCOLONCOLON: return Keywords.cpCOLONCOLON; case IToken.tCOLONCOLON: return Keywords.cpCOLONCOLON;
case IToken.tCOLON: return Keywords.cpCOLON; case IToken.tCOLON: return Keywords.cpCOLON;
case IToken.tSEMI: return Keywords.cpSEMI; case IToken.tSEMI: return Keywords.cpSEMI;
case IToken.tCOMMA: return Keywords.cpCOMMA; case IToken.tCOMMA: return Keywords.cpCOMMA;
@ -120,34 +120,33 @@ public class TokenUtil {
case IToken.tDOT: return Keywords.cpDOT; case IToken.tDOT: return Keywords.cpDOT;
case IToken.tDIVASSIGN: return Keywords.cpDIVASSIGN; case IToken.tDIVASSIGN: return Keywords.cpDIVASSIGN;
case IToken.tDIV: return Keywords.cpDIV; case IToken.tDIV: return Keywords.cpDIV;
case IGCCToken.tMIN: return Keywords.cpMIN; case IGCCToken.tMIN: return Keywords.cpMIN;
case IGCCToken.tMAX: return Keywords.cpMAX; case IGCCToken.tMAX: return Keywords.cpMAX;
case CPreprocessor.tSPACE: return SPACE; case CPreprocessor.tSPACE: return SPACE;
case CPreprocessor.tNOSPACE: return CharArrayUtils.EMPTY; case CPreprocessor.tNOSPACE: return CharArrayUtils.EMPTY;
default: default:
return CharArrayUtils.EMPTY; return CharArrayUtils.EMPTY;
} }
} }
public static char[] getDigraphImage(int type) { public static char[] getDigraphImage(int type) {
switch (type) { switch (type) {
case IToken.tPOUND: return DIGRAPH_POUND; case IToken.tPOUND: return DIGRAPH_POUND;
case IToken.tPOUNDPOUND: return DIGRAPH_POUNDPOUND; case IToken.tPOUNDPOUND: return DIGRAPH_POUNDPOUND;
case IToken.tLBRACKET: return DIGRAPH_LBRACKET; case IToken.tLBRACKET: return DIGRAPH_LBRACKET;
case IToken.tRBRACKET: return DIGRAPH_RBRACKET; case IToken.tRBRACKET: return DIGRAPH_RBRACKET;
case IToken.tLBRACE: return DIGRAPH_LBRACE; case IToken.tLBRACE: return DIGRAPH_LBRACE;
case IToken.tRBRACE: return DIGRAPH_RBRACE; case IToken.tRBRACE: return DIGRAPH_RBRACE;
default: default:
assert false: type; assert false: type;
return CharArrayUtils.EMPTY; return CharArrayUtils.EMPTY;
} }
} }
/** /**
* Returns the last token in the given token list. * Returns the last token in the given token list.
* @throws NullPointerException if the argument is null * @throws NullPointerException if the argument is null
@ -156,8 +155,7 @@ public class TokenUtil {
IToken last; IToken last;
do { do {
last = tokenList; last = tokenList;
} while((tokenList = tokenList.getNext()) != null); } while ((tokenList = tokenList.getNext()) != null);
return last; return last;
} }
} }