1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

IASTNodeLocation support for #inclusions.

This commit is contained in:
John Camelon 2005-01-21 21:12:17 +00:00
parent 0f10569314
commit e22c304553
10 changed files with 836 additions and 504 deletions

View file

@ -16,13 +16,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.tests.CModelElementsTests; import org.eclipse.cdt.core.model.tests.CModelElementsTests;
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests; import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests; import org.eclipse.cdt.core.parser.tests.ast2.DOMParserTestSuite;
import org.eclipse.cdt.core.parser.tests.ast2.AST2KnRTests;
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
import org.eclipse.cdt.core.parser.tests.ast2.QuickParser2Tests;
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest; import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test; import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
@ -58,13 +52,7 @@ public class ParserTestSuite extends TestCase {
suite.addTest( IScannerInfoPluginTest.suite() ); suite.addTest( IScannerInfoPluginTest.suite() );
suite.addTest( ScannerParserLoopTest.suite() ); suite.addTest( ScannerParserLoopTest.suite() );
suite.addTest( GCCParserExtensionTestSuite.suite() ); suite.addTest( GCCParserExtensionTestSuite.suite() );
suite.addTestSuite( AST2Tests.class ); suite.addTest( DOMParserTestSuite.suite() );
suite.addTestSuite( GCCTests.class );
suite.addTestSuite( AST2CPPTests.class );
suite.addTestSuite( QuickParser2Tests.class );
suite.addTestSuite( CompleteParser2Tests.class );
suite.addTestSuite( DOMLocationTests.class );
suite.addTestSuite( AST2KnRTests.class );
return suite; return suite;
} }
} }

View file

@ -12,9 +12,17 @@ package org.eclipse.cdt.core.parser.tests.ast2;
import java.io.InputStream; import java.io.InputStream;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.CDOM; import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
@ -67,9 +75,11 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
language, NULL_LOG, getScannerConfig(language), factory); language, NULL_LOG, getScannerConfig(language), factory);
ISourceCodeParser parser = null; ISourceCodeParser parser = null;
if (language == ParserLanguage.CPP) { if (language == ParserLanguage.CPP) {
parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, new GPPParserExtensionConfiguration() ); parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE,
NULL_LOG, new GPPParserExtensionConfiguration());
} else { } else {
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, new GCCParserExtensionConfiguration() ); parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE,
NULL_LOG, new GCCParserExtensionConfiguration());
} }
stream.close(); stream.close();
IASTTranslationUnit parseResult = parser.parse(); IASTTranslationUnit parseResult = parser.parse();
@ -92,9 +102,79 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
* @param language * @param language
* @return * @return
*/ */
private IScannerExtensionConfiguration getScannerConfig(ParserLanguage language) { private IScannerExtensionConfiguration getScannerConfig(
ParserLanguage language) {
if (language == ParserLanguage.CPP) if (language == ParserLanguage.CPP)
return new GPPScannerExtensionConfiguration(); return new GPPScannerExtensionConfiguration();
return new GCCScannerExtensionConfiguration(); return new GCCScannerExtensionConfiguration();
} }
/**
* @param pathEndsWith
* TODO
* @param offset
* @param length
* @param declarator
*/
private void assertSoleFileLocation(IASTNode n, String pathEndsWith,
int offset, int length) {
IASTNodeLocation[] locations = n.getNodeLocations();
assertEquals(locations.length, 1);
IASTFileLocation nodeLocation = (IASTFileLocation) locations[0];
assertTrue(nodeLocation.getFileName().endsWith(pathEndsWith));
assertEquals(nodeLocation.getNodeOffset(), offset);
assertEquals(nodeLocation.getNodeLength(), length);
}
public void testSimpleInclusion() throws Exception {
String foo = "int FOO;"; //$NON-NLS-1$
String code = "int bar;\n#include \"foo.h\"\n"; //$NON-NLS-1$
importFile("foo.h", foo); //$NON-NLS-1$
IFile cpp = importFile("code.cpp", code); //$NON-NLS-1$
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
: null) {
IASTTranslationUnit tu = parse(cpp, p); //$NON-NLS-1$
IASTDeclaration[] declarations = tu.getDeclarations();
assertEquals(declarations.length, 2);
IASTSimpleDeclaration bar = (IASTSimpleDeclaration) declarations[0];
IASTSimpleDeclaration FOO = (IASTSimpleDeclaration) declarations[1];
assertSoleFileLocation(bar,
"code.cpp", code.indexOf("int"), code.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSoleFileLocation(FOO,
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
public void testSimpleInclusion2() throws Exception {
String foo = "int FOO;"; //$NON-NLS-1$
String code = "int bar;\n#include \"foo.h\"\nfloat byob;\n"; //$NON-NLS-1$
importFile("foo.h", foo); //$NON-NLS-1$
IFile cpp = importFile("code.cpp", code); //$NON-NLS-1$
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
: null) {
IASTTranslationUnit tu = parse(cpp, p); //$NON-NLS-1$
IASTDeclaration[] declarations = tu.getDeclarations();
assertEquals(declarations.length, 3);
IASTSimpleDeclaration bar = (IASTSimpleDeclaration) declarations[0];
IASTSimpleDeclaration FOO = (IASTSimpleDeclaration) declarations[1];
IASTSimpleDeclaration byob = (IASTSimpleDeclaration) declarations[2];
assertSoleFileLocation(bar,
"code.cpp", code.indexOf("int"), code.indexOf("r;") + 2 - code.indexOf( "int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation(FOO,
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1 - foo.indexOf( "int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation( byob, "code.cpp", code.indexOf( "float"), code.indexOf( "b;") + 2 - code.indexOf( "float") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
public static Test suite() {
TestSuite suite = new TestSuite(DOMLocationInclusionTests.class);
suite.addTest(new DOMLocationInclusionTests("cleanupProject")); //$NON-NLS-1$
return suite;
}
} }

View file

@ -0,0 +1,39 @@
/**********************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
/**
* @author jcamelon
*/
public class DOMParserTestSuite extends TestCase {
public static Test suite() {
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
suite.addTestSuite( AST2Tests.class );
suite.addTestSuite( GCCTests.class );
suite.addTestSuite( AST2CPPTests.class );
suite.addTestSuite( QuickParser2Tests.class );
suite.addTestSuite( CompleteParser2Tests.class );
// suite.addTestSuite( DOMScannerTests.class );
suite.addTestSuite( DOMLocationTests.class );
suite.addTest( DOMLocationInclusionTests.suite() );
suite.addTestSuite( AST2KnRTests.class );
return suite;
}
}

View file

@ -0,0 +1,34 @@
/**********************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
import junit.framework.TestCase;
/**
* @author jcamelon
*/
public class DOMScannerTests extends TestCase {
/**
*
*/
public DOMScannerTests() {
super();
}
/**
* @param name
*/
public DOMScannerTests(String name) {
super(name);
}
}

View file

@ -1278,26 +1278,11 @@ abstract class BaseScanner implements IScanner {
} }
pushContext(buffer); pushContext(buffer);
bufferData[bufferStackPos] = data; bufferData[bufferStackPos] = data;
if (data instanceof InclusionData)
pushInclusion(data);
} }
/**
* @param data
*/
protected void pushInclusion(Object data) {
if (log.isTracing()) {
StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$
b.append(((InclusionData) data).reader.filename);
log.traceLog(b.toString());
}
}
protected Object popContext() { protected Object popContext() {
bufferStack[bufferStackPos] = null; bufferStack[bufferStackPos] = null;
if (bufferData[bufferStackPos] instanceof InclusionData)
popInclusion(((InclusionData) bufferData[bufferStackPos]).inclusion);
Object result = bufferData[bufferStackPos]; Object result = bufferData[bufferStackPos];
bufferData[bufferStackPos] = null; bufferData[bufferStackPos] = null;
@ -1308,20 +1293,6 @@ abstract class BaseScanner implements IScanner {
return result; return result;
} }
/**
* @param data
* TODO
*
*/
protected void popInclusion(java.lang.Object data) {
if (log.isTracing()) {
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
buffer
.append(((InclusionData) bufferData[bufferStackPos]).reader.filename);
log.traceLog(buffer.toString());
}
}
/** /**
* *
*/ */
@ -1991,7 +1962,7 @@ abstract class BaseScanner implements IScanner {
pushContext(expText); pushContext(expText);
} }
if (expanding) if (expanding)
return new MacroExpansionToken(); return EXPANSION_TOKEN;
} }
char[] result = escapedNewline ? removedEscapedNewline(buffer, start, len) char[] result = escapedNewline ? removedEscapedNewline(buffer, start, len)
@ -2683,12 +2654,11 @@ abstract class BaseScanner implements IScanner {
fileCache.put(reader.filename, reader); fileCache.put(reader.filename, reader);
} }
if (reader != null) { if (reader != null) {
Object inclusion = createInclusionConstruct(fileNameArray, pushContext(reader.buffer, new InclusionData(reader,
createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset, reader.filename, local, startOffset,
startingLineNumber, nameOffset, nameEndOffset, startingLineNumber, nameOffset, nameEndOffset,
nameLine, endOffset, endLine, false); nameLine, endOffset, endLine, false)));
pushContext(reader.buffer, new InclusionData(reader,
inclusion));
return; return;
} }
} }
@ -4377,6 +4347,7 @@ abstract class BaseScanner implements IScanner {
protected static final char[] TAB = { '\t' }; protected static final char[] TAB = { '\t' };
protected static final char[] SPACE = { ' ' }; protected static final char[] SPACE = { ' ' };
private static final MacroExpansionToken EXPANSION_TOKEN = new MacroExpansionToken();
static { static {
CharArrayIntMap words = new CharArrayIntMap(IToken.tLAST, -1); CharArrayIntMap words = new CharArrayIntMap(IToken.tLAST, -1);

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
@ -36,8 +35,7 @@ public class DOMScanner extends BaseScanner {
private int globalCounter = 0; private int globalCounter = 0;
private int contextDelta = 0; private int contextDelta = 0;
private static class DOMInclusion private static class DOMInclusion {
{
public final char[] pt; public final char[] pt;
public final int o; public final int o;
@ -56,17 +54,23 @@ public class DOMScanner extends BaseScanner {
* @param parserMode * @param parserMode
* @param language * @param language
* @param log * @param log
* @param readerFactory TODO * @param readerFactory
* TODO
* @param requestor * @param requestor
*/ */
public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtensionConfiguration configuration, ICodeReaderFactory readerFactory) { public DOMScanner(CodeReader reader, IScannerInfo info,
ParserMode parserMode, ParserLanguage language, IParserLogService log,
IScannerExtensionConfiguration configuration,
ICodeReaderFactory readerFactory) {
super(reader, info, parserMode, language, log, configuration); super(reader, info, parserMode, language, log, configuration);
this.expressionEvaluator = new ExpressionEvaluator(null, null); this.expressionEvaluator = new ExpressionEvaluator(null, null);
this.codeReaderFactory = readerFactory; this.codeReaderFactory = readerFactory;
postConstructorSetup(reader, info); postConstructorSetup(reader, info);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver() * @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/ */
public ILocationResolver getLocationResolver() { public ILocationResolver getLocationResolver() {
@ -75,36 +79,51 @@ public class DOMScanner extends BaseScanner {
return null; return null;
} }
final IScannerPreprocessorLog locationMap = new LocationMap(); final IScannerPreprocessorLog locationMap = new LocationMap();
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory) * @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/ */
public void setASTFactory(IASTFactory f) { public void setASTFactory(IASTFactory f) {
// do nothing // do nothing
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createInclusionConstruct(char[], char[], boolean, int, int, int, int, int, int, int, boolean) * (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createInclusionConstruct(char[],
* char[], boolean, int, int, int, int, int, int, int, boolean)
*/ */
protected Object createInclusionConstruct(char[] fileName, char[] filenamePath, boolean local, int startOffset, int startingLineNumber, int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endLine, boolean isForced) { protected Object createInclusionConstruct(char[] fileName,
return new DOMInclusion( filenamePath, startOffset ); char[] filenamePath, boolean local, int startOffset,
int startingLineNumber, int nameOffset, int nameEndOffset,
int nameLine, int endOffset, int endLine, boolean isForced) {
return new DOMInclusion(filenamePath, resolveOffset(startOffset));
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processMacro(char[], int, int, int, int, int, int, int) * (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processMacro(char[],
* int, int, int, int, int, int, int)
*/ */
protected void processMacro(char[] name, int startingOffset, int startingLineNumber, int idstart, int idend, int nameLine, int textEnd, int endingLine, IMacro macro) { protected void processMacro(char[] name, int startingOffset,
int startingLineNumber, int idstart, int idend, int nameLine,
int textEnd, int endingLine, IMacro macro) {
if (macro instanceof ObjectStyleMacro) if (macro instanceof ObjectStyleMacro)
locationMap.defineObjectStyleMacro( (ObjectStyleMacro) macro, startingLineNumber, idstart, idend, textEnd ); locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
startingLineNumber, idstart, idend, textEnd);
else if (macro instanceof FunctionStyleMacro) else if (macro instanceof FunctionStyleMacro)
locationMap.defineFunctionStyleMacro( (FunctionStyleMacro) macro, startingLineNumber, idstart, idend, textEnd ); locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
startingLineNumber, idstart, idend, textEnd);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String) * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/ */
protected CodeReader createReaderDuple(String finalPath) { protected CodeReader createReaderDuple(String finalPath) {
@ -112,107 +131,119 @@ public class DOMScanner extends BaseScanner {
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[]) * (non-Javadoc)
*/ *
protected void pushContext(char[] buffer) { * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
//TODO calibrate offsets * java.lang.Object)
super.pushContext(buffer);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[], java.lang.Object)
*/ */
protected void pushContext(char[] buffer, Object data) { protected void pushContext(char[] buffer, Object data) {
//TODO calibrate offsets if (data instanceof InclusionData) {
if (log.isTracing()) {
StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$
b.append(((InclusionData) data).reader.filename);
log.traceLog(b.toString());
}
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
globalCounter += getCurrentOffset();
locationMap.startInclusion(inc.pt, inc.o, globalCounter);
contextDelta = 0;
}
super.pushContext(buffer, data); super.pushContext(buffer, data);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext() * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/ */
protected Object popContext() { protected Object popContext() {
//TODO calibrate offsets //TODO calibrate offsets
Object result = super.popContext(); Object result = super.popContext();
if( result instanceof CodeReader ) if (result instanceof CodeReader) {
{
globalCounter += (((CodeReader) result).buffer.length - contextDelta); globalCounter += (((CodeReader) result).buffer.length - contextDelta);
locationMap.endTranslationUnit(globalCounter); locationMap.endTranslationUnit(globalCounter);
} }
if (result instanceof InclusionData) {
if (log.isTracing()) {
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
buffer
.append(((InclusionData) bufferData[bufferStackPos]).reader.filename);
log.traceLog(buffer.toString());
}
globalCounter += (((InclusionData) result).reader.buffer.length - contextDelta);
contextDelta = getCurrentOffset();
locationMap.endInclusion(globalCounter);
}
return result; return result;
} }
/** /**
* @return * @return
*/ */
protected IToken newToken(int signal) { protected IToken newToken(int signal) {
if( bufferData[bufferStackPos] instanceof MacroData ) if (bufferData[bufferStackPos] instanceof MacroData) {
{
int mostRelevant; int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant) for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader ) if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break; break;
MacroData data = (MacroData) bufferData[mostRelevant + 1]; MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new SimpleExpansionToken( signal, resolveOffset( data.startOffset ), data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1)); return new SimpleExpansionToken(signal,
resolveOffset(data.startOffset), data.endOffset
- data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
} }
return new SimpleToken(signal, resolveOffset( bufferPos[bufferStackPos] + 1 ) , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1) ); return new SimpleToken(signal,
resolveOffset(bufferPos[bufferStackPos] + 1), getCurrentFilename(),
getLineNumber(bufferPos[bufferStackPos] + 1));
} }
protected IToken newToken( int signal, char [] buffer ) protected IToken newToken(int signal, char[] buffer) {
{ if (bufferData[bufferStackPos] instanceof MacroData) {
if( bufferData[bufferStackPos] instanceof MacroData )
{
int mostRelevant; int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant) for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader ) if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break; break;
MacroData data = (MacroData) bufferData[mostRelevant + 1]; MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new ImagedExpansionToken( signal, buffer, resolveOffset( data.startOffset ), data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1)); return new ImagedExpansionToken(signal, buffer,
resolveOffset(data.startOffset), data.endOffset
- data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
} }
IToken i = new ImagedToken(signal, buffer, resolveOffset( bufferPos[bufferStackPos] + 1 ), EMPTY_CHAR_ARRAY, getLineNumber( bufferPos[bufferStackPos] + 1)); IToken i = new ImagedToken(signal, buffer,
if( buffer != null && buffer.length == 0 && signal != IToken.tSTRING && signal != IToken.tLSTRING ) resolveOffset(bufferPos[bufferStackPos] + 1), EMPTY_CHAR_ARRAY,
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some point getLineNumber(bufferPos[bufferStackPos] + 1));
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
&& signal != IToken.tLSTRING)
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some
// point
return i; return i;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object) * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/ */
protected void quickParsePushPopInclusion(Object inclusion) { protected void quickParsePushPopInclusion(Object inclusion) {
//do nothing //do nothing
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushInclusion(java.lang.Object) * (non-Javadoc)
*/ *
protected void pushInclusion(Object data) { * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
super.pushInclusion(data); * int, char[])
if( data instanceof DOMInclusion )
{
DOMInclusion d = (DOMInclusion)data;
locationMap.startInclusion( d.pt, d.o );
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popInclusion()
*/
protected void popInclusion(Object data) {
super.popInclusion(data);
if( data instanceof DOMInclusion )
{
DOMInclusion d = (DOMInclusion)data;
locationMap.endInclusion( d.pt, d.o );
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[])
*/ */
protected void handleProblem(int id, int offset, char[] arg) { protected void handleProblem(int id, int offset, char[] arg) {
IASTProblem problem = new ScannerASTProblem(id, arg, true, false); IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
int o = resolveOffset(offset); int o = resolveOffset(offset);
((ScannerASTProblem)problem).setOffsetAndLength( o, resolveOffset( getCurrentOffset() + 1 ) - o ); ((ScannerASTProblem) problem).setOffsetAndLength(o,
resolveOffset(getCurrentOffset() + 1) - o);
locationMap.encounterProblem(problem); locationMap.encounterProblem(problem);
} }
@ -224,16 +255,20 @@ public class DOMScanner extends BaseScanner {
return globalCounter - contextDelta + offset; return globalCounter - contextDelta + offset;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo) *
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader,
* org.eclipse.cdt.core.parser.IScannerInfo)
*/ */
protected void postConstructorSetup(CodeReader reader, IScannerInfo info) { protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
super.postConstructorSetup(reader, info); super.postConstructorSetup(reader, info);
locationMap.startTranslationUnit(getMainFilename()); locationMap.startTranslationUnit(getMainFilename());
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#throwEOF() * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#throwEOF()
*/ */
protected void throwEOF() throws EndOfFileException { protected void throwEOF() throws EndOfFileException {

View file

@ -31,7 +31,6 @@ public interface ILocationResolver {
public IASTProblem[] getScannerProblems(); public IASTProblem[] getScannerProblems();
public String getTranslationUnitPath(); public String getTranslationUnitPath();
public String [] getInclusionsPaths();
public void cleanup(); public void cleanup();

View file

@ -20,40 +20,29 @@ public interface IScannerPreprocessorLog {
public void startTranslationUnit( char [] filename ); public void startTranslationUnit( char [] filename );
public void endTranslationUnit(int offset); public void endTranslationUnit(int offset);
public void startInclusion(char[] includePath, int offset); public void startInclusion(char[] includePath, int offset, int endOffset);
public void endInclusion(int offset);
public void endInclusion(char[] includePath, int offset);
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion, public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
int offset); int offset);
public void exitObjectStyleMacroExpansion(char[] name, int offset); public void exitObjectStyleMacroExpansion(char[] name, int offset);
public void enterFunctionStyleExpansion(char[] name, char[][] parameters, public void enterFunctionStyleExpansion(char[] name, char[][] parameters,
char[] expansion, int offset); char[] expansion, int offset);
public void exitFunctionStyleExpansion(char[] name, int offset); public void exitFunctionStyleExpansion(char[] name, int offset);
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset, public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset); int nameOffset, int nameEndOffset, int endOffset);
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset, public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset); int nameOffset, int nameEndOffset, int endOffset);
public void encounterPoundIf(int startOffset, int endOffset); public void encounterPoundIf(int startOffset, int endOffset);
public void encounterPoundPragma(int startOffset, int endOffset); public void encounterPoundPragma(int startOffset, int endOffset);
public void encounterPoundError(int startOffset, int endOffset); public void encounterPoundError(int startOffset, int endOffset);
public void encounterPoundIfdef(int startOffset, int endOffset); public void encounterPoundIfdef(int startOffset, int endOffset);
public void encounterPoundUndef(int startOffset, int endOffset); public void encounterPoundUndef(int startOffset, int endOffset);
public void encounterPoundElse(int startOffset, int endOffset); public void encounterPoundElse(int startOffset, int endOffset);
public void encounterPoundElif(int startOffset, int endOffset); public void encounterPoundElif(int startOffset, int endOffset);
public void encounterPoundEndIf(int startOffset, int endOffset); public void encounterPoundEndIf(int startOffset, int endOffset);
public void encounterProblem( IASTProblem problem ); public void encounterProblem( IASTProblem problem );

View file

@ -27,8 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
*/ */
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public static class Location implements IASTNodeLocation public static class Location implements IASTNodeLocation {
{
private final int nodeOffset; private final int nodeOffset;
private final int nodeLength; private final int nodeLength;
@ -41,28 +40,31 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
nodeLength = length; nodeLength = length;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeOffset() * @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeOffset()
*/ */
public int getNodeOffset() { public int getNodeOffset() {
return nodeOffset; return nodeOffset;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeLength() * @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeLength()
*/ */
public int getNodeLength() { public int getNodeLength() {
return nodeLength; return nodeLength;
} }
} }
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class FileLocation extends Location implements IASTFileLocation { public static class FileLocation extends Location implements
IASTFileLocation {
private String fileName; private String fileName;
@ -77,7 +79,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
fileName = new String(tu_filename); fileName = new String(tu_filename);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTFileLocation#getFileName() * @see org.eclipse.cdt.core.dom.ast.IASTFileLocation#getFileName()
*/ */
public String getFileName() { public String getFileName() {
@ -85,17 +89,102 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
} }
private static final char [] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
private List problems = Collections.EMPTY_LIST;
private List inclusions = Collections.EMPTY_LIST;
private List macroExpansions = Collections.EMPTY_LIST;
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0]; private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0]; private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
public static class Context {
/**
* @param startOffset
* @param endOffset
*/
public Context(CompositeContext parent, int startOffset, int endOffset) {
this.context_directive_start = startOffset;
this.context_directive_end = endOffset;
this.parent = parent;
}
private char[] tu_filename = EMPTY_CHAR_ARRAY ; public final int context_directive_start;
private static final String[] EMPTY_STRING_ARRAY = new String[0]; public final int context_directive_end;
private int finalOffset = 0; public int context_ends = -1;
private final CompositeContext parent;
public CompositeContext getParent() {
return parent;
}
}
public static class CompositeContext extends Context {
public CompositeContext(CompositeContext parent, int startOffset,
int endOffset) {
super(parent, startOffset, endOffset);
}
private static final int DEFAULT_SUBCONTEXT_ARRAY_SIZE = 8;
protected List subContexts = Collections.EMPTY_LIST;
public List getSubContexts() {
return subContexts;
}
public void addSubContext(Context c) {
if (subContexts == Collections.EMPTY_LIST)
subContexts = new ArrayList(DEFAULT_SUBCONTEXT_ARRAY_SIZE);
subContexts.add(c);
}
/**
* @return
*/
public boolean hasSubContexts() {
return subContexts != Collections.EMPTY_LIST;
}
}
public static class Inclusion extends CompositeContext {
public final char[] path;
public Inclusion(CompositeContext parent, char[] path, int startOffset,
int endOffset) {
super(parent, startOffset, endOffset);
this.path = path;
}
}
public static class TranslationUnit extends CompositeContext {
public final char[] path;
/**
* @param startOffset
* @param endOffset
*/
public TranslationUnit(char[] path) {
super(null, 0, 0);
this.path = path;
}
}
public static class Problem extends Context {
public final IASTProblem problem;
/**
* @param parent
* @param startOffset
* @param endOffset
*/
public Problem(CompositeContext parent, int startOffset, int endOffset,
IASTProblem problem) {
super(parent, startOffset, endOffset);
this.problem = problem;
}
}
protected TranslationUnit tu;
protected CompositeContext currentContext;
/** /**
* *
@ -142,17 +231,98 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int) * int)
*/ */
public IASTNodeLocation[] getLocations(int offset, int length) { public IASTNodeLocation[] getLocations(int offset, int length) {
if( tu_filename == EMPTY_CHAR_ARRAY ) return EMPTY_LOCATION_ARRAY; if (tu == null)
if( macroExpansions.isEmpty() && inclusions.isEmpty() ) return EMPTY_LOCATION_ARRAY;
{ Context c = findContextForOffset(offset);
if( offset + length > finalOffset ) return EMPTY_LOCATION_ARRAY; if (c.context_ends >= offset + length)
return createSoleLocation(c, offset, length);
return EMPTY_LOCATION_ARRAY;
}
/**
* @param c
* @param offset
* @param length
* @return
*/
protected IASTNodeLocation[] createSoleLocation(Context c, int offset,
int length) {
IASTNodeLocation[] result = new IASTNodeLocation[1]; IASTNodeLocation[] result = new IASTNodeLocation[1];
result[0] = new FileLocation( tu_filename, offset, length ); if (c instanceof TranslationUnit) {
result[0] = new FileLocation(((TranslationUnit) c).path, reconcileOffset( c, offset ),
length);
return result;
}
if( c instanceof Inclusion )
{
result[0] = new FileLocation(((Inclusion) c).path, reconcileOffset( c, offset ),
length);
return result; return result;
} }
return EMPTY_LOCATION_ARRAY; return EMPTY_LOCATION_ARRAY;
} }
/**
* @param c
* @param offset
* @return
*/
protected static int reconcileOffset(Context c, int offset) {
int subtractOff = 0;
if( c instanceof CompositeContext )
{
List subs = ((CompositeContext)c).getSubContexts();
for( int i = 0; i < subs.size(); ++i )
{
Context subC = (Context) subs.get(i);
if( subC.context_ends < offset )
subtractOff += subC.context_ends - subC.context_directive_end;
else
break;
}
}
return offset - c.context_directive_end - subtractOff;
}
/**
* @param offset
* @return
*/
protected Context findContextForOffset(int offset) {
return findContextForOffset(tu, offset);
}
protected static Context findContextForOffset(CompositeContext context,
int offset) {
if (!context.hasSubContexts() )
{
if( context.context_ends >= offset)
return context;
return null;
}
List subContexts = context.getSubContexts();
//check first
Context bestContext = (Context) subContexts.get(0);
if (bestContext.context_directive_end > offset)
return context;
for (int i = 1; i < subContexts.size(); ++i) {
Context nextContext = (Context) subContexts.get(i);
if (nextContext.context_directive_end < offset)
bestContext = nextContext;
else
break;
}
if ( bestContext.context_ends < offset )
return context;
if (bestContext instanceof CompositeContext)
return findContextForOffset((CompositeContext) bestContext, offset);
return bestContext;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -169,7 +339,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit() * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
*/ */
public void startTranslationUnit(char[] filename) { public void startTranslationUnit(char[] filename) {
this.tu_filename = filename; tu = new TranslationUnit(filename);
currentContext = tu;
} }
/* /*
@ -178,7 +349,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int)
*/ */
public void endTranslationUnit(int offset) { public void endTranslationUnit(int offset) {
this.finalOffset = offset; tu.context_ends = offset;
} }
/* /*
@ -187,8 +358,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[], * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[],
* int) * int)
*/ */
public void startInclusion(char[] includePath, int offset) { public void startInclusion(char[] includePath, int offset, int endOffset) {
inclusions.add( new String( includePath )); Inclusion i = new Inclusion(currentContext, includePath, offset,
endOffset);
currentContext.addSubContext(i);
currentContext = i;
} }
/* /*
@ -197,9 +371,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endInclusion(char[], * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endInclusion(char[],
* int) * int)
*/ */
public void endInclusion(char[] includePath, int offset) { public void endInclusion(int offset) {
// TODO Auto-generated method stub ((Inclusion) currentContext).context_ends = offset;
currentContext = currentContext.getParent();
} }
/* /*
@ -366,20 +540,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath() * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath()
*/ */
public String getTranslationUnitPath() { public String getTranslationUnitPath() {
if( tu_filename == EMPTY_CHAR_ARRAY ) return ""; //$NON-NLS-1$ return new String(tu.path);
return new String( tu_filename );
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getInclusionsPaths()
*/
public String[] getInclusionsPaths() {
if (inclusions == Collections.EMPTY_LIST)
return EMPTY_STRING_ARRAY;
return (String[]) inclusions.toArray(new String[inclusions.size()]); }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -395,9 +558,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems() * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems()
*/ */
public IASTProblem[] getScannerProblems() { public IASTProblem[] getScannerProblems() {
if (problems == Collections.EMPTY_LIST) List contexts = new ArrayList(8);
LocationMap.collectContexts(V_PROBLEMS, tu, contexts);
if (contexts.isEmpty())
return EMPTY_PROBLEMS_ARRAY; return EMPTY_PROBLEMS_ARRAY;
return (IASTProblem[]) problems.toArray(new IASTProblem[problems.size()]); IASTProblem[] result = new IASTProblem[contexts.size()];
for (int i = 0; i < contexts.size(); ++i)
result[i] = ((Problem) contexts.get(i)).problem;
return result;
} }
/* /*
@ -406,9 +575,35 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterIProblem(org.eclipse.cdt.core.parser.IProblem) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterIProblem(org.eclipse.cdt.core.parser.IProblem)
*/ */
public void encounterProblem(IASTProblem problem) { public void encounterProblem(IASTProblem problem) {
if (problems == Collections.EMPTY_LIST) ScannerASTProblem p = (ScannerASTProblem) problem;
problems = new ArrayList(4); Problem pr = new Problem(currentContext, p.getOffset(), p.getOffset()
problems.add(problem); + p.getLength(), problem);
pr.context_ends = p.getOffset() + p.getLength();
}
protected static final int V_ALL = 1;
protected static final int V_INCLUSIONS = 2;
protected static final int V_PROBLEMS = 3;
protected static void collectContexts(int key, Context source, List result) {
switch (key) {
case V_ALL:
result.add(source);
break;
case V_INCLUSIONS:
if (source instanceof Inclusion)
result.add(source);
break;
case V_PROBLEMS:
if (source instanceof Problem)
result.add(source);
break;
}
if (source instanceof CompositeContext) {
List l = ((CompositeContext) source).getSubContexts();
for (int i = 0; i < l.size(); ++i)
collectContexts(key, (Context) l.get(i), result);
}
} }
} }

View file

@ -103,8 +103,7 @@ public class Scanner2 extends BaseScanner {
*/ */
protected void processMacro(char[] name, int startingOffset, protected void processMacro(char[] name, int startingOffset,
int startingLineNumber, int idstart, int idend, int nameLine, int startingLineNumber, int idstart, int idend, int nameLine,
int textEnd, int endingLine, int textEnd, int endingLine, org.eclipse.cdt.core.parser.IMacro macro) {
org.eclipse.cdt.core.parser.IMacro macro) {
callbackManager.pushCallback(getASTFactory().createMacro(name, callbackManager.pushCallback(getASTFactory().createMacro(name,
startingOffset, startingLineNumber, idstart, idend, nameLine, startingOffset, startingLineNumber, idstart, idend, nameLine,
textEnd, endingLine, getCurrentFilename(), !isInitialized)); textEnd, endingLine, getCurrentFilename(), !isInitialized));
@ -113,22 +112,19 @@ public class Scanner2 extends BaseScanner {
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushInclusion(java.lang.Object) * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
* java.lang.Object)
*/ */
protected void pushInclusion(Object data) { protected void pushContext(char[] buffer, Object data) {
super.pushContext(buffer, data);
if (data instanceof InclusionData) {
callbackManager.pushCallback(data); callbackManager.pushCallback(data);
super.pushInclusion(data); if (log.isTracing()) {
StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$
b.append(((InclusionData) data).reader.filename);
log.traceLog(b.toString());
}
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popInclusion()
*/
protected void popInclusion(java.lang.Object data) {
super.popInclusion(data);
callbackManager
.pushCallback(((InclusionData) bufferData[bufferStackPos]).inclusion);
} }
/* /*
@ -141,15 +137,6 @@ public class Scanner2 extends BaseScanner {
callbackManager.popCallbacks(); callbackManager.popCallbacks();
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushProblem(org.eclipse.cdt.core.parser.IProblem)
*/
protected void pushProblem(IProblem p) {
callbackManager.pushCallback(p);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -202,13 +189,11 @@ public class Scanner2 extends BaseScanner {
break; break;
MacroData data = (MacroData) bufferData[mostRelevant + 1]; MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new SimpleExpansionToken(signal, data.startOffset, return new SimpleExpansionToken(signal, data.startOffset,
data.endOffset - data.startOffset + 1, data.endOffset - data.startOffset + 1, getCurrentFilename(),
getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1)); getLineNumber(bufferPos[mostRelevant] + 1));
} }
return new SimpleToken(signal, bufferPos[bufferStackPos] + 1, return new SimpleToken(signal, bufferPos[bufferStackPos] + 1,
getCurrentFilename(), getCurrentFilename(), getLineNumber(bufferPos[bufferStackPos] + 1));
getLineNumber(bufferPos[bufferStackPos] + 1));
} }
protected IToken newToken(int signal, char[] buffer) { protected IToken newToken(int signal, char[] buffer) {
@ -220,13 +205,11 @@ public class Scanner2 extends BaseScanner {
break; break;
MacroData data = (MacroData) bufferData[mostRelevant + 1]; MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new ImagedExpansionToken(signal, buffer, data.startOffset, return new ImagedExpansionToken(signal, buffer, data.startOffset,
data.endOffset - data.startOffset + 1, data.endOffset - data.startOffset + 1, getCurrentFilename(),
getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1)); getLineNumber(bufferPos[mostRelevant] + 1));
} }
IToken i = new ImagedToken(signal, buffer, IToken i = new ImagedToken(signal, buffer, bufferPos[bufferStackPos] + 1,
bufferPos[bufferStackPos] + 1, getCurrentFilename(), getCurrentFilename(), getLineNumber(bufferPos[bufferStackPos] + 1));
getLineNumber(bufferPos[bufferStackPos] + 1));
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
&& signal != IToken.tLSTRING) && signal != IToken.tLSTRING)
bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some
@ -236,6 +219,7 @@ public class Scanner2 extends BaseScanner {
} }
protected static final ScannerProblemFactory spf = new ScannerProblemFactory(); protected static final ScannerProblemFactory spf = new ScannerProblemFactory();
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -245,11 +229,29 @@ public class Scanner2 extends BaseScanner {
protected void handleProblem(int id, int offset, char[] arg) { protected void handleProblem(int id, int offset, char[] arg) {
if (parserMode == ParserMode.COMPLETION_PARSE) if (parserMode == ParserMode.COMPLETION_PARSE)
return; return;
IProblem p = spf.createProblem(id, offset, IProblem p = spf.createProblem(id, offset, bufferPos[bufferStackPos],
bufferPos[bufferStackPos],
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(), getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true); arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
pushProblem(p); callbackManager.pushCallback(p);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/
protected Object popContext() {
if (bufferData[bufferStackPos] instanceof InclusionData) {
if (log.isTracing()) {
StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
buffer
.append(((InclusionData) bufferData[bufferStackPos]).reader.filename);
log.traceLog(buffer.toString());
}
callbackManager
.pushCallback(((InclusionData) bufferData[bufferStackPos]).inclusion);
}
return super.popContext();
} }
} }