1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Initial SelectionSearch support for Scanner2.

This commit is contained in:
John Camelon 2004-07-21 20:16:43 +00:00
parent b0444239f0
commit 98f3ab7804

View file

@ -56,33 +56,23 @@ public class Scanner2 implements IScanner, IScannerData {
* @author jcamelon * @author jcamelon
* *
*/ */
private static class ReaderInclusionDuple { private static class InclusionData {
private final IASTInclusion inclusion; public final IASTInclusion inclusion;
private final CodeReader reader; public final CodeReader reader;
public final int index;
/** /**
* @param reader * @param reader
* @param inclusion * @param inclusion
*/ */
public ReaderInclusionDuple(CodeReader reader, IASTInclusion inclusion) { public InclusionData(CodeReader reader, IASTInclusion inclusion, int index ) {
this.reader = reader; this.reader = reader;
this.inclusion = inclusion; this.inclusion = inclusion;
this.index = index;
}
} }
/**
* @return Returns the inclusion.
*/
public final IASTInclusion getInclusion() {
return inclusion;
}
/**
* @return Returns the reader.
*/
public final CodeReader getReader() {
return reader;
}
}
private ISourceElementRequestor requestor; private ISourceElementRequestor requestor;
private ParserLanguage language; private ParserLanguage language;
@ -142,6 +132,7 @@ public class Scanner2 implements IScanner, IScannerData {
fileCache.put(reader.filename, reader); fileCache.put(reader.filename, reader);
pushContext(reader.buffer, reader); pushContext(reader.buffer, reader);
addToFileIndex( reader.filename.toCharArray() );
setupBuiltInMacros(); setupBuiltInMacros();
@ -193,14 +184,14 @@ public class Scanner2 implements IScanner, IScannerData {
private void pushContext(char[] buffer, Object data) { private void pushContext(char[] buffer, Object data) {
pushContext(buffer); pushContext(buffer);
bufferData[bufferStackPos] = data; bufferData[bufferStackPos] = data;
if( data instanceof ReaderInclusionDuple ) if( data instanceof InclusionData )
requestor.enterInclusion( ((ReaderInclusionDuple)data).getInclusion() ); requestor.enterInclusion( ((InclusionData)data).inclusion );
} }
private void popContext() { private void popContext() {
bufferStack[bufferStackPos] = null; bufferStack[bufferStackPos] = null;
if( bufferData[bufferStackPos] instanceof ReaderInclusionDuple ) if( bufferData[bufferStackPos] instanceof InclusionData )
requestor.enterInclusion( ((ReaderInclusionDuple)bufferData[bufferStackPos]).getInclusion() ); requestor.enterInclusion( ((InclusionData)bufferData[bufferStackPos]).inclusion );
bufferData[bufferStackPos] = null; bufferData[bufferStackPos] = null;
--bufferStackPos; --bufferStackPos;
} }
@ -1199,7 +1190,7 @@ public class Scanner2 implements IScanner, IScannerData {
for (int i = 0; i < includePaths.length; ++i) { for (int i = 0; i < includePaths.length; ++i) {
String finalPath = ScannerUtility.createReconciledPath(includePaths[i], filename); String finalPath = ScannerUtility.createReconciledPath(includePaths[i], filename);
if (!foundme) { if (!foundme) {
if (finalPath.equals(((ReaderInclusionDuple)bufferData[bufferStackPos]).getReader().filename)) { if (finalPath.equals(((InclusionData)bufferData[bufferStackPos]).reader.filename)) {
foundme = true; foundme = true;
continue; continue;
} }
@ -1212,7 +1203,7 @@ public class Scanner2 implements IScanner, IScannerData {
fileCache.put(reader.filename, reader); fileCache.put(reader.filename, reader);
if (dlog != null) dlog.println("#include <" + finalPath + ">"); //$NON-NLS-1$ //$NON-NLS-2$ if (dlog != null) dlog.println("#include <" + finalPath + ">"); //$NON-NLS-1$ //$NON-NLS-2$
IASTInclusion inclusion = getASTFactory().createInclusion( new String( filename ), new String( reader.filename ), local, startOffset, startLine, nameOffset, nameEndOffset, nameLine, endOffset, endLine ); IASTInclusion inclusion = getASTFactory().createInclusion( new String( filename ), new String( reader.filename ), local, startOffset, startLine, nameOffset, nameEndOffset, nameLine, endOffset, endLine );
pushContext(reader.buffer, new ReaderInclusionDuple( reader, inclusion )); pushContext(reader.buffer, new InclusionData( reader, inclusion, addToFileIndex( reader.filename.toCharArray() ) ));
return; return;
} }
} }
@ -2510,26 +2501,53 @@ public class Scanner2 implements IScanner, IScannerData {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
protected static final int STARTING_FILECACHE_SIZE = 32;
protected char [][] fileNames = new char[STARTING_FILECACHE_SIZE][];
protected int fileIndexCounter = 0;
/**
* @param cs
* @return
*/
private int addToFileIndex(char[] cs) {
if( fileIndexCounter >= fileNames.length )
{
char [][] prev = fileNames;
fileNames = new char[ prev.length * 2 ][];
System.arraycopy( prev, 0, fileNames, 0, prev.length );
}
int result = fileIndexCounter;
fileNames[ fileIndexCounter ] = cs;
++fileIndexCounter;
return result;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFileIndex() * @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFileIndex()
*/ */
public int getCurrentFileIndex() { public final int getCurrentFileIndex() {
// TODO Auto-generated method stub for( int i = bufferStackPos; i >= 0; --i )
{
if( bufferData[i] instanceof InclusionData )
return ((InclusionData)bufferData[i]).index;
}
return 0; return 0;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFilename() * @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFilename()
*/ */
public char[] getCurrentFilename() { public final char[] getCurrentFilename() {
// TODO Auto-generated method stub return fileNames[ getCurrentFileIndex() ];
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IFilenameProvider#getFilenameForIndex(int) * @see org.eclipse.cdt.core.parser.IFilenameProvider#getFilenameForIndex(int)
*/ */
public String getFilenameForIndex(int index) { public String getFilenameForIndex(int index) {
// TODO Auto-generated method stub if( index >= 0 && index < fileNames.length )
return null; return new String( fileNames[index] );
return EMPTY_STRING;
} }
private static CharArrayIntMap keywords; private static CharArrayIntMap keywords;