1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Added offset lengths to index storage

Refactored IndexView to display offset lengths
This commit is contained in:
Bogdan Gheorghe 2005-04-08 06:07:51 +00:00
parent d2511e5265
commit 817b4953c6
13 changed files with 310 additions and 131 deletions

View file

@ -47,38 +47,38 @@ public class IndexerOffsetTests extends TestCase {
public void testOffsetsResizing() throws Exception{
WordEntry word = new WordEntry("typeDecl/C/Test".toCharArray());
word.addRef(2);
word.addOffset(235,2,ICIndexStorageConstants.OFFSET);
word.addOffset(512,2,ICIndexStorageConstants.OFFSET);
word.addOffset(512,2,ICIndexStorageConstants.OFFSET);
word.addOffset(512,2,ICIndexStorageConstants.OFFSET);
word.addOffset(235,5,2,ICIndexStorageConstants.OFFSET);
word.addOffset(512,3,2,ICIndexStorageConstants.OFFSET);
word.addOffset(512,3,2,ICIndexStorageConstants.OFFSET);
word.addOffset(512,3,2,ICIndexStorageConstants.OFFSET);
word.addRef(5);
word.addOffset(43,5,ICIndexStorageConstants.OFFSET);
word.addOffset(2,5,ICIndexStorageConstants.LINE);
word.addOffset(89,5,ICIndexStorageConstants.OFFSET);
word.addOffset(63,5,ICIndexStorageConstants.LINE);
word.addOffset(124,5,ICIndexStorageConstants.OFFSET);
word.addOffset(43,6,5,ICIndexStorageConstants.OFFSET);
word.addOffset(2,3,5,ICIndexStorageConstants.LINE);
word.addOffset(89,8,5,ICIndexStorageConstants.OFFSET);
word.addOffset(63,2,5,ICIndexStorageConstants.LINE);
word.addOffset(124,7,5,ICIndexStorageConstants.OFFSET);
word.addRef(9);
word.addOffset(433,9,ICIndexStorageConstants.OFFSET);
word.addOffset(234,9,ICIndexStorageConstants.OFFSET);
word.addOffset(433,5,9,ICIndexStorageConstants.OFFSET);
word.addOffset(234,3,9,ICIndexStorageConstants.OFFSET);
word.addRef(11);
word.addOffset(4233,11,ICIndexStorageConstants.OFFSET);
word.addOffset(2314,11,ICIndexStorageConstants.OFFSET);
word.addOffset(4233,2,11,ICIndexStorageConstants.OFFSET);
word.addOffset(2314,7,11,ICIndexStorageConstants.OFFSET);
word.addRef(17);
word.addOffset(2,17,ICIndexStorageConstants.OFFSET);
word.addOffset(52,17,ICIndexStorageConstants.OFFSET);
word.addOffset(2,7,17,ICIndexStorageConstants.OFFSET);
word.addOffset(52,8,17,ICIndexStorageConstants.OFFSET);
int[] test =word.getOffsets(1);
WordEntry word2 = new WordEntry("typeDecl/C/Test".toCharArray());
word2.addRef(4);
word2.addOffset(13,4, ICIndexStorageConstants.OFFSET);
word2.addOffset(17,4, ICIndexStorageConstants.OFFSET);
word2.addOffset(20,4,ICIndexStorageConstants.OFFSET);
word2.addOffset(13,4,4, ICIndexStorageConstants.OFFSET);
word2.addOffset(17,3,4, ICIndexStorageConstants.OFFSET);
word2.addOffset(20,6,4,ICIndexStorageConstants.OFFSET);
word2.addRef(7);
word2.addOffset(21,7, ICIndexStorageConstants.OFFSET);
word2.addOffset(24,7, ICIndexStorageConstants.OFFSET);
word2.addOffset(28,7,ICIndexStorageConstants.OFFSET);
word2.addOffset(21,2,7, ICIndexStorageConstants.OFFSET);
word2.addOffset(24,3,7, ICIndexStorageConstants.OFFSET);
word2.addOffset(28,7,7,ICIndexStorageConstants.OFFSET);
word.addWordInfo(word2.getRefs(), word2.getOffsets(), word2.getOffsetCount());
word.addWordInfo(word2.getRefs(), word2.getOffsets(), word2.getOffsetLengths(), word2.getOffsetCount());
word.mapRefs(new int[]{-1, 1, 17, 3, 4, 11, 6, 7, 8, 24, 10, 5, 12, 13, 14, 15, 16, 2});

View file

@ -151,12 +151,12 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
TestSuite suite = new TestSuite(SourceIndexerTests.class.getName());
suite.addTest(new SourceIndexerTests("testAddNewFileToIndex")); //$NON-NLS-1$
/* suite.addTest(new SourceIndexerTests("testForwardDeclarations")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testForwardDeclarations")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testIndexAll")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testIndexContents")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testMacros")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testRefs")); //$NON-NLS-1$
*/ suite.addTest(new SourceIndexerTests("testExactDeclarations")); //$NON-NLS-1$
//suite.addTest(new SourceIndexerTests("testIndexContents")); //$NON-NLS-1$
//suite.addTest(new SourceIndexerTests("testMacros")); //$NON-NLS-1$
//suite.addTest(new SourceIndexerTests("testRefs")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testExactDeclarations")); //$NON-NLS-1$
//suite.addTest(new SourceIndexerTests("testRemoveFileFromIndex")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testRemoveProjectFromIndex")); //$NON-NLS-1$
suite.addTest(new SourceIndexerTests("testIndexShutdown")); //$NON-NLS-1$
@ -207,20 +207,20 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
assertTrue("Entry Results exist", eresults != null); //$NON-NLS-1$
String [] queryResultModel = {"IndexedFile(1: /IndexerTestProject/mail.cpp)"}; //$NON-NLS-1$
String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/Unknown, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/container, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/first_class, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/postcard, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/D/Mail, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/D/first_class, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/D/postcard, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/index, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/mail, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/size, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/temp, refs={ 1 }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/x, refs={ 1 }"}; //$NON-NLS-1$
String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }, offsets={ [ 288] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/Unknown, refs={ 1 }, offsets={ [ 2732] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/container, refs={ 1 }, offsets={ [ 21078] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/first_class, refs={ 1 }, offsets={ [ 2500] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/C/postcard, refs={ 1 }, offsets={ [ 2292] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/D/Mail, refs={ 1 }, offsets={ [ 288] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/D/first_class, refs={ 1 }, offsets={ [ 2500] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/D/postcard, refs={ 1 }, offsets={ [ 2292] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }, offsets={ [ 21361] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/index, refs={ 1 }, offsets={ [ 21299, 21842] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/mail, refs={ 1 }, offsets={ [ 21330, 21906] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/size, refs={ 1 }, offsets={ [ 21923] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/temp, refs={ 1 }, offsets={ [ 21960] }", //$NON-NLS-1$
"EntryResult: word=typeDecl/V/x, refs={ 1 }, offsets={ [ 21197, 21522] }"}; //$NON-NLS-1$
if (qresults.length != queryResultModel.length)
@ -379,15 +379,15 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
IEntryResult[] typerefreesults = ind.queryEntries(IIndexConstants.TYPE_REF);
assertTrue("Type Ref Results exist", typerefreesults != null); //$NON-NLS-1$
String [] typeDeclEntryResultModel ={"EntryResult: word=typeDecl/C/Mail/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/Unknown/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/C/container/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/first_class/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/C/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/D/Mail/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/D/first_class/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/E/test/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/T/int32, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }","EntryResult: word=typeDecl/V/index, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/mail, refs={ 1 }", "EntryResult: word=typeDecl/V/size, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/x/Z, refs={ 1 }"}; //$NON-NLS-1$
String [] typeDeclEntryResultModel ={"EntryResult: word=typeDecl/C/Mail/Y/X/Z, refs={ 1 }, offsets={ [ 2329] }","EntryResult: word=typeDecl/C/Unknown/Y/X/Z, refs={ 1 }, offsets={ [ 21057] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/C/container/Y/X/Z, refs={ 1 }, offsets={ [ 21439] }","EntryResult: word=typeDecl/C/first_class/Y/X/Z, refs={ 1 }, offsets={ [ 2798] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/C/postcard/Y/X/Z, refs={ 1 }, offsets={ [ 2566] }","EntryResult: word=typeDecl/D/Mail/Y/X/Z, refs={ 1 }, offsets={ [ 2329] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/D/first_class/Y/X/Z, refs={ 1 }, offsets={ [ 2798] }", "EntryResult: word=typeDecl/D/postcard/Y/X/Z, refs={ 1 }, offsets={ [ 2566] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/E/test/Y/X/Z, refs={ 1 }, offsets={ [ 2297] }","EntryResult: word=typeDecl/T/int32, refs={ 1 }, offsets={ [ 2188] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }, offsets={ [ 21782] }","EntryResult: word=typeDecl/V/index, refs={ 1 }, offsets={ [ 21702, 22329] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/mail, refs={ 1 }, offsets={ [ 21736, 22396] }", "EntryResult: word=typeDecl/V/size, refs={ 1 }, offsets={ [ 22419] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/temp, refs={ 1 }, offsets={ [ 22459] }", "EntryResult: word=typeDecl/V/x, refs={ 1 }, offsets={ [ 21585, 21961] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=typeDecl/V/x/Z, refs={ 1 }, offsets={ [ 2255] }"}; //$NON-NLS-1$
IEntryResult[] typedeclresults =ind.queryEntries(IIndexConstants.TYPE_DECL);
assertTrue("Type Decl Results exist", typedeclresults != null); //$NON-NLS-1$
@ -400,7 +400,7 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
assertEquals(typeDeclEntryResultModel[i],typedeclresults[i].toString());
}
String [] typeDefEntryResultModel ={"EntryResult: word=typeDecl/T/int32, refs={ 1 }"}; //$NON-NLS-1$
String [] typeDefEntryResultModel ={"EntryResult: word=typeDecl/T/int32, refs={ 1 }, offsets={ [ 2188] }"}; //$NON-NLS-1$
IEntryResult[] typedefresults =ind.queryEntries(IIndexConstants.TYPEDEF_DECL);
assertTrue("Type Def Results exist", typedefresults != null); //$NON-NLS-1$
@ -412,8 +412,8 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
assertEquals(typeDefEntryResultModel[i],typedefresults[i].toString());
}
String [] namespaceResultModel = {"EntryResult: word=namespaceDecl/X/Z, refs={ 1 }", "EntryResult: word=namespaceDecl/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=namespaceDecl/Z, refs={ 1 }"}; //$NON-NLS-1$
String [] namespaceResultModel = {"EntryResult: word=namespaceDecl/X/Z, refs={ 1 }, offsets={ [ 2264] }", "EntryResult: word=namespaceDecl/Y/X/Z, refs={ 1 }, offsets={ [ 2280] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=namespaceDecl/Z, refs={ 1 }, offsets={ [ 2240] }"}; //$NON-NLS-1$
IEntryResult[] namespaceresults =ind.queryEntries(IIndexConstants.NAMESPACE_DECL);
assertTrue("Namespace Results exist", namespaceresults != null); //$NON-NLS-1$
@ -426,9 +426,9 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
assertEquals(namespaceResultModel[i],namespaceresults[i].toString());
}
String [] fieldResultModel = {"EntryResult: word=fieldDecl/array/container/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/index/container/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=fieldDecl/postage/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=fieldDecl/sz/container/Y/X/Z, refs={ 1 }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=fieldDecl/type/Mail/Y/X/Z, refs={ 1 }"}; //$NON-NLS-1$ //$NON-NLS-2$
String [] fieldResultModel = {"EntryResult: word=fieldDecl/array/container/Y/X/Z, refs={ 1 }, offsets={ [ 21478] }", "EntryResult: word=fieldDecl/index/container/Y/X/Z, refs={ 1 }, offsets={ [ 21478] }, EntryResult: word=fieldDecl/index/container/Y/X/Z, refs={ 1 }, offsets={ [ 21496] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=fieldDecl/postage/Mail/Y/X/Z, refs={ 1 }, offsets={ [ 2463] }", "EntryResult: word=fieldDecl/sz/container/Y/X/Z, refs={ 1 }, offsets={ [ 21511] }", //$NON-NLS-1$ //$NON-NLS-2$
"EntryResult: word=fieldDecl/type/Mail/Y/X/Z, refs={ 1 }, offsets={ [ 2482] }"}; //$NON-NLS-1$ //$NON-NLS-2$
IEntryResult[] fieldresults =ind.queryEntries(IIndexConstants.FIELD_DECL);
assertTrue("Field Results exist", fieldresults != null); //$NON-NLS-1$
@ -702,7 +702,7 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/G/ForwardA/A".toCharArray()); //$NON-NLS-1$
assertTrue("Entry exists",fwdDclResults != null); //$NON-NLS-1$
String [] fwdDclModel = {"EntryResult: word=typeDecl/G/ForwardA/A, refs={ 1 }"}; //$NON-NLS-1$
String [] fwdDclModel = {"EntryResult: word=typeDecl/G/ForwardA/A, refs={ 1 }, offsets={ [ 219] }"}; //$NON-NLS-1$
if (fwdDclResults.length != fwdDclModel.length)
fail("Entry Result length different from model for forward declarations"); //$NON-NLS-1$
@ -715,7 +715,7 @@ public class SourceIndexerTests extends TestCase implements IIndexChangeListener
IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/G/ForwardA/A".toCharArray()); //$NON-NLS-1$
assertTrue("Entry exists", fwdDclRefResults!= null); //$NON-NLS-1$
String [] fwdDclRefModel = {"EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }"}; //$NON-NLS-1$
String [] fwdDclRefModel = {"EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }, offsets={ [ 219] }"}; //$NON-NLS-1$
if (fwdDclRefResults.length != fwdDclRefModel.length)
fail("Entry Result length different from model for forward declarations refs"); //$NON-NLS-1$

View file

@ -29,5 +29,10 @@ public interface IEntryResult {
* file reference etc.)
*/
public int[][] getOffsets();
/**
* Returns the offset lengths for this entry - offset lengths map to the offset in the
* offset array
*/
public int[][] getOffsetLengths();
}

View file

@ -18,11 +18,13 @@ public class EntryResult implements IEntryResult {
private char[] word;
private int[] fileRefs;
private int[][] offsets;
private int[][] offsetLengths;
public EntryResult(char[] word, int[] refs, int[][] offsets) {
public EntryResult(char[] word, int[] refs, int[][] offsets, int[][] offsetLengths) {
this.word = word;
this.fileRefs = refs;
this.offsets = offsets;
this.offsetLengths = offsetLengths;
}
public boolean equals(Object anObject){
@ -84,6 +86,9 @@ public String toString(){
public int[][] getOffsets() {
return offsets;
}
public int[][] getOffsetLengths() {
return offsetLengths;
}
}

View file

@ -17,7 +17,7 @@ public interface ICIndexStorageConstants {
/**
* The signature of the index file.
*/
public static final String SIGNATURE= "INDEX FILE 0.015"; //$NON-NLS-1$
public static final String SIGNATURE= "INDEX FILE 0.016"; //$NON-NLS-1$
/**
* The separator for files in the index file.
*/

View file

@ -103,28 +103,28 @@ public class InMemoryIndex {
* If the word does not exist, it adds it in the index.
* @param indexFlags
*/
protected void addRef(char[] word, int fileNum, int offset, int offsetType) {
protected void addRef(char[] word, int fileNum, int offset, int offsetLength, int offsetType) {
WordEntry entry= this.words.get(word);
if (entry == null) {
entry= new WordEntry(word);
entry.addRef(fileNum);
entry.addOffset(offset,fileNum, offsetType);
entry.addOffset(offset, offsetLength, fileNum, offsetType);
this.words.add(entry);
this.sortedWordEntries= null;
this.footprint += entry.footprint();
} else {
this.footprint += entry.addRef(fileNum);
entry.addOffset(offset, fileNum, offsetType);
entry.addOffset(offset, offsetLength, fileNum, offsetType);
}
}
public void addRef(IndexedFileEntry indexedFile, char[] word, int offset, int offsetType) {
addRef(word, indexedFile.getFileID(), offset, offsetType);
public void addRef(IndexedFileEntry indexedFile, char[] word, int offset, int offsetLength, int offsetType) {
addRef(word, indexedFile.getFileID(), offset, offsetLength, offsetType);
}
public void addRef(IndexedFileEntry indexedFile, String word, int offset, int offsetType) {
addRef(word.toCharArray(), indexedFile.getFileID(), offset, offsetType);
public void addRef(IndexedFileEntry indexedFile, String word, int offset, int offsetLength, int offsetType) {
addRef(word.toCharArray(), indexedFile.getFileID(), offset, offsetLength, offsetType);
}
public void addRelatives(int fileNumber, String inclusion, String parent) {

View file

@ -41,8 +41,10 @@ public class IndexerOutput implements IIndexerOutput {
throw new IllegalStateException();
}
if (offsetLength <= 0)
offsetLength = 1;
index.addRef(word, indexedFileNumber, offset, offsetType);
index.addRef(word, indexedFileNumber, offset, offsetLength, offsetType);
}
/**
* Adds a reference to the given word to the inMemoryIndex.

View file

@ -33,6 +33,10 @@ public class WordEntry {
//key into the offsets
//Offsets are prefixed with LINE or OFFSET designation
private int[][] offsets;
//Lengths of the offsets - all offsets will have an entry in here; OFFSET entries
//will have the real offset value, LINE entires will have a place holder value of 1
private int[][] offsetLengths;
//Number of offsets in each offset array
private int[] offsetCount;
@ -44,6 +48,7 @@ public class WordEntry {
fileRefCount= 0;
fileRefs= new int[1];
offsets = new int [1][1];
offsetLengths = new int[1][1];
offsetCount = new int[1];
}
/**
@ -68,6 +73,8 @@ public class WordEntry {
System.arraycopy(fileRefs, 0, fileRefs= new int[newSize], 0, fileRefCount);
//Grow the offset array
System.arraycopy(offsets, 0, offsets= new int[newSize][1], 0, fileRefCount);
//Grow the offsetLengths array
System.arraycopy(offsetLengths, 0, offsetLengths=new int[newSize][1],0,fileRefCount);
//Grow the offset count array
System.arraycopy(offsetCount, 0, offsetCount= new int[newSize], 0, fileRefCount);
//Add the new file reference
@ -89,9 +96,10 @@ public class WordEntry {
* @param passedOffsetCount
* @param offsets
*/
public void addWordInfo(int[] refs, int[][] passedOffsets, int[] passedOffsetCount) {
public void addWordInfo(int[] refs, int[][] passedOffsets, int[][] passedOffsetLengths, int[] passedOffsetCount) {
int[] newRefs= new int[fileRefCount + refs.length];
int[][] newOffsets = new int[fileRefCount + refs.length][];
int[][] newOffsets = new int[fileRefCount + refs.length][];
int[][] newOffsetLengths = new int[fileRefCount + refs.length][];
int[] newOffSetCount= new int[fileRefCount + refs.length];
int pos1= 0;
@ -117,6 +125,7 @@ public class WordEntry {
if (compare > 0) {
newRefs[posNew]= r1;
newOffsets[posNew]= offsets[pos1];
newOffsetLengths[posNew]=offsetLengths[pos1];
newOffSetCount[posNew]=offsetCount[pos1];
posNew++;
pos1++;
@ -124,6 +133,7 @@ public class WordEntry {
if (r2 != 0) {
newRefs[posNew]= r2;
newOffsets[posNew]=passedOffsets[pos2];
newOffsetLengths[posNew]=passedOffsetLengths[pos2];
newOffSetCount[posNew]=passedOffsetCount[pos2];
posNew++;
}
@ -132,6 +142,7 @@ public class WordEntry {
}
fileRefs= newRefs;
offsets= newOffsets;
offsetLengths=newOffsetLengths;
offsetCount=newOffSetCount;
fileRefCount= posNew;
}
@ -142,7 +153,7 @@ public class WordEntry {
* change of object size, new size of object if adding offset forced the expansion
* of the underlying array
*/
public int addOffset(int offset, int fileNum, int offsetType) {
public int addOffset(int offset, int offsetLength, int fileNum, int offsetType) {
//Get the position in the fileRefs array for this file number - the
//position acts as an index into the offsets array
int filePosition = getPositionForFile(fileNum);
@ -151,6 +162,8 @@ public class WordEntry {
return -1;
//Get the array containing the offsets for this file
int[] selectedOffsets = offsets[filePosition];
//Get the array containing the offset lengths for this file;
int[] selectedOffsetLengths = offsetLengths[filePosition];
//Get the offset count for this file
int selectedOffsetCount = offsetCount[filePosition];
@ -166,7 +179,11 @@ public class WordEntry {
//If there is still space in the array, add the encoded offset, update
//the count
if (selectedOffsetCount < selectedOffsets.length) {
selectedOffsets[selectedOffsetCount++]= encodedNumber;
//Place the offset in next position in the offset array
selectedOffsets[selectedOffsetCount]= encodedNumber;
//Place the length at the same place in the offset length array and increment
//the position counter
selectedOffsetLengths[selectedOffsetCount++]=offsetLength;
offsetCount[filePosition] = selectedOffsetCount;
return 0;
}
@ -174,13 +191,15 @@ public class WordEntry {
//Grow the offset array - start @ 1, grow to 4, 8, 16, 32, 64 etc.
int newSize= selectedOffsetCount < 4 ? 4 : selectedOffsetCount * 2;
System.arraycopy(selectedOffsets, 0, selectedOffsets= new int[newSize], 0, selectedOffsetCount);
//Add the encoded offset to the newly grown array, update the count
selectedOffsets[selectedOffsetCount++]= encodedNumber;
System.arraycopy(selectedOffsetLengths,0, selectedOffsetLengths=new int[newSize], 0, selectedOffsetCount);
//Add the encoded offset to the newly grown array, add the length to the same
//position, update the count
selectedOffsets[selectedOffsetCount]= encodedNumber;
selectedOffsetLengths[selectedOffsetCount++]=offsetLength;
offsetCount[filePosition] = selectedOffsetCount;
//Put the newly grown array back in place
//Put the newly grown arrays back in place
offsets[filePosition]=selectedOffsets;
offsetLengths[filePosition]=selectedOffsetLengths;
return (newSize - fileRefCount + 1) * 4;
}
@ -258,6 +277,19 @@ public class WordEntry {
}
return result;
}
/**
* Returns the offset lengths of the wordEntry
*/
public int[][] getOffsetLengths() {
int[][] result= new int[fileRefCount][];
for (int i=0; i<fileRefCount; i++){
int offsetLength =offsetCount[i];
int[] tempOffset = new int[offsetLength];
System.arraycopy(offsetLengths[i], 0, tempOffset, 0, offsetLength);
result[i]=tempOffset;
}
return result;
}
/**
* returns offset count array
*/
@ -296,6 +328,7 @@ public class WordEntry {
//Trim all arrays of excess flab
System.arraycopy(fileRefs, 0, (fileRefs= new int[fileRefCount]), 0, fileRefCount);
System.arraycopy(offsets, 0, (offsets = new int[fileRefCount][]), 0,fileRefCount);
System.arraycopy(offsetLengths, 0, (offsetLengths = new int[fileRefCount][]), 0,fileRefCount);
System.arraycopy(offsetCount, 0,(offsetCount=new int[fileRefCount]),0,fileRefCount);
//Store original ref positions in order to generate map
@ -306,7 +339,7 @@ public class WordEntry {
//Sort the original file refs
int[] mapping = new int[fileRefs.length];
figureOutMapping(originalRefs, mapping);
figureOutMapping(originalRefs, fileRefs, mapping);
mapOffsets(mapping);
}
@ -316,23 +349,27 @@ public class WordEntry {
private void mapOffsets(int[] mapping) {
int fileRefLength = fileRefs.length;
int[][] tempOffsetsArray = new int[fileRefLength][];
int[] tempOffsetLengthArray = new int[fileRefLength];
int[][] tempOffsetsLengthArray = new int[fileRefLength][];
int[] tempOffsetCountArray = new int[fileRefLength];
for (int i=0; i<mapping.length; i++){
int moveTo = mapping[i];
tempOffsetsArray[moveTo] = offsets[i];
tempOffsetLengthArray [moveTo] = offsetCount[i];
tempOffsetsLengthArray[moveTo] = offsetLengths[i];
tempOffsetCountArray [moveTo] = offsetCount[i];
}
System.arraycopy(tempOffsetsArray, 0, offsets,0, fileRefLength);
System.arraycopy(tempOffsetLengthArray, 0, offsetCount,0, fileRefLength);
System.arraycopy(tempOffsetsLengthArray, 0, offsetLengths, 0, fileRefLength);
System.arraycopy(tempOffsetCountArray, 0, offsetCount,0, fileRefLength);
}
private void figureOutMapping(int[] originalRefs, int[] mapping){
private void figureOutMapping(int[] originalRefs, int[] sortedRefs, int[] mapping){
int position = 0;
for (int i=0; i<originalRefs.length; i++){
int currentRef = originalRefs[i];
for (int j=0; j<fileRefs.length; j++){
if (currentRef == fileRefs[j]){
for (int j=0; j<sortedRefs.length; j++){
if (currentRef == sortedRefs[j]){
mapping[position++] = j;
break;
}
@ -366,6 +403,32 @@ public class WordEntry {
Util.sort(result);
return result;
}
/**
* Returns the offset length entries sorted in the same order as the sorted offsets
* for the given index
* @return
*/
public int[] getOffsetLengths(int index) {
//Get the before/after sort offsets and create a mapping
int[] initialOffsets = offsets[index];
int[] sortedOffsets = getOffsets(index);
int[] map = new int[sortedOffsets.length];
figureOutMapping(initialOffsets,sortedOffsets, map);
//Map the offset lengths to the sorted offset positions
int[] tempOffset = offsetLengths[index];
int offsetLength = offsetCount[index];
int[] result= new int[offsetLength];
for (int i=0; i<map.length; i++){
int moveTo = map[i];
result [moveTo] = tempOffset[i];
}
return result;
}
/**
* @param n
* @param tempOffsetArray
@ -381,5 +444,21 @@ public class WordEntry {
//Put the newly grown array back in place
offsets[index]=selectedOffsets;
}
/**
* @param n
* @param tempOffsetArray
*/
public void setOffsetLengths(int index, int[] tempOffsetArray) {
int[] selectedOffsets = offsetLengths[index];
int tempOffsetArrayLength = tempOffsetArray.length;
//Grow the offset array - start @ 1, grow to 4, 8, 16, 32, 64 etc.
int newSize= tempOffsetArrayLength < 4 ? 4 : tempOffsetArrayLength * 2;
System.arraycopy(tempOffsetArray, 0, selectedOffsets= new int[newSize], 0, tempOffsetArrayLength);
//Put the newly grown array back in place
offsetLengths[index]=selectedOffsets;
}
}

View file

@ -248,7 +248,7 @@ public class BlocksIndexInput extends IndexInput {
case -1 :
WordEntry entry = getEntry(pattern);
if (entry == null) return null;
return new IEntryResult[]{ new EntryResult(entry.getWord(), entry.getRefs(), entry.getOffsets()) };
return new IEntryResult[]{ new EntryResult(entry.getWord(), entry.getRefs(), entry.getOffsets(), entry.getOffsetLengths()) };
case 0 :
blockNums = summary.getAllBlockNums();
break;
@ -270,7 +270,7 @@ public class BlocksIndexInput extends IndexInput {
if (count == entries.length){
System.arraycopy(entries, 0, entries = new IEntryResult[count*2], 0, count);
}
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs(), entry.getOffsets());
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs(), entry.getOffsets(), entry.getOffsetLengths());
found = true;
} else {
if (found) break;
@ -300,7 +300,7 @@ public class BlocksIndexInput extends IndexInput {
if (count == entries.length){
System.arraycopy(entries, 0, entries = new IEntryResult[count*2], 0, count);
}
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs(), entry.getOffsets());
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs(), entry.getOffsets(), entry.getOffsetLengths());
found = true;
} else {
if (found) break;

View file

@ -75,6 +75,16 @@ public class GammaCompressedIndexBlock extends IndexBlock {
prevRef=ref;
}
}
//encode offset lengths
for (int i=0; i<n; i++){
int[] offsetLengthArray = entry.getOffsetLengths(i);
//write offset array length
codeStream.writeGamma(offsetLengthArray.length);
for (int j=0; j<offsetLengthArray.length; j++){
int ref = offsetLengthArray[j];
codeStream.writeGamma(ref);
}
}
}
/**
* @see IndexBlock#addEntry
@ -171,6 +181,16 @@ public class GammaCompressedIndexBlock extends IndexBlock {
}
entry.setOffsets(i, tempOffsetArray);
}
for (int i=0; i<n; ++i) {
int offsetLengthArrayLength = readCodeStream.readGamma();
int[] tempOffsetLengthArray = new int[offsetLengthArrayLength];
for (int j=0; j<offsetLengthArrayLength; j++){
int ref = readCodeStream.readGamma();
tempOffsetLengthArray[j] = ref;
}
entry.setOffsetLengths(i, tempOffsetLengthArray);
}
offset= readCodeStream.byteLength();
prevWord= word;

View file

@ -214,7 +214,7 @@ public class MergeFactory {
} else {
word1.mapRefs(mappingOld);
word2.mapRefs(mappingAdds);
word1.addWordInfo(word2.getRefs(), word2.getOffsets(), word2.getOffsetCount());
word1.addWordInfo(word2.getRefs(), word2.getOffsets(),word2.getOffsetLengths(), word2.getOffsetCount());
mergeOutput.addWord(word1);
addsInput.moveToNextWordEntry();
oldInput.moveToNextWordEntry();

View file

@ -109,8 +109,9 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
if (typeSpec instanceof IASTClassSpecifier){
IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
char[][] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedNameCharArrays();
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS), baseClassSpec.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = baseClassSpec.getStartingOffset();
int offsetLength = baseClassSpec.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS), offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
} catch (ASTNotImplementedException e) {}
}
@ -122,12 +123,16 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
if (decl instanceof IASTClassSpecifier){
IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),friendClassSpec.getStartingOffset(), 1, ICIndexStorageConstants.OFFSET);
int offset = friendClassSpec.getStartingOffset();
int offsetLength = friendClassSpec.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (decl instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier friendClassSpec = (IASTElaboratedTypeSpecifier) decl;
char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS), friendClassSpec.getStartingOffset(), 1, ICIndexStorageConstants.OFFSET);
int offset = friendClassSpec.getStartingOffset();
int offsetLength = friendClassSpec.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS), offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (decl instanceof IASTFunction){
@ -138,7 +143,9 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
}
this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),CLASS, ICSearchConstants.DECLARATIONS), classSpecification.getStartingOffset(), 1, ICIndexStorageConstants.OFFSET);
int offset = classSpecification.getStartingOffset();
int offsetLength = classSpecification.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),CLASS, ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (classSpecification.getClassKind().equals(ASTClassKind.STRUCT))
{
@ -151,7 +158,9 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
if (typeSpec instanceof IASTClassSpecifier){
IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
char[][] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedNameCharArrays();
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS),baseClassSpec.getStartingOffset(), 1, ICIndexStorageConstants.OFFSET);
int offset = baseClassSpec.getStartingOffset();
int offsetLength = baseClassSpec.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,DERIVED,ICSearchConstants.DECLARATIONS),offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
} catch (ASTNotImplementedException e) {}
}
@ -163,12 +172,16 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
if (decl instanceof IASTClassSpecifier){
IASTClassSpecifier friendClassSpec = (IASTClassSpecifier) decl;
char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),friendClassSpec.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = friendClassSpec.getStartingOffset();
int offsetLength = friendClassSpec.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (decl instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier friendClassSpec = (IASTElaboratedTypeSpecifier) decl;
char[][] baseFullyQualifiedName = friendClassSpec.getFullyQualifiedNameCharArrays();
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),friendClassSpec.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = friendClassSpec.getStartingOffset();
int offsetLength = friendClassSpec.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(baseFullyQualifiedName,FRIEND,ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (decl instanceof IASTFunction){
@ -178,16 +191,23 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
}
}
this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),STRUCT, ICSearchConstants.DECLARATIONS),classSpecification.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = classSpecification.getStartingOffset();
int offsetLength = classSpecification.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),STRUCT, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (classSpecification.getClassKind().equals(ASTClassKind.UNION))
{
this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),UNION, ICSearchConstants.DECLARATIONS),classSpecification.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
{
int offset = classSpecification.getStartingOffset();
int offsetLength = classSpecification.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(classSpecification.getFullyQualifiedNameCharArrays(),UNION, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
public void addEnumerationSpecifier(IASTEnumerationSpecifier enumeration, int fileNumber) {
this.output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.DECLARATIONS),enumeration.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = enumeration.getStartingOffset();
int offsetLength = enumeration.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
Iterator i = enumeration.getEnumerators();
while (i.hasNext())
@ -195,8 +215,10 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
IASTEnumerator en = (IASTEnumerator) i.next();
char[][] enumeratorFullName =
createEnumeratorFullyQualifiedName(en);
this.output.addRef(fileNumber, encodeEntry( enumeratorFullName, ENUMTOR_DECL, ENUMTOR_DECL_LENGTH ),en.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
offset = en.getStartingOffset();
offsetLength = en.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry( enumeratorFullName, ENUMTOR_DECL, ENUMTOR_DECL_LENGTH ),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
@ -215,70 +237,98 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
}
public void addEnumeratorReference(IASTEnumerator enumerator, int fileNumber) {
this.output.addRef(fileNumber, encodeEntry(createEnumeratorFullyQualifiedName(enumerator),ENUMTOR_REF,ENUMTOR_REF_LENGTH),enumerator.getStartingOffset(), 1, ICIndexStorageConstants.OFFSET);
int offset = enumerator.getStartingOffset();
int offsetLength = enumerator.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(createEnumeratorFullyQualifiedName(enumerator),ENUMTOR_REF,ENUMTOR_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addMacro(IASTMacro macro, int fileNumber) {
char[][] macroName = new char[][] { macro.getNameCharArray() };
this.output.addRef(fileNumber, encodeEntry(macroName,MACRO_DECL,MACRO_DECL_LENGTH), macro.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = macro.getStartingOffset();
int offsetLength = macro.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(macroName,MACRO_DECL,MACRO_DECL_LENGTH), offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addEnumerationReference(IASTEnumerationSpecifier enumeration, int fileNumber) {
this.output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.REFERENCES), enumeration.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = enumeration.getStartingOffset();
int offsetLength = enumeration.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(enumeration.getFullyQualifiedNameCharArrays(), ENUM, ICSearchConstants.REFERENCES), offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addVariable(IASTVariable variable, int fileNumber) {
this.output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.DECLARATIONS), variable.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = variable.getStartingOffset();
int offsetLength = variable.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.DECLARATIONS), offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addVariableReference(IASTVariable variable, int fileNumber) {
this.output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.REFERENCES),variable.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = variable.getStartingOffset();
int offsetLength = variable.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(variable.getFullyQualifiedNameCharArrays(), VAR, ICSearchConstants.REFERENCES),offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addParameterReference( IASTParameterDeclaration parameter, int fileNumber ){
this.output.addRef(fileNumber,encodeTypeEntry( new char[][] { parameter.getNameCharArray() }, VAR, ICSearchConstants.REFERENCES), parameter.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = parameter.getStartingOffset();
int offsetLength = parameter.getEndingOffset() - offset;
this.output.addRef(fileNumber,encodeTypeEntry( new char[][] { parameter.getNameCharArray() }, VAR, ICSearchConstants.REFERENCES), offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addTypedefDeclaration(IASTTypedefDeclaration typedef, int fileNumber) {
this.output.addRef(fileNumber,encodeEntry(typedef.getFullyQualifiedNameCharArrays(), TYPEDEF_DECL, TYPEDEF_DECL_LENGTH),typedef.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = typedef.getStartingOffset();
int offsetLength = typedef.getEndingOffset() - offset;
this.output.addRef(fileNumber,encodeEntry(typedef.getFullyQualifiedNameCharArrays(), TYPEDEF_DECL, TYPEDEF_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addFieldDeclaration(IASTField field, int fileNumber) {
this.output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_DECL,FIELD_DECL_LENGTH),field.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = field.getStartingOffset();
int offsetLength = field.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_DECL,FIELD_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addFieldReference(IASTField field, int fileNumber) {
this.output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_REF,FIELD_REF_LENGTH),field.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = field.getStartingOffset();
int offsetLength = field.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(field.getFullyQualifiedNameCharArrays(),FIELD_REF,FIELD_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addMethodDeclaration(IASTMethod method, int fileNumber) {
this.output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_DECL,METHOD_DECL_LENGTH),method.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = method.getStartingOffset();
int offsetLength = method.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_DECL,METHOD_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
Iterator i=method.getParameters();
while (i.hasNext()){
Object parm = i.next();
if (parm instanceof IASTParameterDeclaration){
IASTParameterDeclaration parmDecl = (IASTParameterDeclaration) parm;
this.output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),parmDecl.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
offset = parmDecl.getStartingOffset();
offsetLength = parmDecl.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
}
public void addMethodReference(IASTMethod method, int fileNumber) {
this.output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_REF,METHOD_REF_LENGTH),method.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = method.getStartingOffset();
int offsetLength = method.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(method.getFullyQualifiedNameCharArrays(),METHOD_REF,METHOD_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType, int fileNumber) {
int offset = elaboratedType.getStartingOffset();
int offsetLength = elaboratedType.getEndingOffset() - offset;
if (elaboratedType.getClassKind().equals(ASTClassKind.CLASS))
{
this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_CLASS, ICSearchConstants.DECLARATIONS),elaboratedType.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_CLASS, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (elaboratedType.getClassKind().equals(ASTClassKind.STRUCT))
{
this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_STRUCT, ICSearchConstants.DECLARATIONS),elaboratedType.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_STRUCT, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (elaboratedType.getClassKind().equals(ASTClassKind.UNION))
{
this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_UNION, ICSearchConstants.DECLARATIONS),elaboratedType.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber,encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_UNION, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
@ -297,20 +347,27 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
}
public void addFunctionDeclaration(IASTFunction function, int fileNumber){
this.output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_DECL,FUNCTION_DECL_LENGTH),function.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = function.getStartingOffset();
int offsetLength = function.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_DECL,FUNCTION_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
Iterator i=function.getParameters();
while (i.hasNext()){
Object parm = i.next();
if (parm instanceof IASTParameterDeclaration){
IASTParameterDeclaration parmDecl = (IASTParameterDeclaration) parm;
this.output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),parmDecl.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
offset = parmDecl.getStartingOffset();
offsetLength = parmDecl.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeTypeEntry(new char[][]{parmDecl.getNameCharArray()}, VAR, ICSearchConstants.DECLARATIONS),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
}
public void addFunctionReference(IASTFunction function, int fileNumber){
this.output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_REF,FUNCTION_REF_LENGTH),function.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = function.getStartingOffset();
int offsetLength = function.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(function.getFullyQualifiedNameCharArrays(),FUNCTION_REF,FUNCTION_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addNameReference(){
@ -318,15 +375,21 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
}
public void addNamespaceDefinition(IASTNamespaceDefinition namespace, int fileNumber){
this.output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_DECL,NAMESPACE_DECL_LENGTH),namespace.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = namespace.getStartingOffset();
int offsetLength = namespace.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_DECL,NAMESPACE_DECL_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addNamespaceReference(IASTNamespaceDefinition namespace, int fileNumber) {
this.output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_REF,NAMESPACE_REF_LENGTH),namespace.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = namespace.getStartingOffset();
int offsetLength = namespace.getEndingOffset() - offset;
this.output.addRef(fileNumber, encodeEntry(namespace.getFullyQualifiedNameCharArrays(),NAMESPACE_REF,NAMESPACE_REF_LENGTH),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
public void addTypedefReference( IASTTypedefDeclaration typedef, int fileNumber ){
this.output.addRef(fileNumber,encodeTypeEntry( typedef.getFullyQualifiedNameCharArrays(), TYPEDEF, ICSearchConstants.REFERENCES),typedef.getStartingOffset(),1, ICIndexStorageConstants.OFFSET);
int offset = typedef.getStartingOffset();
int offsetLength = typedef.getEndingOffset() - offset;
this.output.addRef(fileNumber,encodeTypeEntry( typedef.getFullyQualifiedNameCharArrays(), TYPEDEF, ICSearchConstants.REFERENCES),offset, offsetLength, ICIndexStorageConstants.OFFSET);
}
private void addSuperTypeReference(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, char classOrInterface, char[] superTypeName, char superClassOrInterface){
@ -341,6 +404,7 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
char[][] fullyQualifiedName = null;
ASTClassKind classKind = null;
int offset=0;
int offsetLength=1;
if (reference instanceof IASTClassSpecifier){
IASTClassSpecifier classRef = (IASTClassSpecifier) reference;
@ -353,31 +417,33 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
classKind = typeRef.getClassKind();
offset=typeRef.getStartingOffset();
offsetLength=typeRef.getEndingOffset()-offset;
}
if (classKind.equals(ASTClassKind.CLASS))
{
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,CLASS, ICSearchConstants.REFERENCES),offset,1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,CLASS, ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (classKind.equals(ASTClassKind.STRUCT))
{
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,STRUCT,ICSearchConstants.REFERENCES),offset,1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,STRUCT,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (classKind.equals(ASTClassKind.UNION))
{
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES),offset,1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
public void addForwardClassReference(IASTTypeSpecifier reference, int fileNumber){
char[][] fullyQualifiedName = null;
ASTClassKind classKind = null;
int offset=0;
int offsetLength=1;
if (reference instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
classKind = typeRef.getClassKind();
offset=typeRef.getStartingOffset();
offsetLength=typeRef.getEndingOffset() - offset;
}
if (classKind == null)
@ -385,15 +451,15 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
if (classKind.equals(ASTClassKind.CLASS))
{
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_CLASS, ICSearchConstants.REFERENCES),offset,1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_CLASS, ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (classKind.equals(ASTClassKind.STRUCT))
{
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_STRUCT,ICSearchConstants.REFERENCES),offset,1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_STRUCT,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
else if (classKind.equals(ASTClassKind.UNION))
{
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_UNION,ICSearchConstants.REFERENCES),offset,1, ICIndexStorageConstants.OFFSET);
this.output.addRef(fileNumber, encodeTypeEntry(fullyQualifiedName,FWD_UNION,ICSearchConstants.REFERENCES),offset,offsetLength, ICIndexStorageConstants.OFFSET);
}
}
/**

View file

@ -214,18 +214,20 @@ public class IndexerNodeLeaf implements IAdaptable {
//offsets
int[][]offsets = entryResult.getOffsets();
int[][]offsetLengths = entryResult.getOffsetLengths();
if (offsets != null){
for (int j=0; j<offsets.length; j++){
String id = OFFSETS_NUMBER + j;
String offsetString = ""; //$NON-NLS-1$
for (int k=0; k<offsets[j].length; k++){
String rawOffset = String.valueOf(offsets[j][k]) ;
String offsetLocation = String.valueOf(offsetLengths[j][k]);
switch(rawOffset.charAt(0)){
case '1':
offsetString += OFFSETS_LINE + rawOffset.substring(1) + " "; //$NON-NLS-1$
break;
case '2':
offsetString += OFFSETS_OFFSET + rawOffset.substring(1) + " "; //$NON-NLS-1$
offsetString += OFFSETS_OFFSET + rawOffset.substring(1) + ":" + offsetLocation + " "; //$NON-NLS-1$ //$NON-NLS-2$
break;
}