mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
more string to char[] changes. savings of about 10 meg (old scanner)
This commit is contained in:
parent
3a58a1be85
commit
2474e4f8b6
14 changed files with 49 additions and 26 deletions
|
@ -20,6 +20,7 @@ public interface IASTUsingDeclaration extends IASTDeclaration, IASTOffsetableEle
|
||||||
|
|
||||||
public boolean isTypename();
|
public boolean isTypename();
|
||||||
public String usingTypeName();
|
public String usingTypeName();
|
||||||
|
public char[] usingTypeNameCharArray();
|
||||||
public Iterator getUsingTypes() throws ASTNotImplementedException;
|
public Iterator getUsingTypes() throws ASTNotImplementedException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2704,7 +2704,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
TraceUtil
|
TraceUtil
|
||||||
.outputTrace(
|
.outputTrace(
|
||||||
log,
|
log,
|
||||||
"ScannerException thrown : ", e.getProblem(), null, null, null); //$NON-NLS-1$
|
"ScannerException thrown : ", e.getProblem() ); //$NON-NLS-1$
|
||||||
// log.errorLog("Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$
|
// log.errorLog("Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$
|
||||||
return fetchToken();
|
return fetchToken();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2475,8 +2475,9 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check for optional pure virtual
|
// check for optional pure virtual
|
||||||
|
char[] image = LA(2).getCharImage();
|
||||||
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tINTEGER
|
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tINTEGER
|
||||||
&& LA(2).getImage().equals("0")) //$NON-NLS-1$
|
&& ( image.length == 1 && image[0] == '0' ) ) //$NON-NLS-1$
|
||||||
{
|
{
|
||||||
consume(IToken.tASSIGN);
|
consume(IToken.tASSIGN);
|
||||||
consume(IToken.tINTEGER);
|
consume(IToken.tINTEGER);
|
||||||
|
|
|
@ -64,13 +64,13 @@ public class SelectionParser extends ContextualParser {
|
||||||
boolean change = false;
|
boolean change = false;
|
||||||
if( value.getOffset() == offsetRange.getFloorOffset() )
|
if( value.getOffset() == offsetRange.getFloorOffset() )
|
||||||
{
|
{
|
||||||
TraceUtil.outputTrace(log, "Offset Floor Hit w/token \"", null, value.getImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
|
TraceUtil.outputTrace(log, "Offset Floor Hit w/token \"", null, value.getCharImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
firstTokenOfDuple = value;
|
firstTokenOfDuple = value;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
if( value.getEndOffset() == offsetRange.getCeilingOffset() )
|
if( value.getEndOffset() == offsetRange.getCeilingOffset() )
|
||||||
{
|
{
|
||||||
TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
|
TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getCharImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
change = true;
|
change = true;
|
||||||
lastTokenOfDuple = value;
|
lastTokenOfDuple = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
|
||||||
private final boolean isTypeName;
|
private final boolean isTypeName;
|
||||||
private final List declarations = new ArrayList();
|
private final List declarations = new ArrayList();
|
||||||
private List references;
|
private List references;
|
||||||
private String name;
|
private char[] name;
|
||||||
private final char [] fn;
|
private final char [] fn;
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename()
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename()
|
||||||
|
@ -43,7 +43,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
|
||||||
* @param filename
|
* @param filename
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public ASTUsingDeclaration( IASTScope ownerScope, String name, List declarations, boolean isTypeName, int startingOffset, int startingLine, int endingOffset, int endingLine, List references, char[] filename )
|
public ASTUsingDeclaration( IASTScope ownerScope, char[] name, List declarations, boolean isTypeName, int startingOffset, int startingLine, int endingOffset, int endingLine, List references, char[] filename )
|
||||||
{
|
{
|
||||||
this.ownerScope = ownerScope;
|
this.ownerScope = ownerScope;
|
||||||
this.isTypeName = isTypeName;
|
this.isTypeName = isTypeName;
|
||||||
|
@ -66,6 +66,9 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
|
||||||
*/
|
*/
|
||||||
public String usingTypeName()
|
public String usingTypeName()
|
||||||
{
|
{
|
||||||
|
return String.valueOf(name);
|
||||||
|
}
|
||||||
|
public char[] usingTypeNameCharArray(){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -595,7 +595,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
addReference( references, createReference( (ISymbol) i.next(), name.getLastToken().getCharImage(), name.getLastToken().getOffset() ) );
|
addReference( references, createReference( (ISymbol) i.next(), name.getLastToken().getCharImage(), name.getLastToken().getOffset() ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
ASTUsingDeclaration using = new ASTUsingDeclaration( scope, name.getLastToken().getImage(),
|
ASTUsingDeclaration using = new ASTUsingDeclaration( scope, name.getLastToken().getCharImage(),
|
||||||
endResult.getReferencedSymbols(), isTypeName, startingOffset, startingLine, endingOffset, endingLine, references, filename );
|
endResult.getReferencedSymbols(), isTypeName, startingOffset, startingLine, endingOffset, endingLine, references, filename );
|
||||||
attachSymbolExtension( endResult, using );
|
attachSymbolExtension( endResult, using );
|
||||||
|
|
||||||
|
@ -884,7 +884,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
IProblem p = problemFactory.createProblem( id,
|
IProblem p = problemFactory.createProblem( id,
|
||||||
startOffset, endOffset, lineNumber, filename, attribute, !isError, isError );
|
startOffset, endOffset, lineNumber, filename, attribute, !isError, isError );
|
||||||
|
|
||||||
TraceUtil.outputTrace(logService, "CompleteParseASTFactory - IProblem : ", p, null, null, null ); //$NON-NLS-1$
|
TraceUtil.outputTrace(logService, "CompleteParseASTFactory - IProblem : ", p ); //$NON-NLS-1$
|
||||||
|
|
||||||
if( shouldThrowException( scope, id, !isError ) )
|
if( shouldThrowException( scope, id, !isError ) )
|
||||||
throw new ASTSemanticException(p);
|
throw new ASTSemanticException(p);
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class ASTUsingDeclaration
|
||||||
implements IASTUsingDeclaration {
|
implements IASTUsingDeclaration {
|
||||||
|
|
||||||
private final boolean isTypename;
|
private final boolean isTypename;
|
||||||
private final String mappingName;
|
private final char [] mappingName;
|
||||||
private final char [] fn;
|
private final char [] fn;
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename()
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename()
|
||||||
|
@ -37,7 +37,7 @@ public class ASTUsingDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ASTUsingDeclaration( IASTScope scope, boolean isTypeName, String mappingName, int startingOffset, int startingLine, int endingOffset, int endingLine, char[] filename )
|
public ASTUsingDeclaration( IASTScope scope, boolean isTypeName, char[] mappingName, int startingOffset, int startingLine, int endingOffset, int endingLine, char[] filename )
|
||||||
{
|
{
|
||||||
super( scope );
|
super( scope );
|
||||||
isTypename = isTypeName;
|
isTypename = isTypeName;
|
||||||
|
@ -57,7 +57,10 @@ public class ASTUsingDeclaration
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#usingTypeName()
|
* @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#usingTypeName()
|
||||||
*/
|
*/
|
||||||
public String usingTypeName() {
|
public String usingTypeName() {
|
||||||
return mappingName;
|
return String.valueOf(mappingName);
|
||||||
|
}
|
||||||
|
public char[] usingTypeNameCharArray(){
|
||||||
|
return mappingName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.internal.core.parser.TokenDuple)
|
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, boolean, org.eclipse.cdt.internal.core.parser.TokenDuple)
|
||||||
*/
|
*/
|
||||||
public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, boolean isTypeName, ITokenDuple name, int startingOffset, int startingLine, int endingOffset, int endingLine) {
|
public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, boolean isTypeName, ITokenDuple name, int startingOffset, int startingLine, int endingOffset, int endingLine) {
|
||||||
return new ASTUsingDeclaration( scope, isTypeName, name.toString(), startingOffset, startingLine, endingOffset, endingLine, name.getFilename() );
|
return new ASTUsingDeclaration( scope, isTypeName, name.toCharArray(), startingOffset, startingLine, endingOffset, endingLine, name.getFilename() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
||||||
public void handlePreprocessorDirective(IScannerData iscanner, String directive, String restOfLine) {
|
public void handlePreprocessorDirective(IScannerData iscanner, String directive, String restOfLine) {
|
||||||
if( directive.equals(POUND_INCLUDE_NEXT) )
|
if( directive.equals(POUND_INCLUDE_NEXT) )
|
||||||
{
|
{
|
||||||
TraceUtil.outputTrace(iscanner.getLogService(), "GCCScannerExtension handling #include_next directive", null, null, null, null); //$NON-NLS-1$
|
TraceUtil.outputTrace(iscanner.getLogService(), "GCCScannerExtension handling #include_next directive" ); //$NON-NLS-1$
|
||||||
// figure out the name of the current file and its path
|
// figure out the name of the current file and its path
|
||||||
IScannerContext context = iscanner.getContextStack().getCurrentContext();
|
IScannerContext context = iscanner.getContextStack().getCurrentContext();
|
||||||
if( context == null || context.getKind() != IScannerContext.ContextKind.INCLUSION )
|
if( context == null || context.getKind() != IScannerContext.ContextKind.INCLUSION )
|
||||||
|
|
|
@ -130,7 +130,7 @@ public final class Scanner implements IScanner, IScannerData {
|
||||||
error );
|
error );
|
||||||
|
|
||||||
// trace log
|
// trace log
|
||||||
TraceUtil.outputTrace(log, "Scanner problem encountered: ", problem, null, null, null ); //$NON-NLS-1$
|
TraceUtil.outputTrace(log, "Scanner problem encountered: ", problem ); //$NON-NLS-1$
|
||||||
|
|
||||||
if( (! requestor.acceptProblem( problem )) && extra )
|
if( (! requestor.acceptProblem( problem )) && extra )
|
||||||
throw new ScannerException( problem );
|
throw new ScannerException( problem );
|
||||||
|
|
|
@ -311,11 +311,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
nextToken = null;
|
nextToken = null;
|
||||||
finished = true;
|
finished = true;
|
||||||
} else {
|
} else {
|
||||||
String t1 = lastToken.getImage();
|
char[] pb = CharArrayUtils.concat( lastToken.getCharImage(), token2.getCharImage() );
|
||||||
String t2 = token2.getImage();
|
|
||||||
char[] pb = new char[t1.length() + t2.length()];
|
|
||||||
t1.getChars(0, t1.length(), pb, 0);
|
|
||||||
t2.getChars(0, t2.length(), pb, t1.length());
|
|
||||||
pushContext(pb);
|
pushContext(pb);
|
||||||
lastToken = oldToken;
|
lastToken = oldToken;
|
||||||
nextToken = null;
|
nextToken = null;
|
||||||
|
@ -327,7 +323,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
int tokenType = IToken.tSTRING;
|
int tokenType = IToken.tSTRING;
|
||||||
if( lastToken.getType() == IToken.tLSTRING || nextToken.getType() == IToken.tLSTRING )
|
if( lastToken.getType() == IToken.tLSTRING || nextToken.getType() == IToken.tLSTRING )
|
||||||
tokenType = IToken.tLSTRING;
|
tokenType = IToken.tLSTRING;
|
||||||
lastToken = new ImagedToken(tokenType, (lastToken.getImage() + nextToken.getImage()).toCharArray(), nextToken.getEndOffset(), getCurrentFilename() ); //TODO Fix this
|
lastToken = new ImagedToken(tokenType, CharArrayUtils.concat( lastToken.getCharImage(), nextToken.getCharImage() ), nextToken.getEndOffset(), getCurrentFilename() );
|
||||||
if (oldToken != null)
|
if (oldToken != null)
|
||||||
oldToken.setNext(lastToken);
|
oldToken.setNext(lastToken);
|
||||||
nextToken = fetchToken();
|
nextToken = fetchToken();
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class ImagedToken extends SimpleToken {
|
||||||
*/
|
*/
|
||||||
protected void setOffsetAndLength(IScannerContext context) {
|
protected void setOffsetAndLength(IScannerContext context) {
|
||||||
if( getImage() == null ) return;
|
if( getImage() == null ) return;
|
||||||
offset = context.getOffset() - getImage().length();
|
offset = context.getOffset() - getCharImage().length;
|
||||||
if( getType() == tSTRING || getType() == tCHAR )
|
if( getType() == tSTRING || getType() == tCHAR )
|
||||||
offset--;
|
offset--;
|
||||||
else if( getType() == tLSTRING || getType() == tLCHAR )
|
else if( getType() == tLSTRING || getType() == tLCHAR )
|
||||||
|
@ -74,18 +74,18 @@ public class ImagedToken extends SimpleToken {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
if( getImage() == null )
|
if( getCharImage() == null )
|
||||||
return 0;
|
return 0;
|
||||||
switch( getType() )
|
switch( getType() )
|
||||||
{
|
{
|
||||||
case tSTRING:
|
case tSTRING:
|
||||||
case tCHAR:
|
case tCHAR:
|
||||||
return getImage().length() + 2; // 'c' is 3 characters, not 1
|
return getCharImage().length + 2; // 'c' is 3 characters, not 1
|
||||||
case tLSTRING:
|
case tLSTRING:
|
||||||
case tLCHAR:
|
case tLCHAR:
|
||||||
return getImage().length() + 3; // L"X" if 4 characters, not 1
|
return getCharImage().length + 3; // L"X" if 4 characters, not 1
|
||||||
default:
|
default:
|
||||||
return getImage().length();
|
return getCharImage().length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class SimpleToken extends AbstractToken implements IToken {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
return getImage().length();
|
return getCharImage().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,6 +29,25 @@ public class TraceUtil {
|
||||||
log.traceLog( buffer.toString() );
|
log.traceLog( buffer.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void outputTrace(IParserLogService log, String preface, IProblem problem ) {
|
||||||
|
if( log.isTracing() ) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
if( preface != null ) buffer.append( preface );
|
||||||
|
if( problem != null ) buffer.append( problem.getMessage());
|
||||||
|
log.traceLog( buffer.toString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void outputTrace(IParserLogService log, String preface, IProblem problem, char[] first, String second, String third ) {
|
||||||
|
if( log.isTracing() ) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
if( preface != null ) buffer.append( preface );
|
||||||
|
if( problem != null ) buffer.append( problem.getMessage());
|
||||||
|
if( first != null ) buffer.append( first );
|
||||||
|
if( second != null ) buffer.append( second );
|
||||||
|
if( third != null ) buffer.append( third );
|
||||||
|
log.traceLog( buffer.toString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void outputTrace(IParserLogService log, String preface, IProblem problem, int first, String second, int third ) {
|
public static void outputTrace(IParserLogService log, String preface, IProblem problem, int first, String second, int third ) {
|
||||||
if( log.isTracing() ) {
|
if( log.isTracing() ) {
|
||||||
outputTrace(
|
outputTrace(
|
||||||
|
|
Loading…
Add table
Reference in a new issue