diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java index e2e0bbb90a3..41e02cd5859 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexerOffsetTests.java @@ -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}); diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java index 6f47e1e3928..350edb0b082 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/SourceIndexerTests.java @@ -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$ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IEntryResult.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IEntryResult.java index 95f6c60b796..29b5bc37a03 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IEntryResult.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/IEntryResult.java @@ -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(); } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java index b56181d5ba0..fd75d81e77b 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/EntryResult.java @@ -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; +} } diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java index 2c6ebce3db3..87a48ea8848 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/ICIndexStorageConstants.java @@ -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. */ diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java index 133e87dadbe..167e375d3c8 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/InMemoryIndex.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java index f7787127afd..66ca6413382 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/IndexerOutput.java @@ -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. diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java index 4c98b7b7f6a..f2a70ca68b2 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/cindexstorage/WordEntry.java @@ -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