@@ -249,7 +249,16 @@ namespace SrcMgr {
249
249
}
250
250
};
251
251
} // end SrcMgr namespace.
252
-
252
+
253
+ // / \brief External source of source location entries.
254
+ class ExternalSLocEntrySource {
255
+ public:
256
+ virtual ~ExternalSLocEntrySource ();
257
+
258
+ // / \brief Read the source location entry with index ID.
259
+ virtual void ReadSLocEntry (unsigned ID) = 0;
260
+ };
261
+
253
262
// / SourceManager - This file handles loading and caching of source files into
254
263
// / memory. This object owns the MemoryBuffer objects for all of the loaded
255
264
// / files and assigns unique FileID's for each unique #include chain.
@@ -281,7 +290,15 @@ class SourceManager {
281
290
// / NextOffset - This is the next available offset that a new SLocEntry can
282
291
// / start at. It is SLocEntryTable.back().getOffset()+size of back() entry.
283
292
unsigned NextOffset;
284
-
293
+
294
+ // / \brief If source location entries are being lazily loaded from
295
+ // / an external source, this vector indicates whether the Ith source
296
+ // / location entry has already been loaded from the external storage.
297
+ std::vector<bool > SLocEntryLoaded;
298
+
299
+ // / \brief An external source for source location entries.
300
+ ExternalSLocEntrySource *ExternalSLocEntries;
301
+
285
302
// / LastFileIDLookup - This is a one-entry cache to speed up getFileID.
286
303
// / LastFileIDLookup records the last FileID looked up or created, because it
287
304
// / is very common to look up many tokens from the same file.
@@ -308,7 +325,9 @@ class SourceManager {
308
325
explicit SourceManager (const SourceManager&);
309
326
void operator =(const SourceManager&);
310
327
public:
311
- SourceManager () : LineTable(0 ), NumLinearScans(0 ), NumBinaryProbes(0 ) {
328
+ SourceManager ()
329
+ : ExternalSLocEntries(0 ), LineTable(0 ), NumLinearScans(0 ),
330
+ NumBinaryProbes (0 ) {
312
331
clearIDTables ();
313
332
}
314
333
~SourceManager ();
@@ -337,19 +356,25 @@ class SourceManager {
337
356
// / createFileID - Create a new FileID that represents the specified file
338
357
// / being #included from the specified IncludePosition. This returns 0 on
339
358
// / error and translates NULL into standard input.
359
+ // / PreallocateID should be non-zero to specify which a pre-allocated,
360
+ // / lazily computed source location is being filled in by this operation.
340
361
FileID createFileID (const FileEntry *SourceFile, SourceLocation IncludePos,
341
- SrcMgr::CharacteristicKind FileCharacter) {
362
+ SrcMgr::CharacteristicKind FileCharacter,
363
+ unsigned PreallocatedID = 0 ,
364
+ unsigned Offset = 0 ) {
342
365
const SrcMgr::ContentCache *IR = getOrCreateContentCache (SourceFile);
343
366
if (IR == 0 ) return FileID (); // Error opening file?
344
- return createFileID (IR, IncludePos, FileCharacter);
367
+ return createFileID (IR, IncludePos, FileCharacter, PreallocatedID, Offset );
345
368
}
346
369
347
370
// / createFileIDForMemBuffer - Create a new FileID that represents the
348
371
// / specified memory buffer. This does no caching of the buffer and takes
349
372
// / ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.
350
- FileID createFileIDForMemBuffer (const llvm::MemoryBuffer *Buffer) {
373
+ FileID createFileIDForMemBuffer (const llvm::MemoryBuffer *Buffer,
374
+ unsigned PreallocatedID = 0 ,
375
+ unsigned Offset = 0 ) {
351
376
return createFileID (createMemBufferContentCache (Buffer), SourceLocation (),
352
- SrcMgr::C_User);
377
+ SrcMgr::C_User, PreallocatedID, Offset );
353
378
}
354
379
355
380
// / createMainFileIDForMembuffer - Create the FileID for a memory buffer
@@ -367,7 +392,9 @@ class SourceManager {
367
392
SourceLocation createInstantiationLoc (SourceLocation Loc,
368
393
SourceLocation InstantiationLocStart,
369
394
SourceLocation InstantiationLocEnd,
370
- unsigned TokLength);
395
+ unsigned TokLength,
396
+ unsigned PreallocatedID = 0 ,
397
+ unsigned Offset = 0 );
371
398
372
399
// ===--------------------------------------------------------------------===//
373
400
// FileID manipulation methods.
@@ -411,8 +438,9 @@ class SourceManager {
411
438
// / getLocForStartOfFile - Return the source location corresponding to the
412
439
// / first byte of the specified file.
413
440
SourceLocation getLocForStartOfFile (FileID FID) const {
414
- assert (FID.ID < SLocEntryTable.size () && SLocEntryTable[FID.ID ].isFile ());
415
- unsigned FileOffset = SLocEntryTable[FID.ID ].getOffset ();
441
+ assert (FID.ID < SLocEntryTable.size () && " FileID out of range" );
442
+ assert (getSLocEntry (FID).isFile () && " FileID is not a file" );
443
+ unsigned FileOffset = getSLocEntry (FID).getOffset ();
416
444
return SourceLocation::getFileLoc (FileOffset);
417
445
}
418
446
@@ -616,11 +644,21 @@ class SourceManager {
616
644
617
645
const SrcMgr::SLocEntry &getSLocEntry (FileID FID) const {
618
646
assert (FID.ID < SLocEntryTable.size () && " Invalid id" );
647
+ if (ExternalSLocEntries &&
648
+ FID.ID < SLocEntryLoaded.size () &&
649
+ !SLocEntryLoaded[FID.ID ])
650
+ ExternalSLocEntries->ReadSLocEntry (FID.ID );
619
651
return SLocEntryTable[FID.ID ];
620
652
}
621
653
622
654
unsigned getNextOffset () const { return NextOffset; }
623
655
656
+ // / \brief Preallocate some number of source location entries, which
657
+ // / will be loaded as needed from the given external source.
658
+ void PreallocateSLocEntries (ExternalSLocEntrySource *Source,
659
+ unsigned NumSLocEntries,
660
+ unsigned NextOffset);
661
+
624
662
private:
625
663
// / isOffsetInFileID - Return true if the specified FileID contains the
626
664
// / specified SourceLocation offset. This is a very hot method.
@@ -632,15 +670,18 @@ class SourceManager {
632
670
// If this is the last entry than it does. Otherwise, the entry after it
633
671
// has to not include it.
634
672
if (FID.ID +1 == SLocEntryTable.size ()) return true ;
635
- return SLocOffset < SLocEntryTable[FID.ID +1 ].getOffset ();
673
+
674
+ return SLocOffset < getSLocEntry (FileID::get (FID.ID +1 )).getOffset ();
636
675
}
637
676
638
677
// / createFileID - Create a new fileID for the specified ContentCache and
639
678
// / include position. This works regardless of whether the ContentCache
640
679
// / corresponds to a file or some other input source.
641
680
FileID createFileID (const SrcMgr::ContentCache* File,
642
681
SourceLocation IncludePos,
643
- SrcMgr::CharacteristicKind DirCharacter);
682
+ SrcMgr::CharacteristicKind DirCharacter,
683
+ unsigned PreallocatedID = 0 ,
684
+ unsigned Offset = 0 );
644
685
645
686
const SrcMgr::ContentCache *
646
687
getOrCreateContentCache (const FileEntry *SourceFile);
0 commit comments