mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
modify Scanner2.scanIdentifier wrt escaped newlines.
remove a couple of uses of String
This commit is contained in:
parent
a7fcc4aa84
commit
0dda631a21
4 changed files with 31 additions and 9 deletions
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
||||||
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -694,7 +695,7 @@ public class ReferenceCache implements IReferenceManager {
|
||||||
if (!(obj instanceof IASTReference))
|
if (!(obj instanceof IASTReference))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (((IASTReference) obj).getName().equals(getName())
|
if ( CharArrayUtils.equals( ((IASTReference) obj).getNameCharArray(), getNameCharArray() )
|
||||||
&& ((IASTReference) obj).getOffset() == getOffset())
|
&& ((IASTReference) obj).getOffset() == getOffset())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class CharArrayUtils {
|
||||||
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) {
|
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) {
|
||||||
if (length1 != str2.length || str1.length < length1 )
|
if (length1 != str2.length || str1.length < length1 )
|
||||||
return false;
|
return false;
|
||||||
|
if( str1 == str2 && start1 == 0 )
|
||||||
|
return true;
|
||||||
for (int i = 0; i < length1; ++i)
|
for (int i = 0; i < length1; ++i)
|
||||||
if (str1[start1++] != str2[i])
|
if (str1[start1++] != str2[i])
|
||||||
return false;
|
return false;
|
||||||
|
@ -193,6 +194,16 @@ public class CharArrayUtils {
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int indexOf( char toBeFound, char[] buffer, int start, int len ) {
|
||||||
|
if( start < 0 || start > buffer.length || start + len > buffer.length )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (int i = start; i < len; i++)
|
||||||
|
if (toBeFound == buffer[i])
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
public static final int indexOf( char[] toBeFound, char[] array ){
|
public static final int indexOf( char[] toBeFound, char[] array ){
|
||||||
if( toBeFound.length > array.length )
|
if( toBeFound.length > array.length )
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -257,4 +268,6 @@ public class CharArrayUtils {
|
||||||
buff[ i + j ] = charImage[j];
|
buff[ i + j ] = charImage[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -730,6 +730,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
|
|
||||||
private IToken scanIdentifier() {
|
private IToken scanIdentifier() {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
|
boolean escapedNewline = false;
|
||||||
int start = bufferPos[bufferStackPos];
|
int start = bufferPos[bufferStackPos];
|
||||||
int limit = bufferLimit[bufferStackPos];
|
int limit = bufferLimit[bufferStackPos];
|
||||||
int len = 1;
|
int len = 1;
|
||||||
|
@ -746,6 +747,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
// escaped newline
|
// escaped newline
|
||||||
++bufferPos[bufferStackPos];
|
++bufferPos[bufferStackPos];
|
||||||
len += 2;
|
len += 2;
|
||||||
|
escapedNewline = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if( c == '\\' && ( bufferPos[bufferStackPos] + 1 < limit ) )
|
else if( c == '\\' && ( bufferPos[bufferStackPos] + 1 < limit ) )
|
||||||
|
@ -793,10 +795,14 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
return new MacroExpansionToken();
|
return new MacroExpansionToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
int tokenType = keywords.get(buffer, start, len);
|
char [] result = escapedNewline ? removedEscapedNewline( buffer, start, len ) : null;
|
||||||
char [] result = removedEscapedNewline( CharArrayUtils.extract( buffer, start, len ) );
|
int tokenType = escapedNewline ? keywords.get(result, 0, result.length)
|
||||||
if (tokenType == keywords.undefined)
|
: keywords.get(buffer, start, len );
|
||||||
|
|
||||||
|
if (tokenType == keywords.undefined){
|
||||||
|
result = (result != null) ? result : CharArrayUtils.extract( buffer, start, len );
|
||||||
return newToken(IToken.tIDENTIFIER, result );
|
return newToken(IToken.tIDENTIFIER, result );
|
||||||
|
}
|
||||||
return newToken(tokenType);
|
return newToken(tokenType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1408,7 +1414,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
|
|
||||||
if( encounteredMultilineComment )
|
if( encounteredMultilineComment )
|
||||||
text = removeMultilineCommentFromBuffer( text );
|
text = removeMultilineCommentFromBuffer( text );
|
||||||
text = removedEscapedNewline( text );
|
text = removedEscapedNewline( text, 0, text.length );
|
||||||
|
|
||||||
// Throw it in
|
// Throw it in
|
||||||
definitions.put(name, arglist == null
|
definitions.put(name, arglist == null
|
||||||
|
@ -1424,8 +1430,8 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
* @param text
|
* @param text
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private char[] removedEscapedNewline(char[] text) {
|
private char[] removedEscapedNewline(char[] text, int start, int len ) {
|
||||||
if( CharArrayUtils.indexOf( '\n', text ) == -1 )
|
if( CharArrayUtils.indexOf( '\n', text, start, len ) == -1 )
|
||||||
return text;
|
return text;
|
||||||
char [] result = new char[ text.length ];
|
char [] result = new char[ text.length ];
|
||||||
Arrays.fill( result, ' ');
|
Arrays.fill( result, ' ');
|
||||||
|
|
|
@ -542,7 +542,9 @@ public class BasicTokenDuple implements ITokenDuple {
|
||||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#toCharArray()
|
* @see org.eclipse.cdt.core.parser.ITokenDuple#toCharArray()
|
||||||
*/
|
*/
|
||||||
public char[] toCharArray() {
|
public char[] toCharArray() {
|
||||||
return toString().toCharArray(); //TODO fix me!
|
if( stringRepresentation == null )
|
||||||
|
stringRepresentation = createCharArrayRepresentation(firstToken, lastToken);
|
||||||
|
return stringRepresentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
Loading…
Add table
Reference in a new issue