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.StructuralCModelElementsTests;
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests;
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.ast2.DOMParserTestSuite;
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
@ -58,13 +52,7 @@ public class ParserTestSuite extends TestCase {
suite.addTest( IScannerInfoPluginTest.suite() );
suite.addTest( ScannerParserLoopTest.suite() );
suite.addTest( GCCParserExtensionTestSuite.suite() );
suite.addTestSuite( AST2Tests.class );
suite.addTestSuite( GCCTests.class );
suite.addTestSuite( AST2CPPTests.class );
suite.addTestSuite( QuickParser2Tests.class );
suite.addTestSuite( CompleteParser2Tests.class );
suite.addTestSuite( DOMLocationTests.class );
suite.addTestSuite( AST2KnRTests.class );
suite.addTest( DOMParserTestSuite.suite() );
return suite;
}
}

View file

@ -12,9 +12,17 @@ package org.eclipse.cdt.core.parser.tests.ast2;
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.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.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService;
@ -67,9 +75,11 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
language, NULL_LOG, getScannerConfig(language), factory);
ISourceCodeParser parser = null;
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 {
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, new GCCParserExtensionConfiguration() );
parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE,
NULL_LOG, new GCCParserExtensionConfiguration());
}
stream.close();
IASTTranslationUnit parseResult = parser.parse();
@ -92,9 +102,79 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
* @param language
* @return
*/
private IScannerExtensionConfiguration getScannerConfig(ParserLanguage language) {
private IScannerExtensionConfiguration getScannerConfig(
ParserLanguage language) {
if (language == ParserLanguage.CPP)
return new GPPScannerExtensionConfiguration();
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);
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() {
bufferStack[bufferStackPos] = null;
if (bufferData[bufferStackPos] instanceof InclusionData)
popInclusion(((InclusionData) bufferData[bufferStackPos]).inclusion);
Object result = bufferData[bufferStackPos];
bufferData[bufferStackPos] = null;
@ -1308,20 +1293,6 @@ abstract class BaseScanner implements IScanner {
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);
}
if (expanding)
return new MacroExpansionToken();
return EXPANSION_TOKEN;
}
char[] result = escapedNewline ? removedEscapedNewline(buffer, start, len)
@ -2683,12 +2654,11 @@ abstract class BaseScanner implements IScanner {
fileCache.put(reader.filename, reader);
}
if (reader != null) {
Object inclusion = createInclusionConstruct(fileNameArray,
pushContext(reader.buffer, new InclusionData(reader,
createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset,
startingLineNumber, nameOffset, nameEndOffset,
nameLine, endOffset, endLine, false);
pushContext(reader.buffer, new InclusionData(reader,
inclusion));
nameLine, endOffset, endLine, false)));
return;
}
}
@ -4377,6 +4347,7 @@ abstract class BaseScanner implements IScanner {
protected static final char[] TAB = { '\t' };
protected static final char[] SPACE = { ' ' };
private static final MacroExpansionToken EXPANSION_TOKEN = new MacroExpansionToken();
static {
CharArrayIntMap words = new CharArrayIntMap(IToken.tLAST, -1);

View file

@ -10,7 +10,6 @@
**********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.parser.CodeReader;
@ -32,212 +31,248 @@ import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
*/
public class DOMScanner extends BaseScanner {
private final ICodeReaderFactory codeReaderFactory;
private int globalCounter = 0;
private int contextDelta = 0;
private final ICodeReaderFactory codeReaderFactory;
private int globalCounter = 0;
private int contextDelta = 0;
private static class DOMInclusion
{
public final char[] pt;
public final int o;
private static class DOMInclusion {
public final char[] pt;
public final int o;
/**
*
*/
public DOMInclusion( char [] path, int offset ) {
this.pt = path;
this.o = offset;
}
}
/**
*
*/
public DOMInclusion(char[] path, int offset) {
this.pt = path;
this.o = offset;
}
}
/**
* @param reader
* @param info
* @param parserMode
* @param language
* @param log
* @param readerFactory TODO
* @param requestor
*/
public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtensionConfiguration configuration, ICodeReaderFactory readerFactory) {
super(reader, info, parserMode, language, log, configuration);
this.expressionEvaluator = new ExpressionEvaluator(null, null);
this.codeReaderFactory = readerFactory;
postConstructorSetup(reader, info);
}
/**
* @param reader
* @param info
* @param parserMode
* @param language
* @param log
* @param readerFactory
* TODO
* @param requestor
*/
public DOMScanner(CodeReader reader, IScannerInfo info,
ParserMode parserMode, ParserLanguage language, IParserLogService log,
IScannerExtensionConfiguration configuration,
ICodeReaderFactory readerFactory) {
super(reader, info, parserMode, language, log, configuration);
this.expressionEvaluator = new ExpressionEvaluator(null, null);
this.codeReaderFactory = readerFactory;
postConstructorSetup(reader, info);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/
public ILocationResolver getLocationResolver() {
if( locationMap instanceof ILocationResolver )
return (ILocationResolver) locationMap;
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/
public ILocationResolver getLocationResolver() {
if (locationMap instanceof ILocationResolver)
return (ILocationResolver) locationMap;
return null;
}
final IScannerPreprocessorLog locationMap = new LocationMap();
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/
public void setASTFactory(IASTFactory f) {
// 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)
*/
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) {
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)
*/
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)
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
startingLineNumber, idstart, idend, textEnd);
else if (macro instanceof FunctionStyleMacro)
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
startingLineNumber, idstart, idend, textEnd);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/
protected CodeReader createReaderDuple(String finalPath) {
return codeReaderFactory.createCodeReaderForInclusion(finalPath);
}
final IScannerPreprocessorLog locationMap = new LocationMap();
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
* java.lang.Object)
*/
protected void pushContext(char[] buffer, Object data) {
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);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/
protected Object popContext() {
//TODO calibrate offsets
Object result = super.popContext();
if (result instanceof CodeReader) {
globalCounter += (((CodeReader) result).buffer.length - contextDelta);
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());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/
public void setASTFactory(IASTFactory f) {
// do nothing
}
globalCounter += (((InclusionData) result).reader.buffer.length - contextDelta);
contextDelta = getCurrentOffset();
locationMap.endInclusion(globalCounter);
}
return result;
}
/* (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) {
return new DOMInclusion( filenamePath, startOffset );
}
/**
* @return
*/
protected IToken newToken(int signal) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
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 SimpleToken(signal,
resolveOffset(bufferPos[bufferStackPos] + 1), getCurrentFilename(),
getLineNumber(bufferPos[bufferStackPos] + 1));
}
/* (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) {
if( macro instanceof ObjectStyleMacro )
locationMap.defineObjectStyleMacro( (ObjectStyleMacro) macro, startingLineNumber, idstart, idend, textEnd );
else if( macro instanceof FunctionStyleMacro )
locationMap.defineFunctionStyleMacro( (FunctionStyleMacro) macro, startingLineNumber, idstart, idend, textEnd );
protected IToken newToken(int signal, char[] buffer) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[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));
if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
&& signal != IToken.tLSTRING)
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some
// point
}
return i;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/
protected CodeReader createReaderDuple(String finalPath) {
return codeReaderFactory.createCodeReaderForInclusion(finalPath);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/
protected void quickParsePushPopInclusion(Object inclusion) {
//do nothing
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
* int, char[])
*/
protected void handleProblem(int id, int offset, char[] arg) {
IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
int o = resolveOffset(offset);
((ScannerASTProblem) problem).setOffsetAndLength(o,
resolveOffset(getCurrentOffset() + 1) - o);
locationMap.encounterProblem(problem);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[])
*/
protected void pushContext(char[] buffer) {
//TODO calibrate offsets
super.pushContext(buffer);
}
/**
* @param offset
* @return
*/
private int resolveOffset(int offset) {
return globalCounter - contextDelta + offset;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[], java.lang.Object)
*/
protected void pushContext(char[] buffer, Object data) {
//TODO calibrate offsets
super.pushContext(buffer, data);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
*/
protected Object popContext() {
//TODO calibrate offsets
Object result = super.popContext();
if( result instanceof CodeReader )
{
globalCounter += (((CodeReader)result).buffer.length - contextDelta);
locationMap.endTranslationUnit( globalCounter );
}
return result;
}
/**
* @return
*/
protected IToken newToken( int signal ) {
if( bufferData[bufferStackPos] instanceof MacroData )
{
int mostRelevant;
for( mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant )
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
break;
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 SimpleToken(signal, resolveOffset( bufferPos[bufferStackPos] + 1 ) , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1) );
}
protected IToken newToken( int signal, char [] buffer )
{
if( bufferData[bufferStackPos] instanceof MacroData )
{
int mostRelevant;
for( mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant )
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
break;
MacroData data = (MacroData)bufferData[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));
if( buffer != null && buffer.length == 0 && signal != IToken.tSTRING && signal != IToken.tLSTRING )
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some point
return i;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/
protected void quickParsePushPopInclusion(Object inclusion) {
//do nothing
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushInclusion(java.lang.Object)
*/
protected void pushInclusion(Object data) {
super.pushInclusion(data);
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) {
IASTProblem problem = new ScannerASTProblem(id, arg, true, false );
int o = resolveOffset( offset );
((ScannerASTProblem)problem).setOffsetAndLength( o, resolveOffset( getCurrentOffset() + 1 ) - o );
locationMap.encounterProblem(problem);
}
/**
* @param offset
* @return
*/
private int resolveOffset(int offset) {
return globalCounter - contextDelta + offset;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader, org.eclipse.cdt.core.parser.IScannerInfo)
/*
* (non-Javadoc)
*
* @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) {
super.postConstructorSetup(reader, info);
locationMap.startTranslationUnit( getMainFilename() );
locationMap.startTranslationUnit(getMainFilename());
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#throwEOF()
*/
protected void throwEOF() throws EndOfFileException {
locationMap.endTranslationUnit( globalCounter );
locationMap.endTranslationUnit(globalCounter);
super.throwEOF();
}

View file

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

View file

@ -20,40 +20,29 @@ public interface IScannerPreprocessorLog {
public void startTranslationUnit( char [] filename );
public void endTranslationUnit(int offset);
public void startInclusion(char[] includePath, int offset);
public void endInclusion(char[] includePath, int offset);
public void startInclusion(char[] includePath, int offset, int endOffset);
public void endInclusion(int offset);
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
int offset);
public void exitObjectStyleMacroExpansion(char[] name, int offset);
public void enterFunctionStyleExpansion(char[] name, char[][] parameters,
char[] expansion, int offset);
public void exitFunctionStyleExpansion(char[] name, int offset);
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset);
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset);
public void encounterPoundIf(int startOffset, int endOffset);
public void encounterPoundPragma(int startOffset, int endOffset);
public void encounterPoundError(int startOffset, int endOffset);
public void encounterPoundIfdef(int startOffset, int endOffset);
public void encounterPoundUndef(int startOffset, int endOffset);
public void encounterPoundElse(int startOffset, int endOffset);
public void encounterPoundElif(int startOffset, int endOffset);
public void encounterPoundEndIf(int startOffset, int endOffset);
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 static class Location implements IASTNodeLocation
{
public static class Location implements IASTNodeLocation {
private final int nodeOffset;
private final int nodeLength;
@ -41,28 +40,31 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
nodeLength = length;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeOffset()
*/
public int getNodeOffset() {
return nodeOffset;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeLength()
*/
public int getNodeLength() {
return nodeLength;
}
}
/**
* @author jcamelon
*/
public static class FileLocation extends Location implements IASTFileLocation {
public static class FileLocation extends Location implements
IASTFileLocation {
private String fileName;
@ -73,11 +75,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*
*/
public FileLocation(char[] tu_filename, int offset, int length) {
super( offset, length );
fileName = new String( tu_filename );
super(offset, length);
fileName = new String(tu_filename);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTFileLocation#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 IASTNodeLocation [] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
private char[] tu_filename = EMPTY_CHAR_ARRAY ;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private int finalOffset = 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;
}
public final int context_directive_start;
public final int context_directive_end;
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)
*/
public IASTNodeLocation[] getLocations(int offset, int length) {
if( tu_filename == EMPTY_CHAR_ARRAY ) return EMPTY_LOCATION_ARRAY;
if( macroExpansions.isEmpty() && inclusions.isEmpty() )
if (tu == null)
return EMPTY_LOCATION_ARRAY;
Context c = findContextForOffset(offset);
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];
if (c instanceof TranslationUnit) {
result[0] = new FileLocation(((TranslationUnit) c).path, reconcileOffset( c, offset ),
length);
return result;
}
if( c instanceof Inclusion )
{
if( offset + length > finalOffset ) return EMPTY_LOCATION_ARRAY;
IASTNodeLocation [] result = new IASTNodeLocation[1];
result[0] = new FileLocation( tu_filename, offset, length );
result[0] = new FileLocation(((Inclusion) c).path, reconcileOffset( c, offset ),
length);
return result;
}
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)
*
@ -169,7 +339,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
*/
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)
*/
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[],
* int)
*/
public void startInclusion(char[] includePath, int offset) {
inclusions.add( new String( includePath ));
public void startInclusion(char[] includePath, int offset, int endOffset) {
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[],
* int)
*/
public void endInclusion(char[] includePath, int offset) {
// TODO Auto-generated method stub
public void endInclusion(int offset) {
((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()
*/
public String getTranslationUnitPath() {
if( tu_filename == EMPTY_CHAR_ARRAY ) return ""; //$NON-NLS-1$
return new String( tu_filename );
return new String(tu.path);
}
/*
* (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)
*
@ -395,9 +558,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#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 (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)
*/
public void encounterProblem(IASTProblem problem) {
if (problems == Collections.EMPTY_LIST)
problems = new ArrayList(4);
problems.add(problem);
ScannerASTProblem p = (ScannerASTProblem) problem;
Problem pr = new Problem(currentContext, p.getOffset(), p.getOffset()
+ 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

@ -34,222 +34,224 @@ import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
*/
public class Scanner2 extends BaseScanner {
/**
* @param reader
* @param info
* @param requestor
* @param parserMode
* @param language
* @param log
* @param workingCopies
* @param configuration
*/
public Scanner2(CodeReader reader, IScannerInfo info,
ISourceElementRequestor requestor, ParserMode parserMode,
ParserLanguage language, IParserLogService log, List workingCopies,
IScannerExtensionConfiguration configuration) {
super(reader, info, parserMode, language, log, configuration);
this.requestor = requestor;
this.callbackManager = new ScannerCallbackManager(requestor);
this.expressionEvaluator = new ExpressionEvaluator(callbackManager, spf);
this.workingCopies = workingCopies;
postConstructorSetup(reader, info);
}
/**
* @param reader
* @param info
* @param requestor
* @param parserMode
* @param language
* @param log
* @param workingCopies
* @param configuration
*/
public Scanner2(CodeReader reader, IScannerInfo info,
ISourceElementRequestor requestor, ParserMode parserMode,
ParserLanguage language, IParserLogService log, List workingCopies,
IScannerExtensionConfiguration configuration) {
super(reader, info, parserMode, language, log, configuration);
this.requestor = requestor;
this.callbackManager = new ScannerCallbackManager(requestor);
this.expressionEvaluator = new ExpressionEvaluator(callbackManager, spf);
this.workingCopies = workingCopies;
postConstructorSetup(reader, info);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getASTFactory()
*/
protected IASTFactory getASTFactory() {
if (astFactory == null)
astFactory = ParserFactory.createASTFactory(parserMode, language);
return astFactory;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getASTFactory()
*/
protected IASTFactory getASTFactory() {
if (astFactory == null)
astFactory = ParserFactory.createASTFactory(parserMode, language);
return astFactory;
}
protected IASTFactory astFactory;
protected IASTFactory astFactory;
// callbacks
protected ScannerCallbackManager callbackManager;
// callbacks
protected ScannerCallbackManager callbackManager;
protected ISourceElementRequestor requestor;
protected ISourceElementRequestor requestor;
protected List workingCopies;
protected List workingCopies;
public final void setASTFactory(IASTFactory f) {
astFactory = f;
}
public final void setASTFactory(IASTFactory f) {
astFactory = f;
}
/*
* (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) {
return getASTFactory().createInclusion(fileName, filenamePath, local,
startOffset, startingLineNumber, nameOffset, nameEndOffset,
nameLine, endOffset, endLine, getCurrentFilename(), isForced);
}
/*
* (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) {
return getASTFactory().createInclusion(fileName, filenamePath, local,
startOffset, startingLineNumber, nameOffset, nameEndOffset,
nameLine, endOffset, endLine, getCurrentFilename(), isForced);
}
/*
* (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,
org.eclipse.cdt.core.parser.IMacro macro) {
callbackManager.pushCallback(getASTFactory().createMacro(name,
startingOffset, startingLineNumber, idstart, idend, nameLine,
textEnd, endingLine, getCurrentFilename(), !isInitialized));
}
/*
* (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, org.eclipse.cdt.core.parser.IMacro macro) {
callbackManager.pushCallback(getASTFactory().createMacro(name,
startingOffset, startingLineNumber, idstart, idend, nameLine,
textEnd, endingLine, getCurrentFilename(), !isInitialized));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushInclusion(java.lang.Object)
*/
protected void pushInclusion(Object data) {
callbackManager.pushCallback(data);
super.pushInclusion(data);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
* java.lang.Object)
*/
protected void pushContext(char[] buffer, Object data) {
super.pushContext(buffer, data);
if (data instanceof InclusionData) {
callbackManager.pushCallback(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);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#beforeSecondFetchToken()
*/
protected void beforeSecondFetchToken() {
if (callbackManager.hasCallbacks())
callbackManager.popCallbacks();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#beforeSecondFetchToken()
*/
protected void beforeSecondFetchToken() {
if (callbackManager.hasCallbacks())
callbackManager.popCallbacks();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/
protected void quickParsePushPopInclusion(Object inclusion) {
callbackManager.pushCallback(new InclusionData(null, inclusion));
callbackManager.pushCallback(inclusion);
}
/*
* (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)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/
protected CodeReader createReaderDuple(String finalPath) {
return ScannerUtility.createReaderDuple(finalPath, requestor,
getWorkingCopies());
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
*/
protected void quickParsePushPopInclusion(Object inclusion) {
callbackManager.pushCallback(new InclusionData(null, inclusion));
callbackManager.pushCallback(inclusion);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/
public ILocationResolver getLocationResolver() {
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
*/
protected CodeReader createReaderDuple(String finalPath) {
return ScannerUtility.createReaderDuple(finalPath, requestor,
getWorkingCopies());
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies()
*/
protected Iterator getWorkingCopies() {
if (workingCopies == null)
return EmptyIterator.EMPTY_ITERATOR;
return workingCopies.iterator();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
*/
public ILocationResolver getLocationResolver() {
return null;
}
/**
* @return
*/
protected IToken newToken(int signal) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new SimpleExpansionToken(signal, data.startOffset,
data.endOffset - data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
return new SimpleToken(signal, bufferPos[bufferStackPos] + 1,
getCurrentFilename(), getLineNumber(bufferPos[bufferStackPos] + 1));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies()
*/
protected Iterator getWorkingCopies() {
if (workingCopies == null)
return EmptyIterator.EMPTY_ITERATOR;
return workingCopies.iterator();
}
protected IToken newToken(int signal, char[] buffer) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new ImagedExpansionToken(signal, buffer, data.startOffset,
data.endOffset - data.startOffset + 1, getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
IToken i = new ImagedToken(signal, buffer, bufferPos[bufferStackPos] + 1,
getCurrentFilename(), 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
*/
protected IToken newToken(int signal) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new SimpleExpansionToken(signal, data.startOffset,
data.endOffset - data.startOffset + 1,
getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
return new SimpleToken(signal, bufferPos[bufferStackPos] + 1,
getCurrentFilename(),
getLineNumber(bufferPos[bufferStackPos] + 1));
}
return i;
}
protected IToken newToken(int signal, char[] buffer) {
if (bufferData[bufferStackPos] instanceof MacroData) {
int mostRelevant;
for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant)
if (bufferData[mostRelevant] instanceof InclusionData
|| bufferData[mostRelevant] instanceof CodeReader)
break;
MacroData data = (MacroData) bufferData[mostRelevant + 1];
return new ImagedExpansionToken(signal, buffer, data.startOffset,
data.endOffset - data.startOffset + 1,
getCurrentFilename(),
getLineNumber(bufferPos[mostRelevant] + 1));
}
IToken i = new ImagedToken(signal, buffer,
bufferPos[bufferStackPos] + 1, getCurrentFilename(),
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
protected static final ScannerProblemFactory spf = new ScannerProblemFactory();
return i;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
* int, char[])
*/
protected void handleProblem(int id, int offset, char[] arg) {
if (parserMode == ParserMode.COMPLETION_PARSE)
return;
IProblem p = spf.createProblem(id, offset, bufferPos[bufferStackPos],
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
callbackManager.pushCallback(p);
}
protected static final ScannerProblemFactory spf = new ScannerProblemFactory();
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
* int, char[])
*/
protected void handleProblem(int id, int offset, char[] arg) {
if (parserMode == ParserMode.COMPLETION_PARSE)
return;
IProblem p = spf.createProblem(id, offset,
bufferPos[bufferStackPos],
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
pushProblem(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();
}
}