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 String usingTypeName();
|
||||
public char[] usingTypeNameCharArray();
|
||||
public Iterator getUsingTypes() throws ASTNotImplementedException;
|
||||
|
||||
}
|
||||
|
|
|
@ -2704,7 +2704,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
TraceUtil
|
||||
.outputTrace(
|
||||
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$
|
||||
return fetchToken();
|
||||
}
|
||||
|
|
|
@ -2475,8 +2475,9 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
}
|
||||
// check for optional pure virtual
|
||||
char[] image = LA(2).getCharImage();
|
||||
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.tINTEGER);
|
||||
|
|
|
@ -64,13 +64,13 @@ public class SelectionParser extends ContextualParser {
|
|||
boolean change = false;
|
||||
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;
|
||||
change = true;
|
||||
}
|
||||
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;
|
||||
lastTokenOfDuple = value;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
|
|||
private final boolean isTypeName;
|
||||
private final List declarations = new ArrayList();
|
||||
private List references;
|
||||
private String name;
|
||||
private char[] name;
|
||||
private final char [] fn;
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename()
|
||||
|
@ -43,7 +43,7 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
|
|||
* @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.isTypeName = isTypeName;
|
||||
|
@ -66,6 +66,9 @@ public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
|
|||
*/
|
||||
public String usingTypeName()
|
||||
{
|
||||
return String.valueOf(name);
|
||||
}
|
||||
public char[] usingTypeNameCharArray(){
|
||||
return name;
|
||||
}
|
||||
/* (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() ) );
|
||||
|
||||
}
|
||||
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 );
|
||||
attachSymbolExtension( endResult, using );
|
||||
|
||||
|
@ -884,7 +884,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
IProblem p = problemFactory.createProblem( id,
|
||||
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 ) )
|
||||
throw new ASTSemanticException(p);
|
||||
|
|
|
@ -27,7 +27,7 @@ public class ASTUsingDeclaration
|
|||
implements IASTUsingDeclaration {
|
||||
|
||||
private final boolean isTypename;
|
||||
private final String mappingName;
|
||||
private final char [] mappingName;
|
||||
private final char [] fn;
|
||||
/* (non-Javadoc)
|
||||
* @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 );
|
||||
isTypename = isTypeName;
|
||||
|
@ -57,7 +57,10 @@ public class ASTUsingDeclaration
|
|||
* @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#usingTypeName()
|
||||
*/
|
||||
public String usingTypeName() {
|
||||
return mappingName;
|
||||
return String.valueOf(mappingName);
|
||||
}
|
||||
public char[] usingTypeNameCharArray(){
|
||||
return mappingName;
|
||||
}
|
||||
|
||||
/* (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)
|
||||
*/
|
||||
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)
|
||||
|
|
|
@ -161,7 +161,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
public void handlePreprocessorDirective(IScannerData iscanner, String directive, String restOfLine) {
|
||||
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
|
||||
IScannerContext context = iscanner.getContextStack().getCurrentContext();
|
||||
if( context == null || context.getKind() != IScannerContext.ContextKind.INCLUSION )
|
||||
|
|
|
@ -130,7 +130,7 @@ public final class Scanner implements IScanner, IScannerData {
|
|||
error );
|
||||
|
||||
// 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 )
|
||||
throw new ScannerException( problem );
|
||||
|
|
|
@ -311,11 +311,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
nextToken = null;
|
||||
finished = true;
|
||||
} else {
|
||||
String t1 = lastToken.getImage();
|
||||
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());
|
||||
char[] pb = CharArrayUtils.concat( lastToken.getCharImage(), token2.getCharImage() );
|
||||
pushContext(pb);
|
||||
lastToken = oldToken;
|
||||
nextToken = null;
|
||||
|
@ -327,7 +323,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
int tokenType = IToken.tSTRING;
|
||||
if( lastToken.getType() == IToken.tLSTRING || nextToken.getType() == 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)
|
||||
oldToken.setNext(lastToken);
|
||||
nextToken = fetchToken();
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ImagedToken extends SimpleToken {
|
|||
*/
|
||||
protected void setOffsetAndLength(IScannerContext context) {
|
||||
if( getImage() == null ) return;
|
||||
offset = context.getOffset() - getImage().length();
|
||||
offset = context.getOffset() - getCharImage().length;
|
||||
if( getType() == tSTRING || getType() == tCHAR )
|
||||
offset--;
|
||||
else if( getType() == tLSTRING || getType() == tLCHAR )
|
||||
|
@ -74,18 +74,18 @@ public class ImagedToken extends SimpleToken {
|
|||
}
|
||||
|
||||
public int getLength() {
|
||||
if( getImage() == null )
|
||||
if( getCharImage() == null )
|
||||
return 0;
|
||||
switch( getType() )
|
||||
{
|
||||
case tSTRING:
|
||||
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 tLCHAR:
|
||||
return getImage().length() + 3; // L"X" if 4 characters, not 1
|
||||
return getCharImage().length + 3; // L"X" if 4 characters, not 1
|
||||
default:
|
||||
return getImage().length();
|
||||
return getCharImage().length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class SimpleToken extends AbstractToken implements IToken {
|
|||
}
|
||||
|
||||
public int getLength() {
|
||||
return getImage().length();
|
||||
return getCharImage().length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,25 @@ public class TraceUtil {
|
|||
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 ) {
|
||||
if( log.isTracing() ) {
|
||||
outputTrace(
|
||||
|
|
Loading…
Add table
Reference in a new issue