blob: 8cc7a8438d2171b027cf6a1aa64b7ca428a83013 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- SourceManager.cpp - Track and cache source files -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the SourceManager interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/SourceManager.h"
Douglas Gregord4f77aa2009-04-13 15:31:25 +000015#include "clang/Basic/SourceManagerInternals.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Basic/FileManager.h"
Chris Lattner5e36a7a2007-07-24 05:57:19 +000017#include "llvm/Support/Compiler.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "llvm/Support/MemoryBuffer.h"
Chris Lattnerd57a7ef2009-08-23 22:45:33 +000019#include "llvm/Support/raw_ostream.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "llvm/System/Path.h"
21#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000022using namespace clang;
23using namespace SrcMgr;
24using llvm::MemoryBuffer;
25
Chris Lattner23b5dc62009-02-04 00:40:31 +000026//===----------------------------------------------------------------------===//
Chris Lattnerde7aeef2009-01-26 00:43:02 +000027// SourceManager Helper Classes
Chris Lattner23b5dc62009-02-04 00:40:31 +000028//===----------------------------------------------------------------------===//
Chris Lattnerde7aeef2009-01-26 00:43:02 +000029
Ted Kremenek78d85f52007-10-30 21:08:08 +000030ContentCache::~ContentCache() {
31 delete Buffer;
Reid Spencer5f016e22007-07-11 17:01:13 +000032}
33
Ted Kremenekc16c2082009-01-06 01:55:26 +000034/// getSizeBytesMapped - Returns the number of bytes actually mapped for
35/// this ContentCache. This can be 0 if the MemBuffer was not actually
36/// instantiated.
37unsigned ContentCache::getSizeBytesMapped() const {
38 return Buffer ? Buffer->getBufferSize() : 0;
39}
40
41/// getSize - Returns the size of the content encapsulated by this ContentCache.
42/// This can be the size of the source file or the size of an arbitrary
43/// scratch buffer. If the ContentCache encapsulates a source file, that
Douglas Gregor29684422009-12-02 06:49:09 +000044/// file is not lazily brought in from disk to satisfy this query.
Ted Kremenekc16c2082009-01-06 01:55:26 +000045unsigned ContentCache::getSize() const {
Douglas Gregorb657f112009-09-22 21:11:38 +000046 return Buffer ? Buffer->getBufferSize() : Entry->getSize();
Ted Kremenekc16c2082009-01-06 01:55:26 +000047}
48
Douglas Gregor29684422009-12-02 06:49:09 +000049void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B) {
50 if (B == Buffer)
51 return;
52
53 delete Buffer;
54 Buffer = B;
55}
56
Chris Lattner39d98412009-12-01 22:52:33 +000057const llvm::MemoryBuffer *ContentCache::getBuffer(std::string *ErrorStr) const {
Ted Kremenek5b034ad2009-01-06 22:43:04 +000058 // Lazily create the Buffer for ContentCaches that wrap files.
59 if (!Buffer && Entry) {
60 // FIXME: Should we support a way to not have to do this check over
61 // and over if we cannot open the file?
Chris Lattner39d98412009-12-01 22:52:33 +000062 Buffer = MemoryBuffer::getFile(Entry->getName(), ErrorStr,Entry->getSize());
Ted Kremenek5b034ad2009-01-06 22:43:04 +000063 }
Ted Kremenekc16c2082009-01-06 01:55:26 +000064 return Buffer;
65}
66
Chris Lattner5b9a5042009-01-26 07:57:50 +000067unsigned LineTableInfo::getLineTableFilenameID(const char *Ptr, unsigned Len) {
68 // Look up the filename in the string table, returning the pre-existing value
69 // if it exists.
Mike Stump1eb44332009-09-09 15:08:12 +000070 llvm::StringMapEntry<unsigned> &Entry =
Chris Lattner5b9a5042009-01-26 07:57:50 +000071 FilenameIDs.GetOrCreateValue(Ptr, Ptr+Len, ~0U);
72 if (Entry.getValue() != ~0U)
73 return Entry.getValue();
Mike Stump1eb44332009-09-09 15:08:12 +000074
Chris Lattner5b9a5042009-01-26 07:57:50 +000075 // Otherwise, assign this the next available ID.
76 Entry.setValue(FilenamesByID.size());
77 FilenamesByID.push_back(&Entry);
78 return FilenamesByID.size()-1;
79}
80
Chris Lattnerac50e342009-02-03 22:13:05 +000081/// AddLineNote - Add a line note to the line table that indicates that there
82/// is a #line at the specified FID/Offset location which changes the presumed
83/// location to LineNo/FilenameID.
Chris Lattner23b5dc62009-02-04 00:40:31 +000084void LineTableInfo::AddLineNote(unsigned FID, unsigned Offset,
Chris Lattnerac50e342009-02-03 22:13:05 +000085 unsigned LineNo, int FilenameID) {
Chris Lattner23b5dc62009-02-04 00:40:31 +000086 std::vector<LineEntry> &Entries = LineEntries[FID];
Mike Stump1eb44332009-09-09 15:08:12 +000087
Chris Lattner23b5dc62009-02-04 00:40:31 +000088 assert((Entries.empty() || Entries.back().FileOffset < Offset) &&
89 "Adding line entries out of order!");
Mike Stump1eb44332009-09-09 15:08:12 +000090
Chris Lattner9d79eba2009-02-04 05:21:58 +000091 SrcMgr::CharacteristicKind Kind = SrcMgr::C_User;
Chris Lattner137b6a62009-02-04 06:25:26 +000092 unsigned IncludeOffset = 0;
Mike Stump1eb44332009-09-09 15:08:12 +000093
Chris Lattner9d79eba2009-02-04 05:21:58 +000094 if (!Entries.empty()) {
95 // If this is a '#line 4' after '#line 42 "foo.h"', make sure to remember
96 // that we are still in "foo.h".
97 if (FilenameID == -1)
98 FilenameID = Entries.back().FilenameID;
Mike Stump1eb44332009-09-09 15:08:12 +000099
Chris Lattner137b6a62009-02-04 06:25:26 +0000100 // If we are after a line marker that switched us to system header mode, or
101 // that set #include information, preserve it.
Chris Lattner9d79eba2009-02-04 05:21:58 +0000102 Kind = Entries.back().FileKind;
Chris Lattner137b6a62009-02-04 06:25:26 +0000103 IncludeOffset = Entries.back().IncludeOffset;
Chris Lattner9d79eba2009-02-04 05:21:58 +0000104 }
Mike Stump1eb44332009-09-09 15:08:12 +0000105
Chris Lattner137b6a62009-02-04 06:25:26 +0000106 Entries.push_back(LineEntry::get(Offset, LineNo, FilenameID, Kind,
107 IncludeOffset));
Chris Lattnerac50e342009-02-03 22:13:05 +0000108}
109
Chris Lattner9d79eba2009-02-04 05:21:58 +0000110/// AddLineNote This is the same as the previous version of AddLineNote, but is
111/// used for GNU line markers. If EntryExit is 0, then this doesn't change the
112/// presumed #include stack. If it is 1, this is a file entry, if it is 2 then
113/// this is a file exit. FileKind specifies whether this is a system header or
114/// extern C system header.
115void LineTableInfo::AddLineNote(unsigned FID, unsigned Offset,
116 unsigned LineNo, int FilenameID,
117 unsigned EntryExit,
118 SrcMgr::CharacteristicKind FileKind) {
119 assert(FilenameID != -1 && "Unspecified filename should use other accessor");
Mike Stump1eb44332009-09-09 15:08:12 +0000120
Chris Lattner9d79eba2009-02-04 05:21:58 +0000121 std::vector<LineEntry> &Entries = LineEntries[FID];
Mike Stump1eb44332009-09-09 15:08:12 +0000122
Chris Lattner9d79eba2009-02-04 05:21:58 +0000123 assert((Entries.empty() || Entries.back().FileOffset < Offset) &&
124 "Adding line entries out of order!");
125
Chris Lattner137b6a62009-02-04 06:25:26 +0000126 unsigned IncludeOffset = 0;
127 if (EntryExit == 0) { // No #include stack change.
128 IncludeOffset = Entries.empty() ? 0 : Entries.back().IncludeOffset;
129 } else if (EntryExit == 1) {
130 IncludeOffset = Offset-1;
131 } else if (EntryExit == 2) {
132 assert(!Entries.empty() && Entries.back().IncludeOffset &&
133 "PPDirectives should have caught case when popping empty include stack");
Mike Stump1eb44332009-09-09 15:08:12 +0000134
Chris Lattner137b6a62009-02-04 06:25:26 +0000135 // Get the include loc of the last entries' include loc as our include loc.
136 IncludeOffset = 0;
137 if (const LineEntry *PrevEntry =
138 FindNearestLineEntry(FID, Entries.back().IncludeOffset))
139 IncludeOffset = PrevEntry->IncludeOffset;
140 }
Mike Stump1eb44332009-09-09 15:08:12 +0000141
Chris Lattner137b6a62009-02-04 06:25:26 +0000142 Entries.push_back(LineEntry::get(Offset, LineNo, FilenameID, FileKind,
143 IncludeOffset));
Chris Lattner9d79eba2009-02-04 05:21:58 +0000144}
145
146
Chris Lattner3cd949c2009-02-04 01:55:42 +0000147/// FindNearestLineEntry - Find the line entry nearest to FID that is before
148/// it. If there is no line entry before Offset in FID, return null.
Mike Stump1eb44332009-09-09 15:08:12 +0000149const LineEntry *LineTableInfo::FindNearestLineEntry(unsigned FID,
Chris Lattner3cd949c2009-02-04 01:55:42 +0000150 unsigned Offset) {
151 const std::vector<LineEntry> &Entries = LineEntries[FID];
152 assert(!Entries.empty() && "No #line entries for this FID after all!");
153
Chris Lattner6c1fbe02009-02-04 04:46:59 +0000154 // It is very common for the query to be after the last #line, check this
155 // first.
156 if (Entries.back().FileOffset <= Offset)
157 return &Entries.back();
Chris Lattner3cd949c2009-02-04 01:55:42 +0000158
Chris Lattner6c1fbe02009-02-04 04:46:59 +0000159 // Do a binary search to find the maximal element that is still before Offset.
160 std::vector<LineEntry>::const_iterator I =
161 std::upper_bound(Entries.begin(), Entries.end(), Offset);
162 if (I == Entries.begin()) return 0;
163 return &*--I;
Chris Lattner3cd949c2009-02-04 01:55:42 +0000164}
Chris Lattnerac50e342009-02-03 22:13:05 +0000165
Douglas Gregorbd945002009-04-13 16:31:14 +0000166/// \brief Add a new line entry that has already been encoded into
167/// the internal representation of the line table.
Mike Stump1eb44332009-09-09 15:08:12 +0000168void LineTableInfo::AddEntry(unsigned FID,
Douglas Gregorbd945002009-04-13 16:31:14 +0000169 const std::vector<LineEntry> &Entries) {
170 LineEntries[FID] = Entries;
171}
Chris Lattnerac50e342009-02-03 22:13:05 +0000172
Chris Lattner5b9a5042009-01-26 07:57:50 +0000173/// getLineTableFilenameID - Return the uniqued ID for the specified filename.
Mike Stump1eb44332009-09-09 15:08:12 +0000174///
Chris Lattner5b9a5042009-01-26 07:57:50 +0000175unsigned SourceManager::getLineTableFilenameID(const char *Ptr, unsigned Len) {
176 if (LineTable == 0)
177 LineTable = new LineTableInfo();
178 return LineTable->getLineTableFilenameID(Ptr, Len);
179}
180
181
Chris Lattner4c4ea172009-02-03 21:52:55 +0000182/// AddLineNote - Add a line note to the line table for the FileID and offset
183/// specified by Loc. If FilenameID is -1, it is considered to be
184/// unspecified.
185void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo,
186 int FilenameID) {
Chris Lattnerac50e342009-02-03 22:13:05 +0000187 std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000188
Chris Lattnerac50e342009-02-03 22:13:05 +0000189 const SrcMgr::FileInfo &FileInfo = getSLocEntry(LocInfo.first).getFile();
190
191 // Remember that this file has #line directives now if it doesn't already.
192 const_cast<SrcMgr::FileInfo&>(FileInfo).setHasLineDirectives();
Mike Stump1eb44332009-09-09 15:08:12 +0000193
Chris Lattnerac50e342009-02-03 22:13:05 +0000194 if (LineTable == 0)
195 LineTable = new LineTableInfo();
Chris Lattner23b5dc62009-02-04 00:40:31 +0000196 LineTable->AddLineNote(LocInfo.first.ID, LocInfo.second, LineNo, FilenameID);
Chris Lattner4c4ea172009-02-03 21:52:55 +0000197}
198
Chris Lattner9d79eba2009-02-04 05:21:58 +0000199/// AddLineNote - Add a GNU line marker to the line table.
200void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo,
201 int FilenameID, bool IsFileEntry,
202 bool IsFileExit, bool IsSystemHeader,
203 bool IsExternCHeader) {
204 // If there is no filename and no flags, this is treated just like a #line,
205 // which does not change the flags of the previous line marker.
206 if (FilenameID == -1) {
207 assert(!IsFileEntry && !IsFileExit && !IsSystemHeader && !IsExternCHeader &&
208 "Can't set flags without setting the filename!");
209 return AddLineNote(Loc, LineNo, FilenameID);
210 }
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Chris Lattner9d79eba2009-02-04 05:21:58 +0000212 std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
213 const SrcMgr::FileInfo &FileInfo = getSLocEntry(LocInfo.first).getFile();
Mike Stump1eb44332009-09-09 15:08:12 +0000214
Chris Lattner9d79eba2009-02-04 05:21:58 +0000215 // Remember that this file has #line directives now if it doesn't already.
216 const_cast<SrcMgr::FileInfo&>(FileInfo).setHasLineDirectives();
Mike Stump1eb44332009-09-09 15:08:12 +0000217
Chris Lattner9d79eba2009-02-04 05:21:58 +0000218 if (LineTable == 0)
219 LineTable = new LineTableInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Chris Lattner9d79eba2009-02-04 05:21:58 +0000221 SrcMgr::CharacteristicKind FileKind;
222 if (IsExternCHeader)
223 FileKind = SrcMgr::C_ExternCSystem;
224 else if (IsSystemHeader)
225 FileKind = SrcMgr::C_System;
226 else
227 FileKind = SrcMgr::C_User;
Mike Stump1eb44332009-09-09 15:08:12 +0000228
Chris Lattner9d79eba2009-02-04 05:21:58 +0000229 unsigned EntryExit = 0;
230 if (IsFileEntry)
231 EntryExit = 1;
232 else if (IsFileExit)
233 EntryExit = 2;
Mike Stump1eb44332009-09-09 15:08:12 +0000234
Chris Lattner9d79eba2009-02-04 05:21:58 +0000235 LineTable->AddLineNote(LocInfo.first.ID, LocInfo.second, LineNo, FilenameID,
236 EntryExit, FileKind);
237}
238
Douglas Gregorbd945002009-04-13 16:31:14 +0000239LineTableInfo &SourceManager::getLineTable() {
240 if (LineTable == 0)
241 LineTable = new LineTableInfo();
242 return *LineTable;
243}
Chris Lattner4c4ea172009-02-03 21:52:55 +0000244
Chris Lattner23b5dc62009-02-04 00:40:31 +0000245//===----------------------------------------------------------------------===//
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000246// Private 'Create' methods.
Chris Lattner23b5dc62009-02-04 00:40:31 +0000247//===----------------------------------------------------------------------===//
Ted Kremenekc16c2082009-01-06 01:55:26 +0000248
Chris Lattner5b9a5042009-01-26 07:57:50 +0000249SourceManager::~SourceManager() {
250 delete LineTable;
Mike Stump1eb44332009-09-09 15:08:12 +0000251
Chris Lattner0d0bf8c2009-02-03 07:30:45 +0000252 // Delete FileEntry objects corresponding to content caches. Since the actual
253 // content cache objects are bump pointer allocated, we just have to run the
254 // dtors, but we call the deallocate method for completeness.
255 for (unsigned i = 0, e = MemBufferInfos.size(); i != e; ++i) {
256 MemBufferInfos[i]->~ContentCache();
257 ContentCacheAlloc.Deallocate(MemBufferInfos[i]);
258 }
259 for (llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::iterator
260 I = FileInfos.begin(), E = FileInfos.end(); I != E; ++I) {
261 I->second->~ContentCache();
262 ContentCacheAlloc.Deallocate(I->second);
263 }
Chris Lattner5b9a5042009-01-26 07:57:50 +0000264}
265
266void SourceManager::clearIDTables() {
267 MainFileID = FileID();
268 SLocEntryTable.clear();
269 LastLineNoFileIDQuery = FileID();
270 LastLineNoContentCache = 0;
271 LastFileIDLookup = FileID();
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Chris Lattner5b9a5042009-01-26 07:57:50 +0000273 if (LineTable)
274 LineTable->clear();
Mike Stump1eb44332009-09-09 15:08:12 +0000275
Chris Lattner5b9a5042009-01-26 07:57:50 +0000276 // Use up FileID #0 as an invalid instantiation.
277 NextOffset = 0;
Chris Lattnere7fb4842009-02-15 20:52:18 +0000278 createInstantiationLoc(SourceLocation(),SourceLocation(),SourceLocation(), 1);
Chris Lattner5b9a5042009-01-26 07:57:50 +0000279}
280
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000281/// getOrCreateContentCache - Create or return a cached ContentCache for the
282/// specified file.
283const ContentCache *
284SourceManager::getOrCreateContentCache(const FileEntry *FileEnt) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000285 assert(FileEnt && "Didn't specify a file entry to use?");
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Reid Spencer5f016e22007-07-11 17:01:13 +0000287 // Do we already have information about this file?
Chris Lattner0d0bf8c2009-02-03 07:30:45 +0000288 ContentCache *&Entry = FileInfos[FileEnt];
289 if (Entry) return Entry;
Mike Stump1eb44332009-09-09 15:08:12 +0000290
Chris Lattner00282d62009-02-03 07:41:46 +0000291 // Nope, create a new Cache entry. Make sure it is at least 8-byte aligned
292 // so that FileInfo can use the low 3 bits of the pointer for its own
293 // nefarious purposes.
294 unsigned EntryAlign = llvm::AlignOf<ContentCache>::Alignment;
295 EntryAlign = std::max(8U, EntryAlign);
296 Entry = ContentCacheAlloc.Allocate<ContentCache>(1, EntryAlign);
Chris Lattner0d0bf8c2009-02-03 07:30:45 +0000297 new (Entry) ContentCache(FileEnt);
298 return Entry;
Reid Spencer5f016e22007-07-11 17:01:13 +0000299}
300
301
Ted Kremenekd1c0eee2007-10-31 17:53:38 +0000302/// createMemBufferContentCache - Create a new ContentCache for the specified
303/// memory buffer. This does no caching.
Ted Kremenek78d85f52007-10-30 21:08:08 +0000304const ContentCache*
305SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) {
Chris Lattner00282d62009-02-03 07:41:46 +0000306 // Add a new ContentCache to the MemBufferInfos list and return it. Make sure
307 // it is at least 8-byte aligned so that FileInfo can use the low 3 bits of
308 // the pointer for its own nefarious purposes.
309 unsigned EntryAlign = llvm::AlignOf<ContentCache>::Alignment;
310 EntryAlign = std::max(8U, EntryAlign);
311 ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(1, EntryAlign);
Chris Lattner0d0bf8c2009-02-03 07:30:45 +0000312 new (Entry) ContentCache();
313 MemBufferInfos.push_back(Entry);
314 Entry->setBuffer(Buffer);
315 return Entry;
Reid Spencer5f016e22007-07-11 17:01:13 +0000316}
317
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000318void SourceManager::PreallocateSLocEntries(ExternalSLocEntrySource *Source,
319 unsigned NumSLocEntries,
320 unsigned NextOffset) {
321 ExternalSLocEntries = Source;
322 this->NextOffset = NextOffset;
323 SLocEntryLoaded.resize(NumSLocEntries + 1);
324 SLocEntryLoaded[0] = true;
325 SLocEntryTable.resize(SLocEntryTable.size() + NumSLocEntries);
326}
327
Douglas Gregor2bf1eb02009-04-27 21:28:04 +0000328void SourceManager::ClearPreallocatedSLocEntries() {
329 unsigned I = 0;
330 for (unsigned N = SLocEntryLoaded.size(); I != N; ++I)
331 if (!SLocEntryLoaded[I])
332 break;
333
334 // We've already loaded all preallocated source location entries.
335 if (I == SLocEntryLoaded.size())
336 return;
337
338 // Remove everything from location I onward.
339 SLocEntryTable.resize(I);
340 SLocEntryLoaded.clear();
341 ExternalSLocEntries = 0;
342}
343
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000344
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000345//===----------------------------------------------------------------------===//
346// Methods to create new FileID's and instantiations.
347//===----------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000348
Nico Weber48002c82008-09-29 00:25:48 +0000349/// createFileID - Create a new fileID for the specified ContentCache and
Ted Kremenek0d892d82007-10-30 22:57:35 +0000350/// include position. This works regardless of whether the ContentCache
351/// corresponds to a file or some other input source.
Chris Lattner2b2453a2009-01-17 06:22:33 +0000352FileID SourceManager::createFileID(const ContentCache *File,
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000353 SourceLocation IncludePos,
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000354 SrcMgr::CharacteristicKind FileCharacter,
355 unsigned PreallocatedID,
356 unsigned Offset) {
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000357 if (PreallocatedID) {
358 // If we're filling in a preallocated ID, just load in the file
359 // entry and return.
Mike Stump1eb44332009-09-09 15:08:12 +0000360 assert(PreallocatedID < SLocEntryLoaded.size() &&
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000361 "Preallocate ID out-of-range");
Mike Stump1eb44332009-09-09 15:08:12 +0000362 assert(!SLocEntryLoaded[PreallocatedID] &&
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000363 "Source location entry already loaded");
364 assert(Offset && "Preallocate source location cannot have zero offset");
Mike Stump1eb44332009-09-09 15:08:12 +0000365 SLocEntryTable[PreallocatedID]
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000366 = SLocEntry::get(Offset, FileInfo::get(IncludePos, File, FileCharacter));
367 SLocEntryLoaded[PreallocatedID] = true;
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000368 FileID FID = FileID::get(PreallocatedID);
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000369 return LastFileIDLookup = FID;
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000370 }
371
Mike Stump1eb44332009-09-09 15:08:12 +0000372 SLocEntryTable.push_back(SLocEntry::get(NextOffset,
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000373 FileInfo::get(IncludePos, File,
374 FileCharacter)));
Ted Kremenekc16c2082009-01-06 01:55:26 +0000375 unsigned FileSize = File->getSize();
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000376 assert(NextOffset+FileSize+1 > NextOffset && "Ran out of source locations!");
377 NextOffset += FileSize+1;
Mike Stump1eb44332009-09-09 15:08:12 +0000378
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000379 // Set LastFileIDLookup to the newly created file. The next getFileID call is
380 // almost guaranteed to be from that file.
Argyrios Kyrtzidisea703f12009-06-23 00:42:06 +0000381 FileID FID = FileID::get(SLocEntryTable.size()-1);
Argyrios Kyrtzidisea703f12009-06-23 00:42:06 +0000382 return LastFileIDLookup = FID;
Reid Spencer5f016e22007-07-11 17:01:13 +0000383}
384
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000385/// createInstantiationLoc - Return a new SourceLocation that encodes the fact
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000386/// that a token from SpellingLoc should actually be referenced from
Reid Spencer5f016e22007-07-11 17:01:13 +0000387/// InstantiationLoc.
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000388SourceLocation SourceManager::createInstantiationLoc(SourceLocation SpellingLoc,
Chris Lattnere7fb4842009-02-15 20:52:18 +0000389 SourceLocation ILocStart,
390 SourceLocation ILocEnd,
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000391 unsigned TokLength,
392 unsigned PreallocatedID,
393 unsigned Offset) {
Chris Lattnere7fb4842009-02-15 20:52:18 +0000394 InstantiationInfo II = InstantiationInfo::get(ILocStart,ILocEnd, SpellingLoc);
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000395 if (PreallocatedID) {
396 // If we're filling in a preallocated ID, just load in the
397 // instantiation entry and return.
Mike Stump1eb44332009-09-09 15:08:12 +0000398 assert(PreallocatedID < SLocEntryLoaded.size() &&
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000399 "Preallocate ID out-of-range");
Mike Stump1eb44332009-09-09 15:08:12 +0000400 assert(!SLocEntryLoaded[PreallocatedID] &&
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000401 "Source location entry already loaded");
402 assert(Offset && "Preallocate source location cannot have zero offset");
403 SLocEntryTable[PreallocatedID] = SLocEntry::get(Offset, II);
404 SLocEntryLoaded[PreallocatedID] = true;
405 return SourceLocation::getMacroLoc(Offset);
406 }
Chris Lattnere7fb4842009-02-15 20:52:18 +0000407 SLocEntryTable.push_back(SLocEntry::get(NextOffset, II));
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000408 assert(NextOffset+TokLength+1 > NextOffset && "Ran out of source locations!");
409 NextOffset += TokLength+1;
410 return SourceLocation::getMacroLoc(NextOffset-(TokLength+1));
Reid Spencer5f016e22007-07-11 17:01:13 +0000411}
412
Douglas Gregor29684422009-12-02 06:49:09 +0000413const llvm::MemoryBuffer *
414SourceManager::getMemoryBufferForFile(const FileEntry *File) {
415 const SrcMgr::ContentCache *IR = getOrCreateContentCache(File);
416 if (IR == 0)
417 return 0;
418
419 return IR->getBuffer();
420}
421
422bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
423 const llvm::MemoryBuffer *Buffer) {
424 const SrcMgr::ContentCache *IR = getOrCreateContentCache(SourceFile);
425 if (IR == 0)
426 return true;
427
428 const_cast<SrcMgr::ContentCache *>(IR)->replaceBuffer(Buffer);
429 return false;
430}
431
Chris Lattner31530ba2009-01-19 07:32:13 +0000432/// getBufferData - Return a pointer to the start and end of the source buffer
433/// data for the specified FileID.
Chris Lattner2b2453a2009-01-17 06:22:33 +0000434std::pair<const char*, const char*>
435SourceManager::getBufferData(FileID FID) const {
436 const llvm::MemoryBuffer *Buf = getBuffer(FID);
437 return std::make_pair(Buf->getBufferStart(), Buf->getBufferEnd());
438}
439
440
Chris Lattner23b5dc62009-02-04 00:40:31 +0000441//===----------------------------------------------------------------------===//
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000442// SourceLocation manipulation methods.
Chris Lattner23b5dc62009-02-04 00:40:31 +0000443//===----------------------------------------------------------------------===//
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000444
445/// getFileIDSlow - Return the FileID for a SourceLocation. This is a very hot
446/// method that is used for all SourceManager queries that start with a
447/// SourceLocation object. It is responsible for finding the entry in
448/// SLocEntryTable which contains the specified location.
449///
450FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const {
451 assert(SLocOffset && "Invalid FileID");
Mike Stump1eb44332009-09-09 15:08:12 +0000452
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000453 // After the first and second level caches, I see two common sorts of
454 // behavior: 1) a lot of searched FileID's are "near" the cached file location
455 // or are "near" the cached instantiation location. 2) others are just
456 // completely random and may be a very long way away.
457 //
458 // To handle this, we do a linear search for up to 8 steps to catch #1 quickly
459 // then we fall back to a less cache efficient, but more scalable, binary
460 // search to find the location.
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000462 // See if this is near the file point - worst case we start scanning from the
463 // most newly created FileID.
464 std::vector<SrcMgr::SLocEntry>::const_iterator I;
Mike Stump1eb44332009-09-09 15:08:12 +0000465
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000466 if (SLocEntryTable[LastFileIDLookup.ID].getOffset() < SLocOffset) {
467 // Neither loc prunes our search.
468 I = SLocEntryTable.end();
469 } else {
470 // Perhaps it is near the file point.
471 I = SLocEntryTable.begin()+LastFileIDLookup.ID;
472 }
473
474 // Find the FileID that contains this. "I" is an iterator that points to a
475 // FileID whose offset is known to be larger than SLocOffset.
476 unsigned NumProbes = 0;
477 while (1) {
478 --I;
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000479 if (ExternalSLocEntries)
480 getSLocEntry(FileID::get(I - SLocEntryTable.begin()));
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000481 if (I->getOffset() <= SLocOffset) {
482#if 0
483 printf("lin %d -> %d [%s] %d %d\n", SLocOffset,
484 I-SLocEntryTable.begin(),
485 I->isInstantiation() ? "inst" : "file",
486 LastFileIDLookup.ID, int(SLocEntryTable.end()-I));
487#endif
488 FileID Res = FileID::get(I-SLocEntryTable.begin());
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000489
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000490 // If this isn't an instantiation, remember it. We have good locality
491 // across FileID lookups.
492 if (!I->isInstantiation())
493 LastFileIDLookup = Res;
494 NumLinearScans += NumProbes+1;
495 return Res;
496 }
497 if (++NumProbes == 8)
498 break;
499 }
Mike Stump1eb44332009-09-09 15:08:12 +0000500
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000501 // Convert "I" back into an index. We know that it is an entry whose index is
502 // larger than the offset we are looking for.
503 unsigned GreaterIndex = I-SLocEntryTable.begin();
504 // LessIndex - This is the lower bound of the range that we're searching.
505 // We know that the offset corresponding to the FileID is is less than
506 // SLocOffset.
507 unsigned LessIndex = 0;
508 NumProbes = 0;
509 while (1) {
510 unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex;
Douglas Gregor7f94b0b2009-04-27 06:38:32 +0000511 unsigned MidOffset = getSLocEntry(FileID::get(MiddleIndex)).getOffset();
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000513 ++NumProbes;
Mike Stump1eb44332009-09-09 15:08:12 +0000514
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000515 // If the offset of the midpoint is too large, chop the high side of the
516 // range to the midpoint.
517 if (MidOffset > SLocOffset) {
518 GreaterIndex = MiddleIndex;
519 continue;
520 }
Mike Stump1eb44332009-09-09 15:08:12 +0000521
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000522 // If the middle index contains the value, succeed and return.
523 if (isOffsetInFileID(FileID::get(MiddleIndex), SLocOffset)) {
524#if 0
525 printf("bin %d -> %d [%s] %d %d\n", SLocOffset,
526 I-SLocEntryTable.begin(),
527 I->isInstantiation() ? "inst" : "file",
528 LastFileIDLookup.ID, int(SLocEntryTable.end()-I));
529#endif
530 FileID Res = FileID::get(MiddleIndex);
531
532 // If this isn't an instantiation, remember it. We have good locality
533 // across FileID lookups.
534 if (!I->isInstantiation())
535 LastFileIDLookup = Res;
536 NumBinaryProbes += NumProbes;
537 return Res;
538 }
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000540 // Otherwise, move the low-side up to the middle index.
541 LessIndex = MiddleIndex;
542 }
543}
544
Chris Lattneraddb7972009-01-26 20:04:19 +0000545SourceLocation SourceManager::
546getInstantiationLocSlowCase(SourceLocation Loc) const {
547 do {
548 std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
Chris Lattnere7fb4842009-02-15 20:52:18 +0000549 Loc = getSLocEntry(LocInfo.first).getInstantiation()
550 .getInstantiationLocStart();
Chris Lattneraddb7972009-01-26 20:04:19 +0000551 Loc = Loc.getFileLocWithOffset(LocInfo.second);
552 } while (!Loc.isFileID());
553
554 return Loc;
555}
556
557SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const {
558 do {
559 std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
560 Loc = getSLocEntry(LocInfo.first).getInstantiation().getSpellingLoc();
561 Loc = Loc.getFileLocWithOffset(LocInfo.second);
562 } while (!Loc.isFileID());
563 return Loc;
564}
565
566
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000567std::pair<FileID, unsigned>
568SourceManager::getDecomposedInstantiationLocSlowCase(const SrcMgr::SLocEntry *E,
569 unsigned Offset) const {
570 // If this is an instantiation record, walk through all the instantiation
571 // points.
572 FileID FID;
573 SourceLocation Loc;
574 do {
Chris Lattnere7fb4842009-02-15 20:52:18 +0000575 Loc = E->getInstantiation().getInstantiationLocStart();
Mike Stump1eb44332009-09-09 15:08:12 +0000576
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000577 FID = getFileID(Loc);
578 E = &getSLocEntry(FID);
579 Offset += Loc.getOffset()-E->getOffset();
Chris Lattnerbcd1a1b2009-01-26 19:41:58 +0000580 } while (!Loc.isFileID());
Mike Stump1eb44332009-09-09 15:08:12 +0000581
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000582 return std::make_pair(FID, Offset);
583}
584
585std::pair<FileID, unsigned>
586SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
587 unsigned Offset) const {
Chris Lattnerbcd1a1b2009-01-26 19:41:58 +0000588 // If this is an instantiation record, walk through all the instantiation
589 // points.
590 FileID FID;
591 SourceLocation Loc;
592 do {
593 Loc = E->getInstantiation().getSpellingLoc();
Mike Stump1eb44332009-09-09 15:08:12 +0000594
Chris Lattnerbcd1a1b2009-01-26 19:41:58 +0000595 FID = getFileID(Loc);
596 E = &getSLocEntry(FID);
597 Offset += Loc.getOffset()-E->getOffset();
598 } while (!Loc.isFileID());
Mike Stump1eb44332009-09-09 15:08:12 +0000599
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000600 return std::make_pair(FID, Offset);
601}
602
Chris Lattner387616e2009-02-17 08:04:48 +0000603/// getImmediateSpellingLoc - Given a SourceLocation object, return the
604/// spelling location referenced by the ID. This is the first level down
605/// towards the place where the characters that make up the lexed token can be
606/// found. This should not generally be used by clients.
607SourceLocation SourceManager::getImmediateSpellingLoc(SourceLocation Loc) const{
608 if (Loc.isFileID()) return Loc;
609 std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
610 Loc = getSLocEntry(LocInfo.first).getInstantiation().getSpellingLoc();
611 return Loc.getFileLocWithOffset(LocInfo.second);
612}
613
614
Chris Lattnere7fb4842009-02-15 20:52:18 +0000615/// getImmediateInstantiationRange - Loc is required to be an instantiation
616/// location. Return the start/end of the instantiation information.
617std::pair<SourceLocation,SourceLocation>
618SourceManager::getImmediateInstantiationRange(SourceLocation Loc) const {
619 assert(Loc.isMacroID() && "Not an instantiation loc!");
620 const InstantiationInfo &II = getSLocEntry(getFileID(Loc)).getInstantiation();
621 return II.getInstantiationLocRange();
622}
623
Chris Lattner66781332009-02-15 21:26:50 +0000624/// getInstantiationRange - Given a SourceLocation object, return the
625/// range of tokens covered by the instantiation in the ultimate file.
626std::pair<SourceLocation,SourceLocation>
627SourceManager::getInstantiationRange(SourceLocation Loc) const {
628 if (Loc.isFileID()) return std::make_pair(Loc, Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Chris Lattner66781332009-02-15 21:26:50 +0000630 std::pair<SourceLocation,SourceLocation> Res =
631 getImmediateInstantiationRange(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000632
Chris Lattner66781332009-02-15 21:26:50 +0000633 // Fully resolve the start and end locations to their ultimate instantiation
634 // points.
635 while (!Res.first.isFileID())
636 Res.first = getImmediateInstantiationRange(Res.first).first;
637 while (!Res.second.isFileID())
638 Res.second = getImmediateInstantiationRange(Res.second).second;
639 return Res;
640}
641
Chris Lattnere7fb4842009-02-15 20:52:18 +0000642
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000643
644//===----------------------------------------------------------------------===//
645// Queries about the code at a SourceLocation.
646//===----------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000647
648/// getCharacterData - Return a pointer to the start of the specified location
649/// in the appropriate MemoryBuffer.
650const char *SourceManager::getCharacterData(SourceLocation SL) const {
651 // Note that this is a hot function in the getSpelling() path, which is
652 // heavily used by -E mode.
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000653 std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(SL);
Mike Stump1eb44332009-09-09 15:08:12 +0000654
Ted Kremenekc16c2082009-01-06 01:55:26 +0000655 // Note that calling 'getBuffer()' may lazily page in a source file.
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000656 return getSLocEntry(LocInfo.first).getFile().getContentCache()
657 ->getBuffer()->getBufferStart() + LocInfo.second;
Reid Spencer5f016e22007-07-11 17:01:13 +0000658}
659
Reid Spencer5f016e22007-07-11 17:01:13 +0000660
Chris Lattner9dc1f532007-07-20 16:37:10 +0000661/// getColumnNumber - Return the column # for the specified file position.
Chris Lattner7da5aea2009-02-04 00:55:58 +0000662/// this is significantly cheaper to compute than the line number.
663unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos) const {
664 const char *Buf = getBuffer(FID)->getBufferStart();
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Reid Spencer5f016e22007-07-11 17:01:13 +0000666 unsigned LineStart = FilePos;
667 while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
668 --LineStart;
669 return FilePos-LineStart+1;
670}
671
Chris Lattner7da5aea2009-02-04 00:55:58 +0000672unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc) const {
Chris Lattner30fc9332009-02-04 01:06:56 +0000673 if (Loc.isInvalid()) return 0;
Chris Lattner7da5aea2009-02-04 00:55:58 +0000674 std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
675 return getColumnNumber(LocInfo.first, LocInfo.second);
676}
677
678unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc) const {
Chris Lattner30fc9332009-02-04 01:06:56 +0000679 if (Loc.isInvalid()) return 0;
Chris Lattner7da5aea2009-02-04 00:55:58 +0000680 std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
681 return getColumnNumber(LocInfo.first, LocInfo.second);
682}
683
684
685
Benjamin Kramerc997eb42009-11-14 16:36:57 +0000686static DISABLE_INLINE void ComputeLineNumbers(ContentCache* FI,
687 llvm::BumpPtrAllocator &Alloc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688static void ComputeLineNumbers(ContentCache* FI, llvm::BumpPtrAllocator &Alloc){
Ted Kremenekc16c2082009-01-06 01:55:26 +0000689 // Note that calling 'getBuffer()' may lazily page in the file.
690 const MemoryBuffer *Buffer = FI->getBuffer();
Mike Stump1eb44332009-09-09 15:08:12 +0000691
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000692 // Find the file offsets of all of the *physical* source lines. This does
693 // not look at trigraphs, escaped newlines, or anything else tricky.
694 std::vector<unsigned> LineOffsets;
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000696 // Line #1 starts at char 0.
697 LineOffsets.push_back(0);
Mike Stump1eb44332009-09-09 15:08:12 +0000698
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000699 const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart();
700 const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd();
701 unsigned Offs = 0;
702 while (1) {
703 // Skip over the contents of the line.
704 // TODO: Vectorize this? This is very performance sensitive for programs
705 // with lots of diagnostics and in -E mode.
706 const unsigned char *NextBuf = (const unsigned char *)Buf;
707 while (*NextBuf != '\n' && *NextBuf != '\r' && *NextBuf != '\0')
708 ++NextBuf;
709 Offs += NextBuf-Buf;
710 Buf = NextBuf;
Mike Stump1eb44332009-09-09 15:08:12 +0000711
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000712 if (Buf[0] == '\n' || Buf[0] == '\r') {
713 // If this is \n\r or \r\n, skip both characters.
714 if ((Buf[1] == '\n' || Buf[1] == '\r') && Buf[0] != Buf[1])
715 ++Offs, ++Buf;
716 ++Offs, ++Buf;
717 LineOffsets.push_back(Offs);
718 } else {
719 // Otherwise, this is a null. If end of file, exit.
720 if (Buf == End) break;
721 // Otherwise, skip the null.
722 ++Offs, ++Buf;
723 }
724 }
Mike Stump1eb44332009-09-09 15:08:12 +0000725
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000726 // Copy the offsets into the FileInfo structure.
727 FI->NumLines = LineOffsets.size();
Chris Lattner0d0bf8c2009-02-03 07:30:45 +0000728 FI->SourceLineCache = Alloc.Allocate<unsigned>(LineOffsets.size());
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000729 std::copy(LineOffsets.begin(), LineOffsets.end(), FI->SourceLineCache);
730}
Reid Spencer5f016e22007-07-11 17:01:13 +0000731
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000732/// getLineNumber - Given a SourceLocation, return the spelling line number
Reid Spencer5f016e22007-07-11 17:01:13 +0000733/// for the position indicated. This requires building and caching a table of
734/// line offsets for the MemoryBuffer, so this is not cheap: use only when
735/// about to emit a diagnostic.
Chris Lattner30fc9332009-02-04 01:06:56 +0000736unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos) const {
Chris Lattner2b2453a2009-01-17 06:22:33 +0000737 ContentCache *Content;
Chris Lattner30fc9332009-02-04 01:06:56 +0000738 if (LastLineNoFileIDQuery == FID)
Ted Kremenek78d85f52007-10-30 21:08:08 +0000739 Content = LastLineNoContentCache;
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000740 else
Chris Lattner30fc9332009-02-04 01:06:56 +0000741 Content = const_cast<ContentCache*>(getSLocEntry(FID)
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000742 .getFile().getContentCache());
Mike Stump1eb44332009-09-09 15:08:12 +0000743
Reid Spencer5f016e22007-07-11 17:01:13 +0000744 // If this is the first use of line information for this buffer, compute the
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000745 /// SourceLineCache for it on demand.
Ted Kremenek78d85f52007-10-30 21:08:08 +0000746 if (Content->SourceLineCache == 0)
Chris Lattner0d0bf8c2009-02-03 07:30:45 +0000747 ComputeLineNumbers(Content, ContentCacheAlloc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000748
749 // Okay, we know we have a line number table. Do a binary search to find the
750 // line number that this character position lands on.
Ted Kremenek78d85f52007-10-30 21:08:08 +0000751 unsigned *SourceLineCache = Content->SourceLineCache;
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000752 unsigned *SourceLineCacheStart = SourceLineCache;
Ted Kremenek78d85f52007-10-30 21:08:08 +0000753 unsigned *SourceLineCacheEnd = SourceLineCache + Content->NumLines;
Mike Stump1eb44332009-09-09 15:08:12 +0000754
Chris Lattner30fc9332009-02-04 01:06:56 +0000755 unsigned QueriedFilePos = FilePos+1;
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000756
Daniel Dunbar4106d692009-05-18 17:30:52 +0000757 // FIXME: I would like to be convinced that this code is worth being as
Mike Stump1eb44332009-09-09 15:08:12 +0000758 // complicated as it is, binary search isn't that slow.
Daniel Dunbar4106d692009-05-18 17:30:52 +0000759 //
760 // If it is worth being optimized, then in my opinion it could be more
761 // performant, simpler, and more obviously correct by just "galloping" outward
762 // from the queried file position. In fact, this could be incorporated into a
763 // generic algorithm such as lower_bound_with_hint.
764 //
765 // If someone gives me a test case where this matters, and I will do it! - DWD
766
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000767 // If the previous query was to the same file, we know both the file pos from
768 // that query and the line number returned. This allows us to narrow the
769 // search space from the entire file to something near the match.
Chris Lattner30fc9332009-02-04 01:06:56 +0000770 if (LastLineNoFileIDQuery == FID) {
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000771 if (QueriedFilePos >= LastLineNoFilePos) {
Daniel Dunbar4106d692009-05-18 17:30:52 +0000772 // FIXME: Potential overflow?
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000773 SourceLineCache = SourceLineCache+LastLineNoResult-1;
Mike Stump1eb44332009-09-09 15:08:12 +0000774
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000775 // The query is likely to be nearby the previous one. Here we check to
776 // see if it is within 5, 10 or 20 lines. It can be far away in cases
777 // where big comment blocks and vertical whitespace eat up lines but
778 // contribute no tokens.
779 if (SourceLineCache+5 < SourceLineCacheEnd) {
780 if (SourceLineCache[5] > QueriedFilePos)
781 SourceLineCacheEnd = SourceLineCache+5;
782 else if (SourceLineCache+10 < SourceLineCacheEnd) {
783 if (SourceLineCache[10] > QueriedFilePos)
784 SourceLineCacheEnd = SourceLineCache+10;
785 else if (SourceLineCache+20 < SourceLineCacheEnd) {
786 if (SourceLineCache[20] > QueriedFilePos)
787 SourceLineCacheEnd = SourceLineCache+20;
788 }
789 }
790 }
791 } else {
Daniel Dunbar4106d692009-05-18 17:30:52 +0000792 if (LastLineNoResult < Content->NumLines)
793 SourceLineCacheEnd = SourceLineCache+LastLineNoResult+1;
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000794 }
795 }
Mike Stump1eb44332009-09-09 15:08:12 +0000796
Chris Lattner1cf12bf2007-07-24 06:43:46 +0000797 // If the spread is large, do a "radix" test as our initial guess, based on
798 // the assumption that lines average to approximately the same length.
799 // NOTE: This is currently disabled, as it does not appear to be profitable in
800 // initial measurements.
801 if (0 && SourceLineCacheEnd-SourceLineCache > 20) {
Ted Kremenek78d85f52007-10-30 21:08:08 +0000802 unsigned FileLen = Content->SourceLineCache[Content->NumLines-1];
Mike Stump1eb44332009-09-09 15:08:12 +0000803
Chris Lattner1cf12bf2007-07-24 06:43:46 +0000804 // Take a stab at guessing where it is.
Ted Kremenek78d85f52007-10-30 21:08:08 +0000805 unsigned ApproxPos = Content->NumLines*QueriedFilePos / FileLen;
Mike Stump1eb44332009-09-09 15:08:12 +0000806
Chris Lattner1cf12bf2007-07-24 06:43:46 +0000807 // Check for -10 and +10 lines.
808 unsigned LowerBound = std::max(int(ApproxPos-10), 0);
809 unsigned UpperBound = std::min(ApproxPos+10, FileLen);
810
811 // If the computed lower bound is less than the query location, move it in.
812 if (SourceLineCache < SourceLineCacheStart+LowerBound &&
813 SourceLineCacheStart[LowerBound] < QueriedFilePos)
814 SourceLineCache = SourceLineCacheStart+LowerBound;
Mike Stump1eb44332009-09-09 15:08:12 +0000815
Chris Lattner1cf12bf2007-07-24 06:43:46 +0000816 // If the computed upper bound is greater than the query location, move it.
817 if (SourceLineCacheEnd > SourceLineCacheStart+UpperBound &&
818 SourceLineCacheStart[UpperBound] >= QueriedFilePos)
819 SourceLineCacheEnd = SourceLineCacheStart+UpperBound;
820 }
Mike Stump1eb44332009-09-09 15:08:12 +0000821
Chris Lattner1cf12bf2007-07-24 06:43:46 +0000822 unsigned *Pos
823 = std::lower_bound(SourceLineCache, SourceLineCacheEnd, QueriedFilePos);
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000824 unsigned LineNo = Pos-SourceLineCacheStart;
Mike Stump1eb44332009-09-09 15:08:12 +0000825
Chris Lattner30fc9332009-02-04 01:06:56 +0000826 LastLineNoFileIDQuery = FID;
Ted Kremenek78d85f52007-10-30 21:08:08 +0000827 LastLineNoContentCache = Content;
Chris Lattner5e36a7a2007-07-24 05:57:19 +0000828 LastLineNoFilePos = QueriedFilePos;
829 LastLineNoResult = LineNo;
830 return LineNo;
Reid Spencer5f016e22007-07-11 17:01:13 +0000831}
832
Chris Lattner30fc9332009-02-04 01:06:56 +0000833unsigned SourceManager::getInstantiationLineNumber(SourceLocation Loc) const {
834 if (Loc.isInvalid()) return 0;
835 std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
836 return getLineNumber(LocInfo.first, LocInfo.second);
837}
838unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc) const {
839 if (Loc.isInvalid()) return 0;
840 std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
841 return getLineNumber(LocInfo.first, LocInfo.second);
842}
843
Chris Lattner6b306672009-02-04 05:33:01 +0000844/// getFileCharacteristic - return the file characteristic of the specified
Mike Stump1eb44332009-09-09 15:08:12 +0000845/// source location, indicating whether this is a normal file, a system
Chris Lattner6b306672009-02-04 05:33:01 +0000846/// header, or an "implicit extern C" system header.
847///
848/// This state can be modified with flags on GNU linemarker directives like:
849/// # 4 "foo.h" 3
850/// which changes all source locations in the current file after that to be
851/// considered to be from a system header.
Mike Stump1eb44332009-09-09 15:08:12 +0000852SrcMgr::CharacteristicKind
Chris Lattner6b306672009-02-04 05:33:01 +0000853SourceManager::getFileCharacteristic(SourceLocation Loc) const {
854 assert(!Loc.isInvalid() && "Can't get file characteristic of invalid loc!");
855 std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
856 const SrcMgr::FileInfo &FI = getSLocEntry(LocInfo.first).getFile();
857
858 // If there are no #line directives in this file, just return the whole-file
859 // state.
860 if (!FI.hasLineDirectives())
861 return FI.getFileCharacteristic();
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Chris Lattner6b306672009-02-04 05:33:01 +0000863 assert(LineTable && "Can't have linetable entries without a LineTable!");
864 // See if there is a #line directive before the location.
865 const LineEntry *Entry =
866 LineTable->FindNearestLineEntry(LocInfo.first.ID, LocInfo.second);
Mike Stump1eb44332009-09-09 15:08:12 +0000867
Chris Lattner6b306672009-02-04 05:33:01 +0000868 // If this is before the first line marker, use the file characteristic.
869 if (!Entry)
870 return FI.getFileCharacteristic();
871
872 return Entry->FileKind;
873}
874
Chris Lattnerbff5c512009-02-17 08:39:06 +0000875/// Return the filename or buffer identifier of the buffer the location is in.
876/// Note that this name does not respect #line directives. Use getPresumedLoc
877/// for normal clients.
878const char *SourceManager::getBufferName(SourceLocation Loc) const {
879 if (Loc.isInvalid()) return "<invalid loc>";
Mike Stump1eb44332009-09-09 15:08:12 +0000880
Chris Lattnerbff5c512009-02-17 08:39:06 +0000881 return getBuffer(getFileID(Loc))->getBufferIdentifier();
882}
883
Chris Lattner30fc9332009-02-04 01:06:56 +0000884
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000885/// getPresumedLoc - This method returns the "presumed" location of a
886/// SourceLocation specifies. A "presumed location" can be modified by #line
887/// or GNU line marker directives. This provides a view on the data that a
888/// user should see in diagnostics, for example.
889///
890/// Note that a presumed location is always given as the instantiation point
891/// of an instantiation location, not at the spelling location.
892PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const {
893 if (Loc.isInvalid()) return PresumedLoc();
Mike Stump1eb44332009-09-09 15:08:12 +0000894
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000895 // Presumed locations are always for instantiation points.
Chris Lattner7da5aea2009-02-04 00:55:58 +0000896 std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000897
Chris Lattner30fc9332009-02-04 01:06:56 +0000898 const SrcMgr::FileInfo &FI = getSLocEntry(LocInfo.first).getFile();
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000899 const SrcMgr::ContentCache *C = FI.getContentCache();
Mike Stump1eb44332009-09-09 15:08:12 +0000900
Chris Lattner3cd949c2009-02-04 01:55:42 +0000901 // To get the source name, first consult the FileEntry (if one exists)
902 // before the MemBuffer as this will avoid unnecessarily paging in the
903 // MemBuffer.
Mike Stump1eb44332009-09-09 15:08:12 +0000904 const char *Filename =
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000905 C->Entry ? C->Entry->getName() : C->getBuffer()->getBufferIdentifier();
Chris Lattner3cd949c2009-02-04 01:55:42 +0000906 unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second);
907 unsigned ColNo = getColumnNumber(LocInfo.first, LocInfo.second);
908 SourceLocation IncludeLoc = FI.getIncludeLoc();
Mike Stump1eb44332009-09-09 15:08:12 +0000909
Chris Lattner3cd949c2009-02-04 01:55:42 +0000910 // If we have #line directives in this file, update and overwrite the physical
911 // location info if appropriate.
912 if (FI.hasLineDirectives()) {
913 assert(LineTable && "Can't have linetable entries without a LineTable!");
914 // See if there is a #line directive before this. If so, get it.
915 if (const LineEntry *Entry =
916 LineTable->FindNearestLineEntry(LocInfo.first.ID, LocInfo.second)) {
Chris Lattnerfc391332009-02-04 02:00:59 +0000917 // If the LineEntry indicates a filename, use it.
Chris Lattner3cd949c2009-02-04 01:55:42 +0000918 if (Entry->FilenameID != -1)
919 Filename = LineTable->getFilename(Entry->FilenameID);
Chris Lattnerfc391332009-02-04 02:00:59 +0000920
921 // Use the line number specified by the LineEntry. This line number may
922 // be multiple lines down from the line entry. Add the difference in
923 // physical line numbers from the query point and the line marker to the
924 // total.
925 unsigned MarkerLineNo = getLineNumber(LocInfo.first, Entry->FileOffset);
926 LineNo = Entry->LineNo + (LineNo-MarkerLineNo-1);
Mike Stump1eb44332009-09-09 15:08:12 +0000927
Chris Lattner0e0e5da2009-02-04 02:15:40 +0000928 // Note that column numbers are not molested by line markers.
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Chris Lattner137b6a62009-02-04 06:25:26 +0000930 // Handle virtual #include manipulation.
931 if (Entry->IncludeOffset) {
932 IncludeLoc = getLocForStartOfFile(LocInfo.first);
933 IncludeLoc = IncludeLoc.getFileLocWithOffset(Entry->IncludeOffset);
934 }
Chris Lattner3cd949c2009-02-04 01:55:42 +0000935 }
936 }
937
938 return PresumedLoc(Filename, LineNo, ColNo, IncludeLoc);
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000939}
940
941//===----------------------------------------------------------------------===//
942// Other miscellaneous methods.
943//===----------------------------------------------------------------------===//
944
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000945/// \brief Get the source location for the given file:line:col triplet.
946///
947/// If the source file is included multiple times, the source location will
948/// be based upon the first inclusion.
949SourceLocation SourceManager::getLocation(const FileEntry *SourceFile,
950 unsigned Line, unsigned Col) const {
951 assert(SourceFile && "Null source file!");
952 assert(Line && Col && "Line and column should start from 1!");
953
954 fileinfo_iterator FI = FileInfos.find(SourceFile);
955 if (FI == FileInfos.end())
956 return SourceLocation();
957 ContentCache *Content = FI->second;
Mike Stump1eb44332009-09-09 15:08:12 +0000958
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000959 // If this is the first use of line information for this buffer, compute the
960 /// SourceLineCache for it on demand.
961 if (Content->SourceLineCache == 0)
962 ComputeLineNumbers(Content, ContentCacheAlloc);
963
964 if (Line > Content->NumLines)
965 return SourceLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000966
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000967 unsigned FilePos = Content->SourceLineCache[Line - 1];
Argyrios Kyrtzidis081445c2009-06-25 18:22:16 +0000968 const char *Buf = Content->getBuffer()->getBufferStart() + FilePos;
Argyrios Kyrtzidis93edc3c2009-06-20 08:40:15 +0000969 unsigned BufLength = Content->getBuffer()->getBufferEnd() - Buf;
970 unsigned i = 0;
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000971
972 // Check that the given column is valid.
Argyrios Kyrtzidis93edc3c2009-06-20 08:40:15 +0000973 while (i < BufLength-1 && i < Col-1 && Buf[i] != '\n' && Buf[i] != '\r')
974 ++i;
975 if (i < Col-1)
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +0000976 return SourceLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000977
Douglas Gregor4a160e12009-12-02 05:34:39 +0000978 // Find the first file ID that corresponds to the given file.
979 FileID FirstFID;
980
981 // First, check the main file ID, since it is common to look for a
982 // location in the main file.
983 if (!MainFileID.isInvalid()) {
984 const SLocEntry &MainSLoc = getSLocEntry(MainFileID);
985 if (MainSLoc.isFile() && MainSLoc.getFile().getContentCache() == Content)
986 FirstFID = MainFileID;
987 }
988
989 if (FirstFID.isInvalid()) {
990 // The location we're looking for isn't in the main file; look
991 // through all of the source locations.
992 for (unsigned I = 0, N = sloc_entry_size(); I != N; ++I) {
993 const SLocEntry &SLoc = getSLocEntry(I);
994 if (SLoc.isFile() && SLoc.getFile().getContentCache() == Content) {
995 FirstFID = FileID::get(I);
996 break;
997 }
998 }
999 }
1000
1001 if (FirstFID.isInvalid())
1002 return SourceLocation();
1003
1004 return getLocForStartOfFile(FirstFID).getFileLocWithOffset(FilePos + Col - 1);
Argyrios Kyrtzidis10b46d22009-06-20 08:09:57 +00001005}
1006
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001007/// \brief Determines the order of 2 source locations in the translation unit.
1008///
1009/// \returns true if LHS source location comes before RHS, false otherwise.
1010bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
1011 SourceLocation RHS) const {
1012 assert(LHS.isValid() && RHS.isValid() && "Passed invalid source location!");
1013 if (LHS == RHS)
1014 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001015
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001016 std::pair<FileID, unsigned> LOffs = getDecomposedLoc(LHS);
1017 std::pair<FileID, unsigned> ROffs = getDecomposedLoc(RHS);
Mike Stump1eb44332009-09-09 15:08:12 +00001018
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001019 // If the source locations are in the same file, just compare offsets.
1020 if (LOffs.first == ROffs.first)
1021 return LOffs.second < ROffs.second;
1022
1023 // If we are comparing a source location with multiple locations in the same
1024 // file, we get a big win by caching the result.
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001026 if (LastLFIDForBeforeTUCheck == LOffs.first &&
1027 LastRFIDForBeforeTUCheck == ROffs.first)
1028 return LastResForBeforeTUCheck;
Mike Stump1eb44332009-09-09 15:08:12 +00001029
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001030 LastLFIDForBeforeTUCheck = LOffs.first;
1031 LastRFIDForBeforeTUCheck = ROffs.first;
Mike Stump1eb44332009-09-09 15:08:12 +00001032
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001033 // "Traverse" the include/instantiation stacks of both locations and try to
1034 // find a common "ancestor".
1035 //
1036 // First we traverse the stack of the right location and check each level
1037 // against the level of the left location, while collecting all levels in a
1038 // "stack map".
1039
1040 std::map<FileID, unsigned> ROffsMap;
1041 ROffsMap[ROffs.first] = ROffs.second;
1042
1043 while (1) {
1044 SourceLocation UpperLoc;
1045 const SrcMgr::SLocEntry &Entry = getSLocEntry(ROffs.first);
1046 if (Entry.isInstantiation())
1047 UpperLoc = Entry.getInstantiation().getInstantiationLocStart();
1048 else
1049 UpperLoc = Entry.getFile().getIncludeLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00001050
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001051 if (UpperLoc.isInvalid())
1052 break; // We reached the top.
Mike Stump1eb44332009-09-09 15:08:12 +00001053
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001054 ROffs = getDecomposedLoc(UpperLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001056 if (LOffs.first == ROffs.first)
1057 return LastResForBeforeTUCheck = LOffs.second < ROffs.second;
Mike Stump1eb44332009-09-09 15:08:12 +00001058
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001059 ROffsMap[ROffs.first] = ROffs.second;
1060 }
1061
1062 // We didn't find a common ancestor. Now traverse the stack of the left
1063 // location, checking against the stack map of the right location.
1064
1065 while (1) {
1066 SourceLocation UpperLoc;
1067 const SrcMgr::SLocEntry &Entry = getSLocEntry(LOffs.first);
1068 if (Entry.isInstantiation())
1069 UpperLoc = Entry.getInstantiation().getInstantiationLocStart();
1070 else
1071 UpperLoc = Entry.getFile().getIncludeLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00001072
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001073 if (UpperLoc.isInvalid())
1074 break; // We reached the top.
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001076 LOffs = getDecomposedLoc(UpperLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001078 std::map<FileID, unsigned>::iterator I = ROffsMap.find(LOffs.first);
1079 if (I != ROffsMap.end())
1080 return LastResForBeforeTUCheck = LOffs.second < I->second;
1081 }
Mike Stump1eb44332009-09-09 15:08:12 +00001082
Daniel Dunbarfbcc7be2009-12-01 23:07:57 +00001083 // There is no common ancestor, most probably because one location is in the
1084 // predefines buffer.
1085 //
1086 // FIXME: We should rearrange the external interface so this simply never
1087 // happens; it can't conceptually happen. Also see PR5662.
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Daniel Dunbarfbcc7be2009-12-01 23:07:57 +00001089 // If exactly one location is a memory buffer, assume it preceeds the other.
1090 bool LIsMB = !getSLocEntry(LOffs.first).getFile().getContentCache()->Entry;
1091 bool RIsMB = !getSLocEntry(ROffs.first).getFile().getContentCache()->Entry;
1092 if (LIsMB != RIsMB)
1093 return LastResForBeforeTUCheck = LIsMB;
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Daniel Dunbarfbcc7be2009-12-01 23:07:57 +00001095 // Otherwise, just assume FileIDs were created in order.
1096 return LastResForBeforeTUCheck = (LOffs.first < ROffs.first);
Argyrios Kyrtzidis2aa03d52009-06-23 22:01:48 +00001097}
Chris Lattnerde7aeef2009-01-26 00:43:02 +00001098
Reid Spencer5f016e22007-07-11 17:01:13 +00001099/// PrintStats - Print statistics to stderr.
1100///
1101void SourceManager::PrintStats() const {
Benjamin Kramer6cb7c1a2009-08-23 12:08:50 +00001102 llvm::errs() << "\n*** Source Manager Stats:\n";
1103 llvm::errs() << FileInfos.size() << " files mapped, " << MemBufferInfos.size()
1104 << " mem buffers mapped.\n";
1105 llvm::errs() << SLocEntryTable.size() << " SLocEntry's allocated, "
1106 << NextOffset << "B of Sloc address space used.\n";
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Reid Spencer5f016e22007-07-11 17:01:13 +00001108 unsigned NumLineNumsComputed = 0;
1109 unsigned NumFileBytesMapped = 0;
Chris Lattner0d0bf8c2009-02-03 07:30:45 +00001110 for (fileinfo_iterator I = fileinfo_begin(), E = fileinfo_end(); I != E; ++I){
1111 NumLineNumsComputed += I->second->SourceLineCache != 0;
1112 NumFileBytesMapped += I->second->getSizeBytesMapped();
Reid Spencer5f016e22007-07-11 17:01:13 +00001113 }
Mike Stump1eb44332009-09-09 15:08:12 +00001114
Benjamin Kramer6cb7c1a2009-08-23 12:08:50 +00001115 llvm::errs() << NumFileBytesMapped << " bytes of files mapped, "
1116 << NumLineNumsComputed << " files with line #'s computed.\n";
1117 llvm::errs() << "FileID scans: " << NumLinearScans << " linear, "
1118 << NumBinaryProbes << " binary.\n";
Reid Spencer5f016e22007-07-11 17:01:13 +00001119}
Douglas Gregor7f94b0b2009-04-27 06:38:32 +00001120
1121ExternalSLocEntrySource::~ExternalSLocEntrySource() { }