[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Patch to remove some temporary objects from the scanner
|
Here is a patch that removes some temporary
objects that the scanner was producing
When scanning "windows.h",
there were about 1,070,000 objects created. After this patch there
are about 910,000 objects created. (1.6 sec elapsed time drops to
1.5 sec)
The JUnits still pass.
-
DaveIndex: parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java,v
retrieving revision 1.9
diff -u -r1.9 ExpressionParser.java
--- parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java 5 Apr 2004 18:18:57 -0000 1.9
+++ parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java 6 Apr 2004 20:27:09 -0000
@@ -2470,7 +2470,7 @@
}
catch (ScannerException e)
{
- TraceUtil.outputTrace(log, "ScannerException thrown : ", e.getProblem(), null, null, null);
+ TraceUtil.outputTrace(log, "ScannerException thrown : ", e.getProblem(), null, null, null); //$NON-NLS-1$
log.errorLog( "Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$h
failParse();
return fetchToken();
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.169
diff -u -r1.169 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 6 Apr 2004 15:38:08 -0000 1.169
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 6 Apr 2004 20:27:12 -0000
@@ -2149,7 +2149,7 @@
catch (BacktrackException e)
{
failParse();
- TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null );
+ TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null ); //$NON-NLS-1$
consume();
// eat this token anyway
continue;
Index: parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java,v
retrieving revision 1.7
diff -u -r1.7 SelectionParser.java
--- parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java 5 Apr 2004 18:18:57 -0000 1.7
+++ parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java 6 Apr 2004 20:27:12 -0000
@@ -42,15 +42,15 @@
protected void handleNewToken(IToken value) {
if( value != null && scanner.isOnTopContext() )
{
- TraceUtil.outputTrace(log, "IToken provided w/offsets ", null, value.getOffset(), " & ", value.getEndOffset() );
+ TraceUtil.outputTrace(log, "IToken provided w/offsets ", null, value.getOffset(), " & ", value.getEndOffset() ); //$NON-NLS-1$ //$NON-NLS-2$
if( value.getOffset() == offsetRange.getFloorOffset() )
{
- TraceUtil.outputTrace(log, "Offset Floor Hit w/token \"", null, value.getImage(), "\"", null );
+ TraceUtil.outputTrace(log, "Offset Floor Hit w/token \"", null, value.getImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
firstTokenOfDuple = value;
}
if( value.getEndOffset() == offsetRange.getCeilingOffset() )
{
- TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getImage(), "\"", null );
+ TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$
lastTokenOfDuple = value;
}
if( scanner.isOnTopContext() && lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() )
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.95
diff -u -r1.95 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 6 Apr 2004 18:12:55 -0000 1.95
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 6 Apr 2004 20:27:15 -0000
@@ -793,7 +793,7 @@
IProblem p = problemFactory.createProblem( id,
startOffset, endOffset, lineNumber, fileProvider.getCurrentFilename(), attribute, false, true );
- TraceUtil.outputTrace(logService, "CompleteParseASTFactory - IProblem : ", p, null, null, null );
+ TraceUtil.outputTrace(logService, "CompleteParseASTFactory - IProblem : ", p, null, null, null ); //$NON-NLS-1$
if( shouldThrowException( scope, id ) )
throw new ASTSemanticException(p);
@@ -1004,10 +1004,10 @@
{
TraceUtil.outputTrace(
logService,
- "Entering createExpression with Kind=",
+ "Entering createExpression with Kind=", //$NON-NLS-1$
null,
kind.getKindName(),
- " idexpression=",
+ " idexpression=", //$NON-NLS-1$
idExpression.toString()
);
}
@@ -1015,10 +1015,10 @@
{
TraceUtil.outputTrace(
logService,
- "Entering createExpression with Kind=",
+ "Entering createExpression with Kind=", //$NON-NLS-1$
null,
kind.getKindName(),
- " literal=",
+ " literal=", //$NON-NLS-1$
literal
);
}
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java,v
retrieving revision 1.5
diff -u -r1.5 ContextStack.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java 5 Apr 2004 18:18:57 -0000 1.5
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java 6 Apr 2004 20:27:18 -0000
@@ -73,7 +73,7 @@
if( !inclusions.add( context.getFilename() ) )
throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION );
- TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getFilename(), null, null );
+ TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getFilename(), null, null ); //$NON-NLS-1$
context.getExtension().enterScope( requestor );
} else if( context.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
@@ -98,7 +98,7 @@
if( currentContext.getKind() == IScannerContext.ContextKind.INCLUSION )
{
- TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, currentContext.getFilename(), null, null);
+ TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, currentContext.getFilename(), null, null); //$NON-NLS-1$
inclusions.remove( currentContext.getFilename() );
currentContext.getExtension().exitScope( requestor );
} else if( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java,v
retrieving revision 1.3
diff -u -r1.3 FunctionMacroDescriptor.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java 4 Mar 2004 18:00:20 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java 6 Apr 2004 20:27:18 -0000
@@ -27,19 +27,17 @@
* RHS expansion in the macro definition.
* @param sig The complete signature of the macro, as a string.
*/
- public FunctionMacroDescriptor( String name, List identifiers, List tokens, String fullSignature, String expansionSignature )
+ public FunctionMacroDescriptor( String name, List identifiers, List tokens, String expansionSignature )
{
this.name = name;
identifierParameters = identifiers;
tokenizedExpansion = tokens;
- signature = fullSignature;
this.expansionSignature = expansionSignature;
}
private String name;
private List identifierParameters;
private List tokenizedExpansion;
- private String signature;
private String expansionSignature;
/**
* Returns the identifiers.
@@ -102,7 +100,20 @@
*/
public final String getCompleteSignature()
{
- return signature;
+ StringBuffer fullSignature = new StringBuffer( "#define " ); //$NON-NLS-1$
+ fullSignature.append( name );
+ fullSignature.append( '(');
+ Iterator iter = getParameters().iterator();
+ int current = 0;
+ while( iter.hasNext() )
+ {
+ if (current > 0) fullSignature.append(',');
+ fullSignature.append((String)iter.next() );
+ current++;
+ }
+ fullSignature.append( ") "); //$NON-NLS-1$
+ fullSignature.append( expansionSignature );
+ return fullSignature.toString();
}
/* (non-Javadoc)
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java,v
retrieving revision 1.9
diff -u -r1.9 GCCScannerExtension.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java 6 Apr 2004 14:37:29 -0000 1.9
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java 6 Apr 2004 20:27:18 -0000
@@ -59,12 +59,12 @@
if( scannerData.getScanner().getDefinition( __ATTRIBUTE__) == null )
{
- scannerData.getScanner().addDefinition( __ATTRIBUTE__, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiers, EMPTY_LIST, "#define __attribute__( x )", "" )); //$NON-NLS-1$ $NON-NLS-2$
+ scannerData.getScanner().addDefinition( __ATTRIBUTE__, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiers, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$
}
if( scannerData.getScanner().getDefinition( __DECLSPEC) == null )
{
- scannerData.getScanner().addDefinition( __DECLSPEC, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiers, EMPTY_LIST, "#define __attribute__( x )", "" )); //$NON-NLS-1$ $NON-NLS-2$
+ scannerData.getScanner().addDefinition( __DECLSPEC, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiers, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$
}
@@ -111,7 +111,7 @@
public void handlePreprocessorDirective(String directive, String restOfLine) {
if( directive.equals("#include_next") ) //$NON-NLS-1$
{
- TraceUtil.outputTrace(scannerData.getLogService(), "GCCScannerExtension handling #include_next directive", null, null, null, null);
+ TraceUtil.outputTrace(scannerData.getLogService(), "GCCScannerExtension handling #include_next directive", null, null, null, null); //$NON-NLS-1$
// figure out the name of the current file and its path
IScannerContext context = scannerData.getContextStack().getCurrentContext();
if( context.getKind() != IScannerContext.ContextKind.INCLUSION )
@@ -158,7 +158,7 @@
}
}
- else if( directive.equals( "#warning") || directive.equals("#ident"))
+ else if( directive.equals( "#warning") || directive.equals("#ident")) //$NON-NLS-1$ //$NON-NLS-2$
return; // good enough -- the rest of the line has been consumed
}
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java,v
retrieving revision 1.3
diff -u -r1.3 ObjectMacroDescriptor.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java 26 Feb 2004 23:10:24 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java 6 Apr 2004 20:27:18 -0000
@@ -14,30 +14,29 @@
import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
+import org.eclipse.cdt.internal.core.parser.token.Token;
/**
* @author jcamelon
*/
public class ObjectMacroDescriptor implements IMacroDescriptor {
- private static final List EMPTY_LIST = new ArrayList();
- private final String fullSignature, expansionSignature;
+ private static final ArrayList EMPTY_LIST = new ArrayList();
+ private final String expansionSignature;
private final String name;
- private final List tokenizedExpansion;
+ private final Token token;
public ObjectMacroDescriptor( String name, String expansionSignature )
{
this.name = name;
this.expansionSignature = expansionSignature;
- fullSignature = "#define " + name + " " + expansionSignature; //$NON-NLS-1$ //$NON-NLS-2$
- tokenizedExpansion = EMPTY_LIST;
+ token = null;
}
- public ObjectMacroDescriptor( String name, String signature, List tokenizedExpansion, String expansionSignature )
+ public ObjectMacroDescriptor( String name, Token t, String expansionSignature )
{
this.name = name;
- this.tokenizedExpansion = tokenizedExpansion;
- this.fullSignature = signature;
+ this.token = t;
this.expansionSignature = expansionSignature;
}
@@ -59,7 +58,9 @@
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/
public List getTokenizedExpansion() {
- return tokenizedExpansion;
+ ArrayList x = new ArrayList();
+ x.add(token);
+ return x;
}
/* (non-Javadoc)
@@ -73,7 +74,12 @@
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getSignature()
*/
public String getCompleteSignature() {
- return fullSignature;
+ StringBuffer signatureBuffer = new StringBuffer();
+ signatureBuffer.append( "#define " ); //$NON-NLS-1$
+ signatureBuffer.append( name );
+ signatureBuffer.append( ' ' );
+ signatureBuffer.append( expansionSignature );
+ return signatureBuffer.toString();
}
/* (non-Javadoc)
@@ -82,12 +88,14 @@
public boolean compatible(IMacroDescriptor descriptor) {
if( descriptor.getName() == null ) return false;
if( descriptor.getMacroType() != getMacroType() ) return false;
- if( descriptor.getTokenizedExpansion() == null ) return false;
- if( ! name.equals( descriptor.getName() )) return false;
- if( descriptor.getTokenizedExpansion().size() != tokenizedExpansion.size() ) return false;
- if( ! (descriptor.getTokenizedExpansion().containsAll( tokenizedExpansion ))) return false;
- return true;
+ // Both macros are ObjectMacroDescriptors!
+
+ if( ! name.equals( descriptor.getName() )) return false;
+ String result = descriptor.getExpansionSignature();
+ if( result == null ) return expansionSignature == null;
+
+ return result.equals(expansionSignature);
}
/* (non-Javadoc)
Index: parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java,v
retrieving revision 1.29
diff -u -r1.29 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java 6 Apr 2004 14:37:29 -0000 1.29
+++ parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java 6 Apr 2004 20:27:21 -0000
@@ -98,7 +98,7 @@
error );
// trace log
- TraceUtil.outputTrace(scannerData.getLogService(), "Scanner problem encountered: ", problem, null, null, null );
+ TraceUtil.outputTrace(scannerData.getLogService(), "Scanner problem encountered: ", problem, null, null, null ); //$NON-NLS-1$
if( (! scannerData.getClientRequestor().acceptProblem( problem )) && extra )
throw new ScannerException( problem );
@@ -152,6 +152,7 @@
// assert false
}
+
TraceUtil.outputTrace(log, "Scanner constructed with the following configuration:"); //$NON-NLS-1$
TraceUtil.outputTrace(log, "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$
@@ -349,14 +350,9 @@
}
public void addDefinition(String key, String value) {
- StringBuffer signatureBuffer = new StringBuffer();
- signatureBuffer.append( key );
- signatureBuffer.append( ' ' );
- signatureBuffer.append( value );
-
addDefinition(key,
- new ObjectMacroDescriptor( key, signatureBuffer.toString(),
- tokenizeReplacementString( NO_OFFSET_LIMIT, key, value, null ), value ));
+ new ObjectMacroDescriptor( key,
+ value ));
}
public final IMacroDescriptor getDefinition(String key) {
@@ -382,9 +378,12 @@
}
protected String getRestOfPreprocessorLine() throws ScannerException, EndOfFileException {
- StringBuffer buffer = new StringBuffer();
+
skipOverWhitespace();
int c = getChar();
+ if (c == '\n')
+ return ""; //$NON-NLS-1$
+ StringBuffer buffer = new StringBuffer();
boolean inString = false;
boolean inChar = false;
while (true) {
@@ -586,7 +585,12 @@
try
{
- scannerData.getContextStack().updateContext(duple.getUnderlyingReader(), duple.getFilename(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
+ scannerData.getContextStack().updateContext(
+ duple.getUnderlyingReader(),
+ duple.getFilename(),
+ ScannerContext.ContextKind.INCLUSION,
+ inclusion,
+ scannerData.getClientRequestor() );
}
catch (ContextException e1)
{
@@ -929,7 +933,12 @@
storageBuffer.append( buff.toString() );
try
{
- scannerData.getContextStack().updateContext( new StringReader( storageBuffer.toString()), PASTING, IScannerContext.ContextKind.MACROEXPANSION, null, scannerData.getClientRequestor() );
+ scannerData.getContextStack().updateContext(
+ new StringReader( storageBuffer.toString()),
+ PASTING,
+ IScannerContext.ContextKind.MACROEXPANSION,
+ null,
+ scannerData.getClientRequestor() );
}
catch (ContextException e)
{
@@ -1015,9 +1024,7 @@
if ( next != null &&
(next.getType() == IToken.tSTRING ||
next.getType() == IToken.tLSTRING )) {
- StringBuffer buffer = new StringBuffer( returnToken.getImage() );
- buffer.append( next.getImage() );
- returnToken.setImage( buffer.toString() );
+ buff.append( next.getImage() );
}
else
cachedToken = next;
@@ -1025,6 +1032,8 @@
next = null;
}
+ returnToken.setImage(buff.toString());
+
currentToken = returnToken;
returnToken.setNext( null );
return returnToken;
@@ -1175,9 +1184,6 @@
int c;
int beginningOffset = scannerData.getContextStack().getCurrentContext().getOffset() - 1;
int beginningLine = scannerData.getContextStack().getCurrentLineNumber();
- // lets prepare for a preprocessor statement
- StringBuffer buff = new StringBuffer();
- buff.append('#');
// we are allowed arbitrary whitespace after the '#' and before the rest of the text
boolean skipped = skipOverWhitespace();
@@ -1195,6 +1201,8 @@
return newConstantToken( tPOUND ); //$NON-NLS-1$
}
+ StringBuffer buff = new StringBuffer();
+ buff.append('#');
while (((c >= 'a') && (c <= 'z'))
|| ((c >= 'A') && (c <= 'Z')) || (c == '_') ) {
buff.append((char) c);
@@ -1250,7 +1258,6 @@
handleInvalidCompletion();
return null;
}
- skipOverWhitespace();
removeSymbol(getNextIdentifier());
skipOverTextUntilNewline();
return null;
@@ -1278,7 +1285,6 @@
case PreprocessorDirectives.IFDEF :
//TODO add in content assist stuff here
- skipOverWhitespace();
String definition = getNextIdentifier();
if( isLimitReached() )
@@ -1318,8 +1324,7 @@
case PreprocessorDirectives.IFNDEF :
//TODO add in content assist stuff here
- skipOverWhitespace();
-
+
String definition2 = getNextIdentifier();
if( isLimitReached() )
handleCompletionOnDefinition( definition2 );
@@ -1549,18 +1554,14 @@
IMacroDescriptor mapping = getDefinition(ident);
- if (mapping != null) {
- StringBuffer buffer = new StringBuffer(POUND_DEFINE);
- buffer.append( ident );
- if( scannerData.getContextStack().shouldExpandDefinition( buffer.toString() ) ) {
+ if (mapping != null)
+ if( scannerData.getContextStack().shouldExpandDefinition( ident ) ) {
expandDefinition(ident, mapping, baseOffset);
return null;
}
- }
- if( pasting && pasteIntoInputStream(buff)){
+ if( pasting && pasteIntoInputStream(buff))
return null;
- }
Object tokenTypeObject;
if( scannerData.getLanguage() == ParserLanguage.CPP )
@@ -2033,7 +2034,16 @@
if( ! expression.trim().equals("")) //$NON-NLS-1$
{
- IScanner subScanner = new Scanner( new StringReader(expression), SCRATCH, EMPTY_MAP, EMPTY_LIST, NULL_REQUESTOR, ParserMode.QUICK_PARSE, scannerData.getLanguage(), NULL_LOG_SERVICE, scannerExtension );
+ IScanner subScanner = new Scanner(
+ new StringReader(expression),
+ SCRATCH,
+ EMPTY_MAP,
+ EMPTY_LIST,
+ NULL_REQUESTOR,
+ ParserMode.QUICK_PARSE,
+ scannerData.getLanguage(),
+ NULL_LOG_SERVICE,
+ scannerExtension );
IToken lastToken = null;
while( true )
{
@@ -2461,14 +2471,11 @@
protected void skipOverSinglelineComment() throws ScannerException, EndOfFileException {
-
- StringBuffer comment = new StringBuffer("//"); //$NON-NLS-1$
int c;
loop:
for (;;) {
c = getChar();
- comment.append((char)c);
switch (c) {
case NOCHAR :
case '\n' :
@@ -2485,14 +2492,12 @@
protected boolean skipOverMultilineComment() throws ScannerException, EndOfFileException {
int state = 0;
boolean encounteredNewline = false;
- StringBuffer comment = new StringBuffer("/*"); //$NON-NLS-1$
// simple state machine to handle multi-line comments
// state 0 == no end of comment in site
// state 1 == encountered *, expecting /
// state 2 == we are no longer in a comment
int c = getChar();
- comment.append((char)c);
while (state != 2 && c != NOCHAR) {
if (c == '\n')
encounteredNewline = true;
@@ -2510,7 +2515,6 @@
break;
}
c = getChar();
- comment.append((char)c);
}
if (c == NOCHAR && !isLimitReached() )
@@ -2524,14 +2528,12 @@
}
protected void poundInclude( int beginningOffset, int startLine ) throws ScannerException, EndOfFileException {
- StringBuffer potentialErrorLine = new StringBuffer( "#include "); //$NON-NLS-1$
skipOverWhitespace();
int baseOffset = lastContext.getOffset() - lastContext.undoStackSize();
int nameLine = scannerData.getContextStack().getCurrentLineNumber();
String includeLine = getRestOfPreprocessorLine();
int endLine = scannerData.getContextStack().getCurrentLineNumber();
- potentialErrorLine.append( includeLine );
-
+
ScannerUtility.InclusionDirective directive = null;
try
{
@@ -2539,6 +2541,8 @@
}
catch( ScannerUtility.InclusionParseException ipe )
{
+ StringBuffer potentialErrorLine = new StringBuffer( "#include "); //$NON-NLS-1$
+ potentialErrorLine.append( includeLine );
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, potentialErrorLine.toString(), beginningOffset, false, true );
return;
}
@@ -2673,39 +2677,23 @@
}
protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) {
- StringBuffer signatureBuffer = new StringBuffer();
- signatureBuffer.append( key );
- signatureBuffer.append( ' ' );
- signatureBuffer.append( value );
-
-// List macroReplacementTokens;
-// if (value.trim().equals( "" ))
-// macroReplacementTokens = new ArrayList();
-// else
-// macroReplacementTokens = tokenizeReplacementString( NO_OFFSET_LIMIT, key, value, null );
-
- List macroReplacementTokens = new ArrayList();
+ Token t = null;
if( !value.trim().equals( "" ) ) //$NON-NLS-1$
{
-
- Token t = new Token(
+ t = new Token(
IToken.tIDENTIFIER,
value,
scannerData.getContextStack().getCurrentContext(),
scannerData.getContextStack().getCurrentLineNumber()
);
- macroReplacementTokens.add( t );
}
- return new ObjectMacroDescriptor( key,
- signatureBuffer.toString(),
- macroReplacementTokens,
+ return new ObjectMacroDescriptor( key,
+ t,
value);
}
protected void poundDefine(int beginning, int beginningLine ) throws ScannerException, EndOfFileException {
- StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
- skipOverWhitespace();
// definition
String key = getNextIdentifier();
int offset = scannerData.getContextStack().getCurrentContext().getOffset() - key.length() - scannerData.getContextStack().getCurrentContext().undoStackSize();
@@ -2732,6 +2720,7 @@
c = getChar();
continue;
} else {
+ StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
ungetChar( c );
potentialErrorMessage.append( buffer );
potentialErrorMessage.append( '\\');
@@ -2740,6 +2729,7 @@
return;
}
} else if( c == '\r' || c == '\n' ){
+ StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
potentialErrorMessage.append( buffer );
potentialErrorMessage.append( '\\');
potentialErrorMessage.append( (char)c );
@@ -2768,23 +2758,16 @@
List macroReplacementTokens = null;
String replacementString = getRestOfPreprocessorLine();
-
+ // TODO: This tokenization could be done live, instead of using a sub-scanner.
macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$
tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) :
EMPTY_LIST;
- StringBuffer fullSignature = new StringBuffer( POUND_DEFINE);
- fullSignature.append( key );
- fullSignature.append( '(');
- fullSignature.append( parameters );
- fullSignature.append( ") "); //$NON-NLS-1$
- fullSignature.append( replacementString );
descriptor = new FunctionMacroDescriptor(
key,
parameterIdentifiers,
macroReplacementTokens,
- fullSignature.toString(),
replacementString);
checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning);
@@ -2835,6 +2818,7 @@
} else {
// this is not a comment
// it is a bad statement
+ StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
potentialErrorMessage.append( key );
potentialErrorMessage.append( " /"); //$NON-NLS-1$
potentialErrorMessage.append( getRestOfPreprocessorLine() );
@@ -2842,8 +2826,7 @@
return;
}
} else {
- potentialErrorMessage = new StringBuffer();
- potentialErrorMessage.append( "#define"); //$NON-NLS-1$
+ StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
potentialErrorMessage.append( key );
potentialErrorMessage.append( (char)c );
potentialErrorMessage.append( getRestOfPreprocessorLine() );
@@ -2886,7 +2869,17 @@
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
- Scanner tokenizer = new Scanner(new StringReader(params), TEXT, scannerData.getDefinitions(), scannerData.getIncludePathNames(), NULL_REQUESTOR, scannerData.getParserMode(), scannerData.getLanguage(), NULL_LOG_SERVICE, (IScannerExtension)scannerExtension.clone() );
+ Scanner tokenizer = new Scanner(
+ new StringReader(params),
+ TEXT,
+ scannerData.getDefinitions(),
+ scannerData.getIncludePathNames(),
+ NULL_REQUESTOR,
+ scannerData.getParserMode(),
+ scannerData.getLanguage(),
+ NULL_LOG_SERVICE,
+ (IScannerExtension)scannerExtension.clone() );
+
tokenizer.setThrowExceptionOnBadCharacterRead(false);
Vector parameterValues = new Vector();
Token t = null;
@@ -2951,15 +2944,8 @@
protected void expandDefinition(String symbol, String expansion, int symbolOffset ) throws ScannerException
{
- StringBuffer fullSignatureBuffer = new StringBuffer();
- fullSignatureBuffer.append( symbol );
- fullSignatureBuffer.append( ' ');
- fullSignatureBuffer.append( expansion );
- List tokens = tokenizeReplacementString(NO_OFFSET_LIMIT, symbol, expansion, null );
expandDefinition( symbol,
- new ObjectMacroDescriptor( symbol,
- fullSignatureBuffer.toString(),
- tokens,
+ new ObjectMacroDescriptor( symbol,
expansion ),
symbolOffset);
}
@@ -2973,9 +2959,13 @@
String replacementValue = expansion.getExpansionSignature();
try
{
- StringBuffer buffer = new StringBuffer( POUND_DEFINE );
- buffer.append( symbol );
- scannerData.getContextStack().updateContext( new StringReader(replacementValue), buffer.toString(), ScannerContext.ContextKind.MACROEXPANSION, null, scannerData.getClientRequestor(), symbolOffset, symbol.length());
+ scannerData.getContextStack().updateContext(
+ new StringReader(replacementValue),
+ symbol, ScannerContext.ContextKind.MACROEXPANSION,
+ null,
+ scannerData.getClientRequestor(),
+ symbolOffset,
+ symbol.length());
}
catch (ContextException e)
{
@@ -3118,11 +3108,14 @@
String finalString = buffer.toString();
try
{
- StringBuffer completeSignature = new StringBuffer( POUND_DEFINE );
- completeSignature.append( expansion.getCompleteSignature() );
scannerData.getContextStack().updateContext(
new StringReader(finalString),
- completeSignature.toString(), ScannerContext.ContextKind.MACROEXPANSION, null, scannerData.getClientRequestor(), symbolOffset, endMacroOffset - symbolOffset + 1 );
+ expansion.getName(),
+ ScannerContext.ContextKind.MACROEXPANSION,
+ null,
+ scannerData.getClientRequestor(),
+ symbolOffset,
+ endMacroOffset - symbolOffset + 1 );
}
catch (ContextException e)
{
@@ -3139,7 +3132,7 @@
}
else {
- TraceUtil.outputTrace(scannerData.getLogService(), "Unexpected type of MacroDescriptor stored in definitions table: ", null, expansion.getMacroType().toString(), null, null);
+ TraceUtil.outputTrace(scannerData.getLogService(), "Unexpected type of MacroDescriptor stored in definitions table: ", null, expansion.getMacroType().toString(), null, null); //$NON-NLS-1$
}
}
Index: parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java,v
retrieving revision 1.1
diff -u -r1.1 TraceUtil.java
--- parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java 5 Apr 2004 18:18:57 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/util/TraceUtil.java 6 Apr 2004 20:27:21 -0000
@@ -19,42 +19,34 @@
*/
public class TraceUtil {
public static void outputTrace(IParserLogService log, String preface, IProblem problem, String first, String second, String third ) {
- if( log.isTracing() ){
+ if( log.isTracing() ) {
StringBuffer buffer = new StringBuffer();
- buffer.append( preface != null ? preface : "" );
- buffer.append( problem != null ? problem.getMessage() : "" );
- buffer.append( first != null ? first : "" );
- buffer.append( second != null ? second : "" );
- buffer.append( third != null ? third : "" );
+ 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() ){
- StringBuffer buffer = new StringBuffer();
- buffer.append( preface != null ? preface : "" );
- buffer.append( problem != null ? problem.getMessage() : "" );
- buffer.append( Integer.toString( first ) );
- buffer.append( second != null ? second : "" );
- buffer.append( Integer.toString( third ) );
- log.traceLog( buffer.toString() );
- }
+ if( log.isTracing() ) {
+ outputTrace(
+ log,
+ preface,
+ problem,
+ Integer.toString( first ),
+ second,
+ Integer.toString( third ) );
+ }
}
public static void outputTrace(IParserLogService log, String preface, String first, String second, String third ) {
- if( log.isTracing() ){
- StringBuffer buffer = new StringBuffer();
- buffer.append( preface != null ? preface : "" );
- buffer.append( first != null ? first : "" );
- buffer.append( second != null ? second : "" );
- buffer.append( third != null ? third : "" );
- log.traceLog( buffer.toString() );
- }
+ outputTrace(log, preface, null, first, second, third);
}
public static void outputTrace(IParserLogService log, String preface) {
if( log.isTracing() ){
- StringBuffer buffer = new StringBuffer();
- buffer.append( preface != null ? preface : "" );
- log.traceLog( buffer.toString() );
+ if ( preface != null )
+ log.traceLog( preface );
}
}
}