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.IASTVariableReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -694,7 +695,7 @@ public class ReferenceCache implements IReferenceManager {
|
|||
if (!(obj instanceof IASTReference))
|
||||
return false;
|
||||
|
||||
if (((IASTReference) obj).getName().equals(getName())
|
||||
if ( CharArrayUtils.equals( ((IASTReference) obj).getNameCharArray(), getNameCharArray() )
|
||||
&& ((IASTReference) obj).getOffset() == getOffset())
|
||||
return true;
|
||||
return false;
|
||||
|
|
|
@ -55,7 +55,8 @@ public class CharArrayUtils {
|
|||
public static final boolean equals(char[] str1, int start1, int length1, char[] str2) {
|
||||
if (length1 != str2.length || str1.length < length1 )
|
||||
return false;
|
||||
|
||||
if( str1 == str2 && start1 == 0 )
|
||||
return true;
|
||||
for (int i = 0; i < length1; ++i)
|
||||
if (str1[start1++] != str2[i])
|
||||
return false;
|
||||
|
@ -193,6 +194,16 @@ public class CharArrayUtils {
|
|||
return i;
|
||||
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 ){
|
||||
if( toBeFound.length > array.length )
|
||||
return -1;
|
||||
|
@ -257,4 +268,6 @@ public class CharArrayUtils {
|
|||
buff[ i + j ] = charImage[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -730,6 +730,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
|
||||
private IToken scanIdentifier() {
|
||||
char[] buffer = bufferStack[bufferStackPos];
|
||||
boolean escapedNewline = false;
|
||||
int start = bufferPos[bufferStackPos];
|
||||
int limit = bufferLimit[bufferStackPos];
|
||||
int len = 1;
|
||||
|
@ -746,6 +747,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
// escaped newline
|
||||
++bufferPos[bufferStackPos];
|
||||
len += 2;
|
||||
escapedNewline = true;
|
||||
continue;
|
||||
}
|
||||
else if( c == '\\' && ( bufferPos[bufferStackPos] + 1 < limit ) )
|
||||
|
@ -793,10 +795,14 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
return new MacroExpansionToken();
|
||||
}
|
||||
|
||||
int tokenType = keywords.get(buffer, start, len);
|
||||
char [] result = removedEscapedNewline( CharArrayUtils.extract( buffer, start, len ) );
|
||||
if (tokenType == keywords.undefined)
|
||||
char [] result = escapedNewline ? removedEscapedNewline( buffer, start, len ) : null;
|
||||
int tokenType = escapedNewline ? keywords.get(result, 0, result.length)
|
||||
: 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(tokenType);
|
||||
}
|
||||
|
||||
|
@ -1408,7 +1414,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
|
||||
if( encounteredMultilineComment )
|
||||
text = removeMultilineCommentFromBuffer( text );
|
||||
text = removedEscapedNewline( text );
|
||||
text = removedEscapedNewline( text, 0, text.length );
|
||||
|
||||
// Throw it in
|
||||
definitions.put(name, arglist == null
|
||||
|
@ -1424,8 +1430,8 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private char[] removedEscapedNewline(char[] text) {
|
||||
if( CharArrayUtils.indexOf( '\n', text ) == -1 )
|
||||
private char[] removedEscapedNewline(char[] text, int start, int len ) {
|
||||
if( CharArrayUtils.indexOf( '\n', text, start, len ) == -1 )
|
||||
return text;
|
||||
char [] result = new char[ text.length ];
|
||||
Arrays.fill( result, ' ');
|
||||
|
|
|
@ -542,7 +542,9 @@ public class BasicTokenDuple implements ITokenDuple {
|
|||
* @see org.eclipse.cdt.core.parser.ITokenDuple#toCharArray()
|
||||
*/
|
||||
public char[] toCharArray() {
|
||||
return toString().toCharArray(); //TODO fix me!
|
||||
if( stringRepresentation == null )
|
||||
stringRepresentation = createCharArrayRepresentation(firstToken, lastToken);
|
||||
return stringRepresentation;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
Loading…
Add table
Reference in a new issue