mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cosmetics.
This commit is contained in:
parent
78f863bc01
commit
76ddab24aa
9 changed files with 167 additions and 172 deletions
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -45,22 +45,22 @@ public class MacroDefinitionParser {
|
|||
*/
|
||||
static class TokenParameterReference extends TokenWithImage {
|
||||
private final int fIndex;
|
||||
|
||||
|
||||
public TokenParameterReference(int type, int idx, Object source, int offset, int endOffset, char[] name) {
|
||||
super(type, source, offset, endOffset, name);
|
||||
fIndex= idx;
|
||||
}
|
||||
|
||||
|
||||
public int getIndex() {
|
||||
return fIndex;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + fIndex + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static char[] getExpansion(AbstractCharArray expansionImage, int offset, int endOffset) {
|
||||
TokenList tl= new TokenList();
|
||||
Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null);
|
||||
|
@ -83,7 +83,7 @@ public class MacroDefinitionParser {
|
|||
buf.append(t.getCharImage());
|
||||
endOffset= t.getEndOffset();
|
||||
}
|
||||
final int length= buf.length();
|
||||
final int length= buf.length();
|
||||
final char[] expansion= new char[length];
|
||||
buf.getChars(0, length, expansion, 0);
|
||||
return expansion;
|
||||
|
@ -93,10 +93,10 @@ public class MacroDefinitionParser {
|
|||
private int fExpansionOffset;
|
||||
private int fExpansionEndOffset;
|
||||
private Token fNameToken;
|
||||
|
||||
|
||||
MacroDefinitionParser() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In case the name was successfully parsed, the name token is returned.
|
||||
* Otherwise the return value is undefined.
|
||||
|
@ -105,10 +105,10 @@ public class MacroDefinitionParser {
|
|||
return fNameToken;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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 {
|
||||
final Token name = parseName(lexer);
|
||||
final AbstractCharArray source= lexer.getInput();
|
||||
|
@ -122,10 +122,10 @@ public class MacroDefinitionParser {
|
|||
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.
|
||||
*/
|
||||
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 {
|
||||
final Token name = parseName(lexer);
|
||||
|
||||
|
@ -135,14 +135,14 @@ public class MacroDefinitionParser {
|
|||
if (replacementToken.getType() != IToken.tEND_OF_INPUT) {
|
||||
throw new InvalidMacroDefinitionException(nameChars, replacementToken.getOffset(), replacementToken.getEndOffset());
|
||||
}
|
||||
|
||||
if (paramList == null) {
|
||||
|
||||
if (paramList == null) {
|
||||
return new ObjectStyleMacro(nameChars, replacement);
|
||||
}
|
||||
return new FunctionStyleMacro(nameChars, paramList, fHasVarArgs, replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Parses a macro definition basically checking for var-args.
|
||||
*/
|
||||
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 FunctionStyleMacro(name, paramList, hasVarargs, replacement);
|
||||
|
@ -195,11 +195,11 @@ public class MacroDefinitionParser {
|
|||
fNameToken= name;
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
private char[][] parseParamList(Lexer lex, final Token name) throws OffsetLimitReachedException, InvalidMacroDefinitionException {
|
||||
final Token lparen= lex.nextToken();
|
||||
fHasVarArgs= FunctionStyleMacro.NO_VAARGS;
|
||||
if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) {
|
||||
if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) {
|
||||
return null;
|
||||
}
|
||||
ArrayList<char[]> paramList= new ArrayList<char[]>();
|
||||
|
@ -224,7 +224,7 @@ public class MacroDefinitionParser {
|
|||
paramList.add(Keywords.cVA_ARGS);
|
||||
next= lex.nextToken();
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tRPAREN:
|
||||
if (next == null) {
|
||||
next= param;
|
||||
|
@ -255,7 +255,7 @@ public class MacroDefinitionParser {
|
|||
Token needAnotherToken= null;
|
||||
|
||||
Token candidate= lexer.currentToken();
|
||||
fExpansionOffset= fExpansionEndOffset= candidate.getOffset();
|
||||
fExpansionOffset= fExpansionEndOffset= candidate.getOffset();
|
||||
|
||||
loop: while(true) {
|
||||
switch (candidate.getType()) {
|
||||
|
@ -266,18 +266,16 @@ public class MacroDefinitionParser {
|
|||
break loop;
|
||||
case IToken.tIDENTIFIER:
|
||||
if (paramList != null) {
|
||||
// convert the parameters to special tokens
|
||||
// Convert the parameters to special tokens.
|
||||
final char[] image = candidate.getCharImage();
|
||||
int idx= CharArrayUtils.indexOf(image, paramList);
|
||||
if (idx >= 0) {
|
||||
candidate= new TokenParameterReference(CPreprocessor.tMACRO_PARAMETER, idx, lexer.getSource(), candidate.getOffset(), candidate.getEndOffset(), paramList[idx]);
|
||||
needParam= false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (needParam) {
|
||||
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());
|
||||
}
|
||||
needParam= false;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -35,9 +35,9 @@ public class MacroExpander {
|
|||
private static final class AbortMacroExpansionException extends Exception {}
|
||||
|
||||
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
|
||||
* handle recursive expansions and to figure out whether spaces are required during a stringify
|
||||
* operation across such boundaries.
|
||||
|
@ -56,7 +56,7 @@ public class MacroExpander {
|
|||
public char[] getCharImage() {
|
||||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
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.
|
||||
*/
|
||||
private class TokenSource extends TokenList {
|
||||
|
@ -112,7 +112,7 @@ public class MacroExpander {
|
|||
|
||||
if (fLexer != null) {
|
||||
t= fLexer.currentToken();
|
||||
while(t.getType() == Lexer.tNEWLINE) {
|
||||
while (t.getType() == Lexer.tNEWLINE) {
|
||||
t= fLexer.nextToken();
|
||||
}
|
||||
return t.getType() == IToken.tLPAREN;
|
||||
|
@ -131,14 +131,14 @@ public class MacroExpander {
|
|||
private boolean fCompletionMode;
|
||||
private int fStartOffset;
|
||||
private int fEndOffset;
|
||||
|
||||
|
||||
// for using the expander to track expansions
|
||||
private String fFixedCurrentFilename;
|
||||
private int fFixedLineNumber;
|
||||
private char[] fFixedInput;
|
||||
private ScannerContext fReportMacros;
|
||||
private boolean fReportUndefined;
|
||||
|
||||
|
||||
public MacroExpander(ILexerLog log, CharArrayMap<PreprocessorMacro> macroDictionary,
|
||||
LocationMap locationMap, LexerOptions lexOptions) {
|
||||
fDictionary= macroDictionary;
|
||||
|
@ -147,10 +147,10 @@ public class MacroExpander {
|
|||
fLexOptions= lexOptions;
|
||||
fLog= log;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* 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,
|
||||
PreprocessorMacro macro, Token identifier, boolean completionMode,
|
||||
|
@ -162,16 +162,16 @@ public class MacroExpander {
|
|||
} else {
|
||||
fReportMacros= null;
|
||||
}
|
||||
|
||||
|
||||
fImplicitMacroExpansions.clear();
|
||||
fImageLocationInfos.clear();
|
||||
|
||||
|
||||
fStartOffset= identifier.getOffset();
|
||||
fEndOffset= identifier.getEndOffset();
|
||||
fCompletionMode= completionMode;
|
||||
|
||||
|
||||
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden= new IdentityHashMap<PreprocessorMacro, PreprocessorMacro>();
|
||||
|
||||
|
||||
// setup input sequence
|
||||
TokenSource input= new TokenSource(lexer);
|
||||
TokenList firstExpansion= new TokenList();
|
||||
|
@ -186,8 +186,8 @@ public class MacroExpander {
|
|||
|
||||
result= expandAll(input, forbidden, protectDefined, null);
|
||||
} catch (CompletionInMacroExpansionException e) {
|
||||
// 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
|
||||
// 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
|
||||
// they are inserted at the position of the expansion.
|
||||
// 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.
|
||||
|
@ -211,7 +211,7 @@ public class MacroExpander {
|
|||
fFixedLineNumber= lineNumber;
|
||||
fReportMacros= null;
|
||||
Lexer lexer= new Lexer(fFixedInput, fLexOptions, fLog, this);
|
||||
|
||||
|
||||
try {
|
||||
tracker.start(fFixedInput);
|
||||
Token identifier= lexer.nextToken();
|
||||
|
@ -246,21 +246,21 @@ public class MacroExpander {
|
|||
} catch (OffsetLimitReachedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* together with boundary markers in the result token list.
|
||||
* @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,
|
||||
TokenList result, MacroExpansionTracker tracker)
|
||||
throws OffsetLimitReachedException {
|
||||
if (fReportMacros != null)
|
||||
fReportMacros.significantMacro(macro);
|
||||
|
||||
|
||||
if (macro.isFunctionStyle()) {
|
||||
final int paramCount = macro.getParameterPlaceholderList().length;
|
||||
final TokenSource[] argInputs= new TokenSource[paramCount];
|
||||
|
@ -271,13 +271,13 @@ public class MacroExpander {
|
|||
try {
|
||||
lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker);
|
||||
} catch (AbortMacroExpansionException e) {
|
||||
// ignore this macro expansion
|
||||
// Ignore this macro expansion.
|
||||
for (TokenSource argInput : argInputs) {
|
||||
executeScopeMarkers(argInput, forbidden);
|
||||
if (tracker != null) {
|
||||
tracker.setExpandedMacroArgument(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tracker != null) {
|
||||
if (tracker.isRequestedStep()) {
|
||||
tracker.storeFunctionStyleMacroReplacement(macro, new TokenList(), result);
|
||||
|
@ -288,7 +288,7 @@ public class MacroExpander {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
TokenList[] clonedArgs= new TokenList[paramCount];
|
||||
TokenList[] expandedArgs= new TokenList[paramCount];
|
||||
for (int i = 0; i < paramCount; i++) {
|
||||
|
@ -342,11 +342,11 @@ public class MacroExpander {
|
|||
|
||||
private void executeScopeMarkers(TokenSource input, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden) {
|
||||
Token t= input.removeFirst();
|
||||
while(t != null) {
|
||||
while (t != null) {
|
||||
if (t.getType() == CPreprocessor.tSCOPE_MARKER) {
|
||||
((ExpansionBoundary) t).execute(forbidden);
|
||||
}
|
||||
t= input.removeFirst();
|
||||
t= input.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ public class MacroExpander {
|
|||
boolean protect= false;
|
||||
Token l= null;
|
||||
Token t= input.removeFirst();
|
||||
while(t != null) {
|
||||
while (t != null) {
|
||||
switch (t.getType()) {
|
||||
case CPreprocessor.tSCOPE_MARKER:
|
||||
((ExpansionBoundary) t).execute(forbidden);
|
||||
|
@ -395,7 +395,7 @@ public class MacroExpander {
|
|||
|
||||
addSpacemarker(l, t, replacement); // start expansion
|
||||
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));
|
||||
addSpacemarker(last, input.first(), replacement); // end expansion
|
||||
|
||||
|
@ -404,12 +404,12 @@ public class MacroExpander {
|
|||
break;
|
||||
case IToken.tLPAREN:
|
||||
case CPreprocessor.tNOSPACE:
|
||||
case CPreprocessor.tSPACE:
|
||||
case CPreprocessor.tSPACE:
|
||||
result.append(t);
|
||||
break;
|
||||
default:
|
||||
protect= false;
|
||||
result.append(t);
|
||||
result.append(t);
|
||||
break;
|
||||
}
|
||||
l= t;
|
||||
|
@ -450,26 +450,26 @@ public class MacroExpander {
|
|||
}
|
||||
target.append(new Token(CPreprocessor.tNOSPACE, null, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expects that the identifier has been consumed.
|
||||
*/
|
||||
private Token parseArguments(TokenSource input, FunctionStyleMacro macro,
|
||||
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden,
|
||||
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden,
|
||||
TokenSource[] result, MacroExpansionTracker tracker)
|
||||
throws OffsetLimitReachedException, AbortMacroExpansionException {
|
||||
final int argCount= macro.getParameterPlaceholderList().length;
|
||||
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 nesting= -1;
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i]= new TokenSource(null);
|
||||
}
|
||||
|
||||
|
||||
boolean missingRParenthesis= false;
|
||||
boolean tooManyArgs= false;
|
||||
|
||||
|
||||
boolean isFirstOfArg= true;
|
||||
Token lastToken= null;
|
||||
TokenList spaceMarkers= new TokenList();
|
||||
|
@ -481,7 +481,7 @@ public class MacroExpander {
|
|||
}
|
||||
if (tracker != null) {
|
||||
switch (t.getType()) {
|
||||
case IToken.tEND_OF_INPUT:
|
||||
case IToken.tEND_OF_INPUT:
|
||||
case IToken.tCOMPLETION:
|
||||
case CPreprocessor.tSCOPE_MARKER:
|
||||
case Lexer.tNEWLINE:
|
||||
|
@ -509,28 +509,28 @@ public class MacroExpander {
|
|||
throw new CompletionInMacroExpansionException(ORIGIN, t, result[idx]);
|
||||
}
|
||||
throw new OffsetLimitReachedException(ORIGIN, t);
|
||||
|
||||
|
||||
case Lexer.tNEWLINE:
|
||||
continue loop;
|
||||
|
||||
case IToken.tLPAREN:
|
||||
// the first one sets nesting to zero.
|
||||
// The first one sets nesting to zero.
|
||||
if (++nesting == 0) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tRPAREN:
|
||||
assert nesting >= 0;
|
||||
if (--nesting < 0) {
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tCOMMA:
|
||||
assert nesting >= 0;
|
||||
if (nesting == 0) {
|
||||
if (idx < argCount-1) { // next argument
|
||||
if (idx < argCount - 1) { // Next argument.
|
||||
isFirstOfArg= true;
|
||||
spaceMarkers.clear();
|
||||
idx++;
|
||||
|
@ -541,7 +541,7 @@ public class MacroExpander {
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CPreprocessor.tSCOPE_MARKER:
|
||||
if (argCount == 0) {
|
||||
((ExpansionBoundary) t).execute(forbidden);
|
||||
|
@ -549,14 +549,14 @@ public class MacroExpander {
|
|||
result[idx].append(t);
|
||||
}
|
||||
continue loop;
|
||||
|
||||
|
||||
case CPreprocessor.tSPACE:
|
||||
case CPreprocessor.tNOSPACE:
|
||||
if (!isFirstOfArg) {
|
||||
spaceMarkers.append(t);
|
||||
}
|
||||
continue loop;
|
||||
|
||||
|
||||
default:
|
||||
assert nesting >= 0;
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ public class MacroExpander {
|
|||
handleProblem(IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST, macro.getNameCharArray());
|
||||
throw new AbortMacroExpansionException();
|
||||
}
|
||||
|
||||
|
||||
if (tooManyArgs) {
|
||||
handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, macro.getNameCharArray());
|
||||
} else if (idx + 1 < requiredArgs) {
|
||||
|
@ -581,18 +581,18 @@ public class MacroExpander {
|
|||
}
|
||||
return lastToken;
|
||||
}
|
||||
|
||||
|
||||
private void handleProblem(int problemID, char[] arg) {
|
||||
fLog.handleProblem(problemID, arg, fStartOffset, fEndOffset);
|
||||
}
|
||||
|
||||
private void replaceArgs(PreprocessorMacro macro, TokenList[] args, TokenList[] expandedArgs, TokenList result) {
|
||||
TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this));
|
||||
|
||||
|
||||
Token l= null;
|
||||
Token n;
|
||||
Token pasteArg1= null;
|
||||
for (Token t= replacement.first(); t != null; l=t, t=n) {
|
||||
Token n;
|
||||
Token pasteArg1= null;
|
||||
for (Token t= replacement.first(); t != null; l= t, t= n) {
|
||||
n= (Token) t.getNext();
|
||||
|
||||
switch (t.getType()) {
|
||||
|
@ -614,7 +614,7 @@ public class MacroExpander {
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tPOUND:
|
||||
addSpacemarker(l, t, result); // start stringify
|
||||
StringBuilder buf= new StringBuilder();
|
||||
|
@ -628,19 +628,19 @@ public class MacroExpander {
|
|||
n= (Token) n.getNext();
|
||||
}
|
||||
buf.append('"');
|
||||
final int length= buf.length();
|
||||
final int length= buf.length();
|
||||
final char[] image= new char[length];
|
||||
buf.getChars(0, length, image, 0);
|
||||
|
||||
|
||||
Token generated= new TokenWithImage(IToken.tSTRING, null, 0, 0, image);
|
||||
if (isKind(n, IToken.tPOUNDPOUND)) { // start token paste, same as start stringify
|
||||
pasteArg1= generated;
|
||||
pasteArg1= generated;
|
||||
} else {
|
||||
result.append(generated);
|
||||
addSpacemarker(t, n, result); // end stringify
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tPOUNDPOUND:
|
||||
Token pasteArg2= null;
|
||||
TokenList rest= null;
|
||||
|
@ -664,7 +664,7 @@ public class MacroExpander {
|
|||
idx= -1;
|
||||
pasteArg2= n;
|
||||
}
|
||||
|
||||
|
||||
t= n;
|
||||
n= (Token) n.getNext();
|
||||
final boolean pasteNext= isKind(n, IToken.tPOUNDPOUND);
|
||||
|
@ -676,7 +676,7 @@ public class MacroExpander {
|
|||
generated= pasteArg1;
|
||||
if (rest == null)
|
||||
rest= new TokenList();
|
||||
|
||||
|
||||
rest.prepend(pasteArg2);
|
||||
spaceDef0= generated;
|
||||
spaceDef1= pasteArg2;
|
||||
|
@ -707,15 +707,15 @@ public class MacroExpander {
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tCOMMA:
|
||||
if (isKind(n, IToken.tPOUNDPOUND)) {
|
||||
final Token nn= (Token) n.getNext();
|
||||
if (isKind(nn, CPreprocessor.tMACRO_PARAMETER)) {
|
||||
idx= ((TokenParameterReference) nn).getIndex();
|
||||
|
||||
|
||||
// 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)) {
|
||||
final Token nnn= (Token) nn.getNext();
|
||||
TokenList arg= clone(expandedArgs[idx]);
|
||||
|
@ -733,14 +733,14 @@ public class MacroExpander {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addSpacemarker(l, t, result);
|
||||
pasteArg1= t;
|
||||
} else {
|
||||
result.append(t);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if (isKind(n, IToken.tPOUNDPOUND)) {
|
||||
addSpacemarker(l, t, result); // start token paste
|
||||
|
@ -752,7 +752,7 @@ public class MacroExpander {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isKind(final IToken t, final int kind) {
|
||||
return t != null && t.getType() == kind;
|
||||
}
|
||||
|
@ -760,9 +760,9 @@ public class MacroExpander {
|
|||
private BitSet getParamUsage(PreprocessorMacro macro) {
|
||||
final BitSet result= new BitSet();
|
||||
final TokenList replacement= macro.getTokens(fDefinitionParser, fLexOptions, this);
|
||||
|
||||
|
||||
Token l= null;
|
||||
Token n;
|
||||
Token n;
|
||||
for (Token t= replacement.first(); t != null; l= t, t= n) {
|
||||
n= (Token) t.getNext();
|
||||
switch (t.getType()) {
|
||||
|
@ -773,7 +773,7 @@ public class MacroExpander {
|
|||
}
|
||||
result.set(idx);
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tPOUND:
|
||||
if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) {
|
||||
idx= ((TokenParameterReference) n).getIndex();
|
||||
|
@ -781,7 +781,7 @@ public class MacroExpander {
|
|||
t= n; n= (Token) n.getNext();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case IToken.tPOUNDPOUND:
|
||||
if (isKind(n, CPreprocessor.tMACRO_PARAMETER)) {
|
||||
idx= ((TokenParameterReference) n).getIndex();
|
||||
|
@ -795,17 +795,17 @@ public class MacroExpander {
|
|||
t= n; n= (Token) n.getNext();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void objStyleTokenPaste(PreprocessorMacro macro, TokenList result) {
|
||||
TokenList replacement= clone(macro.getTokens(fDefinitionParser, fLexOptions, this));
|
||||
|
||||
|
||||
Token l= null;
|
||||
Token n;
|
||||
Token pasteArg1= null;
|
||||
Token n;
|
||||
Token pasteArg1= null;
|
||||
for (Token t= replacement.first(); t != null; l= t, t= n) {
|
||||
n= (Token) t.getNext();
|
||||
|
||||
|
@ -817,7 +817,7 @@ public class MacroExpander {
|
|||
pasteArg2= n;
|
||||
n= (Token) n.getNext();
|
||||
}
|
||||
|
||||
|
||||
t= tokenpaste(pasteArg1, pasteArg2, macro);
|
||||
if (t != null) {
|
||||
if (isKind(n, IToken.tPOUNDPOUND)) {
|
||||
|
@ -829,7 +829,7 @@ public class MacroExpander {
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if (isKind(n, IToken.tPOUNDPOUND)) {
|
||||
addSpacemarker(l, t, result); // start token paste
|
||||
|
@ -910,7 +910,7 @@ public class MacroExpander {
|
|||
}
|
||||
space= false;
|
||||
break;
|
||||
|
||||
|
||||
case CPreprocessor.tSPACE:
|
||||
if (!space && l != null && n != null) {
|
||||
buf.append(' ');
|
||||
|
@ -920,7 +920,7 @@ public class MacroExpander {
|
|||
|
||||
case CPreprocessor.tNOSPACE:
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
buf.append(t.getCharImage());
|
||||
space= false;
|
||||
|
@ -928,7 +928,7 @@ public class MacroExpander {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IASTName[] clearImplicitExpansions() {
|
||||
IASTName[] result= fImplicitMacroExpansions.toArray(new IASTName[fImplicitMacroExpansions.size()]);
|
||||
fImplicitMacroExpansions.clear();
|
||||
|
@ -983,7 +983,7 @@ public class MacroExpander {
|
|||
l= t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int getCurrentLineNumber() {
|
||||
if (fFixedInput != null) {
|
||||
return fFixedLineNumber + countNewlines(fFixedInput);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -30,12 +30,12 @@ public class MacroExpansionStep implements IMacroExpansionStep {
|
|||
fMacroDefinition= def;
|
||||
fMacroLocation= macroLoc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCodeBeforeStep() {
|
||||
return fBefore;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCodeAfterStep() {
|
||||
StringBuilder result= new StringBuilder();
|
||||
|
@ -49,7 +49,7 @@ public class MacroExpansionStep implements IMacroExpansionStep {
|
|||
result.append(fBefore, offset, fBefore.length());
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IMacroBinding getExpandedMacro() {
|
||||
return fMacroDefinition;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -35,7 +35,7 @@ public class MacroExpansionTracker {
|
|||
}
|
||||
|
||||
private final int fStepToTrack;
|
||||
|
||||
|
||||
private int fStepCount;
|
||||
private String fPreStep;
|
||||
private ReplaceEdit fReplacement;
|
||||
|
@ -58,14 +58,14 @@ public class MacroExpansionTracker {
|
|||
public boolean isDone() {
|
||||
return fStepCount > fStepToTrack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether we are currently looking at the requested step.
|
||||
*/
|
||||
public boolean isRequestedStep() {
|
||||
return fStepCount == fStepToTrack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the total amount of steps encountered so far.
|
||||
*/
|
||||
|
@ -79,7 +79,7 @@ public class MacroExpansionTracker {
|
|||
public String getCodeBeforeStep() {
|
||||
return fPreStep;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* There was no macro at the beginning of the input.
|
||||
*/
|
||||
|
@ -140,7 +140,7 @@ public class MacroExpansionTracker {
|
|||
fPreStep= new String(fInput);
|
||||
fReplacement= new ReplaceEdit(0, 0, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
private void toString(TokenList tokenList, char[] rootInput, StringBuilder before,
|
||||
StringBuilder replace, StringBuilder after) {
|
||||
StringBuilder buf= before;
|
||||
|
@ -176,7 +176,7 @@ public class MacroExpansionTracker {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private char[] getInputForSource(Object source, char[] rootInput) {
|
||||
if (source instanceof MacroExpander) {
|
||||
return rootInput;
|
||||
|
@ -197,7 +197,7 @@ public class MacroExpansionTracker {
|
|||
public void startFunctionStyleMacro(Token identifier) {
|
||||
fMacroStack.add(new MacroInfo(identifier));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void appendFunctionStyleMacro(TokenList result) {
|
||||
MacroInfo minfo= fMacroStack.getLast();
|
||||
MacroInfo minfo= fMacroStack.getLast();
|
||||
boolean active= true;
|
||||
int nesting= -1;
|
||||
int pcount= 0;
|
||||
|
@ -298,7 +298,7 @@ public class MacroExpansionTracker {
|
|||
result.append(t);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if (active) {
|
||||
result.append(t);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* 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"}
|
||||
*
|
||||
|
@ -44,7 +44,6 @@
|
|||
* 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.
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
@ -48,7 +48,7 @@ public class Token implements IToken, Cloneable {
|
|||
|
||||
@Override
|
||||
final public int getLength() {
|
||||
return fEndOffset-fOffset;
|
||||
return fEndOffset - fOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,6 @@ public class Token implements IToken, Cloneable {
|
|||
return fNextToken;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
final public void setType(int kind) {
|
||||
fKind= kind;
|
||||
|
@ -73,8 +72,8 @@ public class Token implements IToken, Cloneable {
|
|||
}
|
||||
|
||||
public void shiftOffset(int shift) {
|
||||
fOffset+= shift;
|
||||
fEndOffset+= shift;
|
||||
fOffset += shift;
|
||||
fEndOffset += shift;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,7 +85,7 @@ public class Token implements IToken, Cloneable {
|
|||
public String toString() {
|
||||
return getImage();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
final public boolean isOperator() {
|
||||
return TokenUtil.isOperator(fKind);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
class TokenList {
|
||||
|
@ -17,7 +17,8 @@ class TokenList {
|
|||
final Token removeFirst() {
|
||||
final Token first= fFirst;
|
||||
if (first == fLast) {
|
||||
fFirst= fLast= null;
|
||||
fFirst= null;
|
||||
fLast= null;
|
||||
return first;
|
||||
}
|
||||
fFirst= (Token) first.getNext();
|
||||
|
@ -26,38 +27,38 @@ class TokenList {
|
|||
|
||||
public final void append(Token t) {
|
||||
if (fFirst == null) {
|
||||
fFirst= fLast= t;
|
||||
}
|
||||
else {
|
||||
fFirst= t;
|
||||
fLast= t;
|
||||
} else {
|
||||
fLast.setNext(t);
|
||||
fLast= t;
|
||||
}
|
||||
t.setNext(null);
|
||||
}
|
||||
|
||||
|
||||
public final void appendAll(TokenList tl) {
|
||||
final Token t= tl.first();
|
||||
if (t != null) {
|
||||
if (fFirst == null) {
|
||||
fFirst= tl.fFirst;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fLast.setNext(tl.fFirst);
|
||||
}
|
||||
fLast= tl.fLast;
|
||||
}
|
||||
tl.fFirst= tl.fLast= null;
|
||||
tl.fFirst= null;
|
||||
tl.fLast= null;
|
||||
}
|
||||
|
||||
public final void appendAllButLast(TokenList tl) {
|
||||
Token t= tl.first();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void prepend(Token t) {
|
||||
final Token first= t;
|
||||
if (first != null) {
|
||||
|
@ -81,7 +82,7 @@ class TokenList {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final TokenList cloneTokens() {
|
||||
TokenList result= new TokenList();
|
||||
for (Token t= fFirst; t != null; t= (Token) t.getNext()) {
|
||||
|
@ -110,8 +111,7 @@ class TokenList {
|
|||
fLast= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
final Token r= (Token) l.getNext();
|
||||
if (r != null) {
|
||||
l.setNext(r.getNext());
|
||||
|
@ -124,19 +124,20 @@ class TokenList {
|
|||
|
||||
void cutAfter(Token l) {
|
||||
if (l == null) {
|
||||
fFirst= fLast= null;
|
||||
}
|
||||
else {
|
||||
fFirst= null;
|
||||
fLast= null;
|
||||
} else {
|
||||
l.setNext(null);
|
||||
fLast= l;
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
fFirst= fLast= null;
|
||||
fFirst= null;
|
||||
fLast= null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return fFirst==null;
|
||||
return fFirst == null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
|
@ -20,7 +20,7 @@ public class TokenUtil {
|
|||
private static final char[] SPACE = {' '};
|
||||
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[] DIGRAPH_LBRACE= "<%".toCharArray(); //$NON-NLS-1$
|
||||
private static final char[] DIGRAPH_RBRACE= "%>".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.tSHIFTR: case IToken.tSHIFTRASSIGN:
|
||||
case IToken.tXOR: case IToken.tXORASSIGN:
|
||||
|
||||
|
||||
// logical operations
|
||||
case IToken.tNOT: case IToken.tAND: case IToken.tOR:
|
||||
|
||||
|
@ -52,25 +52,25 @@ public class TokenUtil {
|
|||
case IToken.tPLUS: case IToken.tPLUSASSIGN:
|
||||
case IToken.tSTAR: case IToken.tSTARASSIGN:
|
||||
case IGCCToken.tMAX: case IGCCToken.tMIN:
|
||||
|
||||
|
||||
// comparison
|
||||
case IToken.tEQUAL: case IToken.tNOTEQUAL:
|
||||
case IToken.tGT: case IToken.tGTEQUAL:
|
||||
case IToken.tLT: case IToken.tLTEQUAL:
|
||||
|
||||
|
||||
// other
|
||||
case IToken.tASSIGN: case IToken.tCOMMA:
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static char[] getImage(int type) {
|
||||
switch (type) {
|
||||
case IToken.tPOUND: return IMAGE_POUND;
|
||||
case IToken.tPOUNDPOUND: return IMAGE_POUND_POUND;
|
||||
case IToken.tCOLONCOLON: return Keywords.cpCOLONCOLON;
|
||||
case IToken.tPOUNDPOUND: return IMAGE_POUND_POUND;
|
||||
case IToken.tCOLONCOLON: return Keywords.cpCOLONCOLON;
|
||||
case IToken.tCOLON: return Keywords.cpCOLON;
|
||||
case IToken.tSEMI: return Keywords.cpSEMI;
|
||||
case IToken.tCOMMA: return Keywords.cpCOMMA;
|
||||
|
@ -120,34 +120,33 @@ public class TokenUtil {
|
|||
case IToken.tDOT: return Keywords.cpDOT;
|
||||
case IToken.tDIVASSIGN: return Keywords.cpDIVASSIGN;
|
||||
case IToken.tDIV: return Keywords.cpDIV;
|
||||
|
||||
|
||||
case IGCCToken.tMIN: return Keywords.cpMIN;
|
||||
case IGCCToken.tMAX: return Keywords.cpMAX;
|
||||
|
||||
case CPreprocessor.tSPACE: return SPACE;
|
||||
|
||||
case CPreprocessor.tSPACE: return SPACE;
|
||||
case CPreprocessor.tNOSPACE: return CharArrayUtils.EMPTY;
|
||||
|
||||
|
||||
default:
|
||||
return CharArrayUtils.EMPTY;
|
||||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static char[] getDigraphImage(int type) {
|
||||
switch (type) {
|
||||
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.tRBRACKET: return DIGRAPH_RBRACKET;
|
||||
case IToken.tLBRACE: return DIGRAPH_LBRACE;
|
||||
case IToken.tRBRACE: return DIGRAPH_RBRACE;
|
||||
|
||||
|
||||
default:
|
||||
assert false: type;
|
||||
return CharArrayUtils.EMPTY;
|
||||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the last token in the given token list.
|
||||
* @throws NullPointerException if the argument is null
|
||||
|
@ -156,8 +155,7 @@ public class TokenUtil {
|
|||
IToken last;
|
||||
do {
|
||||
last = tokenList;
|
||||
} while((tokenList = tokenList.getNext()) != null);
|
||||
} while ((tokenList = tokenList.getNext()) != null);
|
||||
return last;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue