mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 15:05:36 +02:00
Patch for David Daoust.
Removed some temporary objects that the scanner was producing. Fixed small bug in GCCScannerExtension these changes brought to the surface.
This commit is contained in:
parent
c366011c66
commit
0662f31cee
11 changed files with 154 additions and 148 deletions
|
@ -1,3 +1,7 @@
|
|||
2004-04-06 David Daoust
|
||||
Removed some temporary objects that the scanner was producing.
|
||||
Fixed small bug in GCCScannerExtension.
|
||||
|
||||
2004-04-06 Andrew Niefer
|
||||
Small changes to help with template parsing
|
||||
- report line numbers with some problems
|
||||
|
|
|
@ -2470,7 +2470,7 @@ public class ExpressionParser implements IExpressionParser {
|
|||
}
|
||||
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();
|
||||
|
|
|
@ -2149,7 +2149,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
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;
|
||||
|
|
|
@ -42,15 +42,15 @@ public class SelectionParser extends ContextualParser {
|
|||
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() )
|
||||
|
|
|
@ -793,7 +793,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
{
|
||||
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
{
|
||||
TraceUtil.outputTrace(
|
||||
logService,
|
||||
"Entering createExpression with Kind=",
|
||||
"Entering createExpression with Kind=", //$NON-NLS-1$
|
||||
null,
|
||||
kind.getKindName(),
|
||||
" literal=",
|
||||
" literal=", //$NON-NLS-1$
|
||||
literal
|
||||
);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public class ContextStack {
|
|||
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 @@ public class ContextStack {
|
|||
|
||||
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 )
|
||||
|
|
|
@ -27,19 +27,17 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
|
|||
* 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 class FunctionMacroDescriptor implements IMacroDescriptor {
|
|||
*/
|
||||
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)
|
||||
|
|
|
@ -18,12 +18,10 @@ import java.util.Set;
|
|||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException;
|
||||
import org.eclipse.cdt.internal.core.parser.token.Token;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +39,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
static
|
||||
{
|
||||
simpleIdentifiers = new ArrayList();
|
||||
simpleIdentifiers.add( new Token( IToken.tIDENTIFIER, "x")); //$NON-NLS-1
|
||||
simpleIdentifiers.add( "x" ); //$NON-NLS-1
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String)
|
||||
|
@ -59,12 +57,12 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
|
||||
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 +109,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
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 +156,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
}
|
||||
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -14,30 +14,29 @@ import java.util.ArrayList;
|
|||
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 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
|
|||
* @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 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
|
|||
* @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 class ObjectMacroDescriptor implements IMacroDescriptor {
|
|||
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)
|
||||
|
|
|
@ -98,7 +98,7 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
// 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 class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
next = null;
|
||||
}
|
||||
|
||||
returnToken.setImage(buff.toString());
|
||||
|
||||
currentToken = returnToken;
|
||||
returnToken.setNext( null );
|
||||
return returnToken;
|
||||
|
@ -1175,9 +1184,6 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
handleInvalidCompletion();
|
||||
return null;
|
||||
}
|
||||
skipOverWhitespace();
|
||||
removeSymbol(getNextIdentifier());
|
||||
skipOverTextUntilNewline();
|
||||
return null;
|
||||
|
@ -1278,7 +1285,6 @@ public class Scanner implements IScanner {
|
|||
|
||||
case PreprocessorDirectives.IFDEF :
|
||||
//TODO add in content assist stuff here
|
||||
skipOverWhitespace();
|
||||
|
||||
String definition = getNextIdentifier();
|
||||
if( isLimitReached() )
|
||||
|
@ -1318,8 +1324,7 @@ public class Scanner implements IScanner {
|
|||
|
||||
case PreprocessorDirectives.IFNDEF :
|
||||
//TODO add in content assist stuff here
|
||||
skipOverWhitespace();
|
||||
|
||||
|
||||
String definition2 = getNextIdentifier();
|
||||
if( isLimitReached() )
|
||||
handleCompletionOnDefinition( definition2 );
|
||||
|
@ -1549,18 +1554,14 @@ public class Scanner implements IScanner {
|
|||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
break;
|
||||
}
|
||||
c = getChar();
|
||||
comment.append((char)c);
|
||||
}
|
||||
|
||||
if (c == NOCHAR && !isLimitReached() )
|
||||
|
@ -2524,14 +2528,12 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
c = getChar();
|
||||
continue;
|
||||
} else {
|
||||
StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE );
|
||||
ungetChar( c );
|
||||
potentialErrorMessage.append( buffer );
|
||||
potentialErrorMessage.append( '\\');
|
||||
|
@ -2740,6 +2729,7 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
} 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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
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 @@ public class Scanner implements IScanner {
|
|||
|
||||
}
|
||||
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$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,42 +19,34 @@ import org.eclipse.cdt.core.parser.IProblem;
|
|||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue