]> granicus.if.org Git - clang/blob - include/clang/Basic/SourceManager.h
Make SourceManager::isBeforeInTranslationUnit handle macro locations correctly.
[clang] / include / clang / Basic / SourceManager.h
1 //===--- SourceManager.h - Track and cache source files ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the SourceManager interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_SOURCEMANAGER_H
15 #define LLVM_CLANG_SOURCEMANAGER_H
16
17 #include "clang/Basic/LLVM.h"
18 #include "clang/Basic/SourceLocation.h"
19 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/DataTypes.h"
21 #include "llvm/ADT/PointerIntPair.h"
22 #include "llvm/ADT/PointerUnion.h"
23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/Support/MemoryBuffer.h"
26 #include <vector>
27 #include <cassert>
28
29 namespace clang {
30
31 class Diagnostic;
32 class SourceManager;
33 class FileManager;
34 class FileEntry;
35 class LineTableInfo;
36 class LangOptions;
37   
38 /// SrcMgr - Public enums and private classes that are part of the
39 /// SourceManager implementation.
40 ///
41 namespace SrcMgr {
42   /// CharacteristicKind - This is used to represent whether a file or directory
43   /// holds normal user code, system code, or system code which is implicitly
44   /// 'extern "C"' in C++ mode.  Entire directories can be tagged with this
45   /// (this is maintained by DirectoryLookup and friends) as can specific
46   /// FileInfos when a #pragma system_header is seen or various other cases.
47   ///
48   enum CharacteristicKind {
49     C_User, C_System, C_ExternCSystem
50   };
51
52   /// ContentCache - One instance of this struct is kept for every file
53   /// loaded or used.  This object owns the MemoryBuffer object.
54   class ContentCache {
55     enum CCFlags {
56       /// \brief Whether the buffer is invalid.
57       InvalidFlag = 0x01,
58       /// \brief Whether the buffer should not be freed on destruction.
59       DoNotFreeFlag = 0x02
60     };
61     
62     /// Buffer - The actual buffer containing the characters from the input
63     /// file.  This is owned by the ContentCache object.
64     /// The bits indicate indicates whether the buffer is invalid.
65     mutable llvm::PointerIntPair<const llvm::MemoryBuffer *, 2> Buffer;
66
67   public:
68     /// Reference to the file entry representing this ContentCache.
69     /// This reference does not own the FileEntry object.
70     /// It is possible for this to be NULL if
71     /// the ContentCache encapsulates an imaginary text buffer.
72     const FileEntry *OrigEntry;
73
74     /// \brief References the file which the contents were actually loaded from.
75     /// Can be different from 'Entry' if we overridden the contents of one file
76     /// with the contents of another file.
77     const FileEntry *ContentsEntry;
78
79     /// SourceLineCache - A bump pointer allocated array of offsets for each
80     /// source line.  This is lazily computed.  This is owned by the
81     /// SourceManager BumpPointerAllocator object.
82     unsigned *SourceLineCache;
83
84     /// NumLines - The number of lines in this ContentCache.  This is only valid
85     /// if SourceLineCache is non-null.
86     unsigned NumLines;
87
88     /// getBuffer - Returns the memory buffer for the associated content.
89     ///
90     /// \param Diag Object through which diagnostics will be emitted if the
91     /// buffer cannot be retrieved.
92     /// 
93     /// \param Loc If specified, is the location that invalid file diagnostics
94     ///     will be emitted at.
95     ///
96     /// \param Invalid If non-NULL, will be set \c true if an error occurred.
97     const llvm::MemoryBuffer *getBuffer(Diagnostic &Diag,
98                                         const SourceManager &SM,
99                                         SourceLocation Loc = SourceLocation(),
100                                         bool *Invalid = 0) const;
101
102     /// getSize - Returns the size of the content encapsulated by this
103     ///  ContentCache. This can be the size of the source file or the size of an
104     ///  arbitrary scratch buffer.  If the ContentCache encapsulates a source
105     ///  file this size is retrieved from the file's FileEntry.
106     unsigned getSize() const;
107
108     /// getSizeBytesMapped - Returns the number of bytes actually mapped for
109     /// this ContentCache. This can be 0 if the MemBuffer was not actually
110     /// expanded.
111     unsigned getSizeBytesMapped() const;
112     
113     /// Returns the kind of memory used to back the memory buffer for
114     /// this content cache.  This is used for performance analysis.
115     llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const;
116
117     void setBuffer(const llvm::MemoryBuffer *B) {
118       assert(!Buffer.getPointer() && "MemoryBuffer already set.");
119       Buffer.setPointer(B);
120       Buffer.setInt(false);
121     }
122     
123     /// \brief Get the underlying buffer, returning NULL if the buffer is not
124     /// yet available.
125     const llvm::MemoryBuffer *getRawBuffer() const {
126       return Buffer.getPointer();
127     }
128
129     /// \brief Replace the existing buffer (which will be deleted)
130     /// with the given buffer.
131     void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false);
132
133     /// \brief Determine whether the buffer itself is invalid.
134     bool isBufferInvalid() const {
135       return Buffer.getInt() & InvalidFlag;
136     }
137     
138     /// \brief Determine whether the buffer should be freed.
139     bool shouldFreeBuffer() const {
140       return (Buffer.getInt() & DoNotFreeFlag) == 0;
141     }
142     
143     ContentCache(const FileEntry *Ent = 0)
144       : Buffer(0, false), OrigEntry(Ent), ContentsEntry(Ent),
145         SourceLineCache(0), NumLines(0) {}
146
147     ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
148       : Buffer(0, false), OrigEntry(Ent), ContentsEntry(contentEnt),
149         SourceLineCache(0), NumLines(0) {}
150
151     ~ContentCache();
152
153     /// The copy ctor does not allow copies where source object has either
154     ///  a non-NULL Buffer or SourceLineCache.  Ownership of allocated memory
155     ///  is not transferred, so this is a logical error.
156     ContentCache(const ContentCache &RHS) 
157       : Buffer(0, false), SourceLineCache(0) 
158     {
159       OrigEntry = RHS.OrigEntry;
160       ContentsEntry = RHS.ContentsEntry;
161
162       assert (RHS.Buffer.getPointer() == 0 && RHS.SourceLineCache == 0
163               && "Passed ContentCache object cannot own a buffer.");
164
165       NumLines = RHS.NumLines;
166     }
167
168   private:
169     // Disable assignments.
170     ContentCache &operator=(const ContentCache& RHS);
171   };
172
173   /// FileInfo - Information about a FileID, basically just the logical file
174   /// that it represents and include stack information.
175   ///
176   /// Each FileInfo has include stack information, indicating where it came
177   /// from. This information encodes the #include chain that a token was
178   /// expanded from. The main include file has an invalid IncludeLoc.
179   ///
180   /// FileInfos contain a "ContentCache *", with the contents of the file.
181   ///
182   class FileInfo {
183     /// IncludeLoc - The location of the #include that brought in this file.
184     /// This is an invalid SLOC for the main file (top of the #include chain).
185     unsigned IncludeLoc;  // Really a SourceLocation
186
187     /// Data - This contains the ContentCache* and the bits indicating the
188     /// characteristic of the file and whether it has #line info, all bitmangled
189     /// together.
190     uintptr_t Data;
191   public:
192     /// get - Return a FileInfo object.
193     static FileInfo get(SourceLocation IL, const ContentCache *Con,
194                         CharacteristicKind FileCharacter) {
195       FileInfo X;
196       X.IncludeLoc = IL.getRawEncoding();
197       X.Data = (uintptr_t)Con;
198       assert((X.Data & 7) == 0 &&"ContentCache pointer insufficiently aligned");
199       assert((unsigned)FileCharacter < 4 && "invalid file character");
200       X.Data |= (unsigned)FileCharacter;
201       return X;
202     }
203
204     SourceLocation getIncludeLoc() const {
205       return SourceLocation::getFromRawEncoding(IncludeLoc);
206     }
207     const ContentCache* getContentCache() const {
208       return reinterpret_cast<const ContentCache*>(Data & ~7UL);
209     }
210
211     /// getCharacteristic - Return whether this is a system header or not.
212     CharacteristicKind getFileCharacteristic() const {
213       return (CharacteristicKind)(Data & 3);
214     }
215
216     /// hasLineDirectives - Return true if this FileID has #line directives in
217     /// it.
218     bool hasLineDirectives() const { return (Data & 4) != 0; }
219
220     /// setHasLineDirectives - Set the flag that indicates that this FileID has
221     /// line table entries associated with it.
222     void setHasLineDirectives() {
223       Data |= 4;
224     }
225   };
226
227   /// ExpansionInfo - Each ExpansionInfo encodes the expansion location - where
228   /// the token was ultimately expanded, and the SpellingLoc - where the actual
229   /// character data for the token came from.
230   class ExpansionInfo {
231     // Really these are all SourceLocations.
232
233     /// SpellingLoc - Where the spelling for the token can be found.
234     unsigned SpellingLoc;
235
236     /// ExpansionLocStart/ExpansionLocEnd - In a macro expansion, these
237     /// indicate the start and end of the expansion. In object-like macros,
238     /// these will be the same. In a function-like macro expansion, the start
239     /// will be the identifier and the end will be the ')'. Finally, in
240     /// macro-argument instantitions, the end will be 'SourceLocation()', an
241     /// invalid location.
242     unsigned ExpansionLocStart, ExpansionLocEnd;
243
244   public:
245     SourceLocation getSpellingLoc() const {
246       return SourceLocation::getFromRawEncoding(SpellingLoc);
247     }
248     SourceLocation getExpansionLocStart() const {
249       return SourceLocation::getFromRawEncoding(ExpansionLocStart);
250     }
251     SourceLocation getExpansionLocEnd() const {
252       SourceLocation EndLoc =
253         SourceLocation::getFromRawEncoding(ExpansionLocEnd);
254       return EndLoc.isInvalid() ? getExpansionLocStart() : EndLoc;
255     }
256
257     std::pair<SourceLocation,SourceLocation> getExpansionLocRange() const {
258       return std::make_pair(getExpansionLocStart(), getExpansionLocEnd());
259     }
260
261     bool isMacroArgExpansion() const {
262       // Note that this needs to return false for default constructed objects.
263       return getExpansionLocStart().isValid() &&
264         SourceLocation::getFromRawEncoding(ExpansionLocEnd).isInvalid();
265     }
266
267     /// create - Return a ExpansionInfo for an expansion. Start and End specify
268     /// the expansion range (where the macro is expanded), and SpellingLoc
269     /// specifies the spelling location (where the characters from the token
270     /// come from). All three can refer to normal File SLocs or expansion
271     /// locations.
272     static ExpansionInfo create(SourceLocation SpellingLoc,
273                                 SourceLocation Start, SourceLocation End) {
274       ExpansionInfo X;
275       X.SpellingLoc = SpellingLoc.getRawEncoding();
276       X.ExpansionLocStart = Start.getRawEncoding();
277       X.ExpansionLocEnd = End.getRawEncoding();
278       return X;
279     }
280
281     /// createForMacroArg - Return a special ExpansionInfo for the expansion of
282     /// a macro argument into a function-like macro's body. ExpansionLoc
283     /// specifies the expansion location (where the macro is expanded). This
284     /// doesn't need to be a range because a macro is always expanded at
285     /// a macro parameter reference, and macro parameters are always exactly
286     /// one token. SpellingLoc specifies the spelling location (where the
287     /// characters from the token come from). ExpansionLoc and SpellingLoc can
288     /// both refer to normal File SLocs or expansion locations.
289     ///
290     /// Given the code:
291     /// \code
292     ///   #define F(x) f(x)
293     ///   F(42);
294     /// \endcode
295     ///
296     /// When expanding '\c F(42)', the '\c x' would call this with an
297     /// SpellingLoc pointing at '\c 42' anad an ExpansionLoc pointing at its
298     /// location in the definition of '\c F'.
299     static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc,
300                                            SourceLocation ExpansionLoc) {
301       // We store an intentionally invalid source location for the end of the
302       // expansion range to mark that this is a macro argument ion rather than
303       // a normal one.
304       return create(SpellingLoc, ExpansionLoc, SourceLocation());
305     }
306   };
307
308   /// SLocEntry - This is a discriminated union of FileInfo and
309   /// ExpansionInfo.  SourceManager keeps an array of these objects, and
310   /// they are uniquely identified by the FileID datatype.
311   class SLocEntry {
312     unsigned Offset;   // low bit is set for expansion info.
313     union {
314       FileInfo File;
315       ExpansionInfo Expansion;
316     };
317   public:
318     unsigned getOffset() const { return Offset >> 1; }
319
320     bool isExpansion() const { return Offset & 1; }
321     bool isFile() const { return !isExpansion(); }
322
323     const FileInfo &getFile() const {
324       assert(isFile() && "Not a file SLocEntry!");
325       return File;
326     }
327
328     const ExpansionInfo &getExpansion() const {
329       assert(isExpansion() && "Not a macro expansion SLocEntry!");
330       return Expansion;
331     }
332
333     static SLocEntry get(unsigned Offset, const FileInfo &FI) {
334       SLocEntry E;
335       E.Offset = Offset << 1;
336       E.File = FI;
337       return E;
338     }
339
340     static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) {
341       SLocEntry E;
342       E.Offset = (Offset << 1) | 1;
343       E.Expansion = Expansion;
344       return E;
345     }
346   };
347 }  // end SrcMgr namespace.
348
349 /// \brief External source of source location entries.
350 class ExternalSLocEntrySource {
351 public:
352   virtual ~ExternalSLocEntrySource();
353
354   /// \brief Read the source location entry with index ID, which will always be
355   /// less than -1.
356   ///
357   /// \returns true if an error occurred that prevented the source-location
358   /// entry from being loaded.
359   virtual bool ReadSLocEntry(int ID) = 0;
360 };
361   
362
363 /// IsBeforeInTranslationUnitCache - This class holds the cache used by
364 /// isBeforeInTranslationUnit.  The cache structure is complex enough to be
365 /// worth breaking out of SourceManager.
366 class IsBeforeInTranslationUnitCache {
367   /// L/R QueryFID - These are the FID's of the cached query.  If these match up
368   /// with a subsequent query, the result can be reused.
369   FileID LQueryFID, RQueryFID;
370
371   /// \brief True if LQueryFID was created before RQueryFID. This is used
372   /// to compare macro expansion locations.
373   bool IsLQFIDBeforeRQFID;
374
375   /// CommonFID - This is the file found in common between the two #include
376   /// traces.  It is the nearest common ancestor of the #include tree.
377   FileID CommonFID;
378   
379   /// L/R CommonOffset - This is the offset of the previous query in CommonFID.
380   /// Usually, this represents the location of the #include for QueryFID, but if
381   /// LQueryFID is a parent of RQueryFID (or vise versa) then these can be a
382   /// random token in the parent.
383   unsigned LCommonOffset, RCommonOffset;
384 public:
385   
386   /// isCacheValid - Return true if the currently cached values match up with
387   /// the specified LHS/RHS query.  If not, we can't use the cache.
388   bool isCacheValid(FileID LHS, FileID RHS) const {
389     return LQueryFID == LHS && RQueryFID == RHS;
390   }
391   
392   /// getCachedResult - If the cache is valid, compute the result given the
393   /// specified offsets in the LHS/RHS FID's.
394   bool getCachedResult(unsigned LOffset, unsigned ROffset) const {
395     // If one of the query files is the common file, use the offset.  Otherwise,
396     // use the #include loc in the common file.
397     if (LQueryFID != CommonFID) LOffset = LCommonOffset;
398     if (RQueryFID != CommonFID) ROffset = RCommonOffset;
399
400     // It is common for multiple macro expansions to be "included" from the same
401     // location (expansion location), in which case use the order of the FileIDs
402     // to determine which came first.
403     if (LOffset == ROffset && LQueryFID != CommonFID && RQueryFID != CommonFID)
404       return IsLQFIDBeforeRQFID;
405
406     return LOffset < ROffset;
407   }
408   
409   // Set up a new query.
410   void setQueryFIDs(FileID LHS, FileID RHS, bool isLFIDBeforeRFID) {
411     assert(LHS != RHS);
412     LQueryFID = LHS;
413     RQueryFID = RHS;
414     IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
415   }
416
417   void clear() {
418     LQueryFID = RQueryFID = FileID();
419     IsLQFIDBeforeRQFID = false;
420   }
421   
422   void setCommonLoc(FileID commonFID, unsigned lCommonOffset,
423                     unsigned rCommonOffset) {
424     CommonFID = commonFID;
425     LCommonOffset = lCommonOffset;
426     RCommonOffset = rCommonOffset;
427   }
428   
429 };
430
431 /// \brief This class handles loading and caching of source files into memory.
432 ///
433 /// This object owns the MemoryBuffer objects for all of the loaded
434 /// files and assigns unique FileID's for each unique #include chain.
435 ///
436 /// The SourceManager can be queried for information about SourceLocation
437 /// objects, turning them into either spelling or expansion locations. Spelling
438 /// locations represent where the bytes corresponding to a token came from and
439 /// expansion locations represent where the location is in the user's view. In
440 /// the case of a macro expansion, for example, the spelling location indicates
441 /// where the expanded token came from and the expansion location specifies
442 /// where it was expanded.
443 class SourceManager : public llvm::RefCountedBase<SourceManager> {
444   /// \brief Diagnostic object.
445   Diagnostic &Diag;
446
447   FileManager &FileMgr;
448
449   mutable llvm::BumpPtrAllocator ContentCacheAlloc;
450
451   /// FileInfos - Memoized information about all of the files tracked by this
452   /// SourceManager.  This set allows us to merge ContentCache entries based
453   /// on their FileEntry*.  All ContentCache objects will thus have unique,
454   /// non-null, FileEntry pointers.
455   llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
456
457   /// \brief True if the ContentCache for files that are overriden by other
458   /// files, should report the original file name. Defaults to true.
459   bool OverridenFilesKeepOriginalName;
460
461   /// \brief Files that have been overriden with the contents from another file.
462   llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
463
464   /// MemBufferInfos - Information about various memory buffers that we have
465   /// read in.  All FileEntry* within the stored ContentCache objects are NULL,
466   /// as they do not refer to a file.
467   std::vector<SrcMgr::ContentCache*> MemBufferInfos;
468
469   /// \brief The table of SLocEntries that are local to this module.
470   ///
471   /// Positive FileIDs are indexes into this table. Entry 0 indicates an invalid
472   /// expansion.
473   std::vector<SrcMgr::SLocEntry> LocalSLocEntryTable;
474
475   /// \brief The table of SLocEntries that are loaded from other modules.
476   ///
477   /// Negative FileIDs are indexes into this table. To get from ID to an index,
478   /// use (-ID - 2).
479   std::vector<SrcMgr::SLocEntry> LoadedSLocEntryTable;
480
481   /// \brief The starting offset of the next local SLocEntry.
482   ///
483   /// This is LocalSLocEntryTable.back().Offset + the size of that entry.
484   unsigned NextLocalOffset;
485
486   /// \brief The starting offset of the latest batch of loaded SLocEntries.
487   ///
488   /// This is LoadedSLocEntryTable.back().Offset, except that that entry might
489   /// not have been loaded, so that value would be unknown.
490   unsigned CurrentLoadedOffset;
491
492   /// \brief A bitmap that indicates whether the entries of LoadedSLocEntryTable
493   /// have already been loaded from the external source.
494   ///
495   /// Same indexing as LoadedSLocEntryTable.
496   std::vector<bool> SLocEntryLoaded;
497
498   /// \brief An external source for source location entries.
499   ExternalSLocEntrySource *ExternalSLocEntries;
500
501   /// LastFileIDLookup - This is a one-entry cache to speed up getFileID.
502   /// LastFileIDLookup records the last FileID looked up or created, because it
503   /// is very common to look up many tokens from the same file.
504   mutable FileID LastFileIDLookup;
505
506   /// LineTable - This holds information for #line directives.  It is referenced
507   /// by indices from SLocEntryTable.
508   LineTableInfo *LineTable;
509
510   /// LastLineNo - These ivars serve as a cache used in the getLineNumber
511   /// method which is used to speedup getLineNumber calls to nearby locations.
512   mutable FileID LastLineNoFileIDQuery;
513   mutable SrcMgr::ContentCache *LastLineNoContentCache;
514   mutable unsigned LastLineNoFilePos;
515   mutable unsigned LastLineNoResult;
516
517   /// MainFileID - The file ID for the main source file of the translation unit.
518   FileID MainFileID;
519
520   // Statistics for -print-stats.
521   mutable unsigned NumLinearScans, NumBinaryProbes;
522
523   // Cache results for the isBeforeInTranslationUnit method.
524   mutable IsBeforeInTranslationUnitCache IsBeforeInTUCache;
525
526   // Cache for the "fake" buffer used for error-recovery purposes.
527   mutable llvm::MemoryBuffer *FakeBufferForRecovery;
528   
529   // SourceManager doesn't support copy construction.
530   explicit SourceManager(const SourceManager&);
531   void operator=(const SourceManager&);
532 public:
533   SourceManager(Diagnostic &Diag, FileManager &FileMgr);
534   ~SourceManager();
535
536   void clearIDTables();
537
538   Diagnostic &getDiagnostics() const { return Diag; }
539
540   FileManager &getFileManager() const { return FileMgr; }
541
542   /// \brief Set true if the SourceManager should report the original file name
543   /// for contents of files that were overriden by other files.Defaults to true.
544   void setOverridenFilesKeepOriginalName(bool value) {
545     OverridenFilesKeepOriginalName = value;
546   }
547
548   /// createMainFileIDForMembuffer - Create the FileID for a memory buffer
549   ///  that will represent the FileID for the main source.  One example
550   ///  of when this would be used is when the main source is read from STDIN.
551   FileID createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
552     assert(MainFileID.isInvalid() && "MainFileID already set!");
553     MainFileID = createFileIDForMemBuffer(Buffer);
554     return MainFileID;
555   }
556
557   //===--------------------------------------------------------------------===//
558   // MainFileID creation and querying methods.
559   //===--------------------------------------------------------------------===//
560
561   /// getMainFileID - Returns the FileID of the main source file.
562   FileID getMainFileID() const { return MainFileID; }
563
564   /// createMainFileID - Create the FileID for the main source file.
565   FileID createMainFileID(const FileEntry *SourceFile) {
566     assert(MainFileID.isInvalid() && "MainFileID already set!");
567     MainFileID = createFileID(SourceFile, SourceLocation(), SrcMgr::C_User);
568     return MainFileID;
569   }
570
571   /// \brief Set the file ID for the precompiled preamble, which is also the
572   /// main file.
573   void SetPreambleFileID(FileID Preamble) {
574     assert(MainFileID.isInvalid() && "MainFileID already set!");
575     MainFileID = Preamble;
576   }
577   
578   //===--------------------------------------------------------------------===//
579   // Methods to create new FileID's and macro expansions.
580   //===--------------------------------------------------------------------===//
581
582   /// createFileID - Create a new FileID that represents the specified file
583   /// being #included from the specified IncludePosition.  This translates NULL
584   /// into standard input.
585   FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos,
586                       SrcMgr::CharacteristicKind FileCharacter,
587                       int LoadedID = 0, unsigned LoadedOffset = 0) {
588     const SrcMgr::ContentCache *IR = getOrCreateContentCache(SourceFile);
589     assert(IR && "getOrCreateContentCache() cannot return NULL");
590     return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
591   }
592
593   /// createFileIDForMemBuffer - Create a new FileID that represents the
594   /// specified memory buffer.  This does no caching of the buffer and takes
595   /// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.
596   FileID createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer,
597                                   int LoadedID = 0, unsigned LoadedOffset = 0) {
598     return createFileID(createMemBufferContentCache(Buffer), SourceLocation(),
599                         SrcMgr::C_User, LoadedID, LoadedOffset);
600   }
601
602   /// createMacroArgExpansionLoc - Return a new SourceLocation that encodes the
603   /// fact that a token from SpellingLoc should actually be referenced from
604   /// ExpansionLoc, and that it represents the expansion of a macro argument
605   /// into the function-like macro body.
606   SourceLocation createMacroArgExpansionLoc(SourceLocation Loc,
607                                             SourceLocation ExpansionLoc,
608                                             unsigned TokLength);
609
610   /// createExpansionLoc - Return a new SourceLocation that encodes the fact
611   /// that a token from SpellingLoc should actually be referenced from
612   /// ExpansionLoc.
613   SourceLocation createExpansionLoc(SourceLocation Loc,
614                                     SourceLocation ExpansionLocStart,
615                                     SourceLocation ExpansionLocEnd,
616                                     unsigned TokLength,
617                                     int LoadedID = 0,
618                                     unsigned LoadedOffset = 0);
619
620   /// \brief Retrieve the memory buffer associated with the given file.
621   ///
622   /// \param Invalid If non-NULL, will be set \c true if an error
623   /// occurs while retrieving the memory buffer.
624   const llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File,
625                                                    bool *Invalid = 0);
626
627   /// \brief Override the contents of the given source file by providing an
628   /// already-allocated buffer.
629   ///
630   /// \param SourceFile the source file whose contents will be overriden.
631   ///
632   /// \param Buffer the memory buffer whose contents will be used as the
633   /// data in the given source file.
634   ///
635   /// \param DoNotFree If true, then the buffer will not be freed when the
636   /// source manager is destroyed.
637   void overrideFileContents(const FileEntry *SourceFile,
638                             const llvm::MemoryBuffer *Buffer,
639                             bool DoNotFree = false);
640
641   /// \brief Override the the given source file with another one.
642   ///
643   /// \param SourceFile the source file which will be overriden.
644   ///
645   /// \param NewFile the file whose contents will be used as the
646   /// data instead of the contents of the given source file.
647   void overrideFileContents(const FileEntry *SourceFile,
648                             const FileEntry *NewFile);
649
650   //===--------------------------------------------------------------------===//
651   // FileID manipulation methods.
652   //===--------------------------------------------------------------------===//
653
654   /// getBuffer - Return the buffer for the specified FileID. If there is an
655   /// error opening this buffer the first time, this manufactures a temporary
656   /// buffer and returns a non-empty error string.
657   const llvm::MemoryBuffer *getBuffer(FileID FID, SourceLocation Loc,
658                                       bool *Invalid = 0) const {
659     bool MyInvalid = false;
660     const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid);
661     if (MyInvalid || !Entry.isFile()) {
662       if (Invalid)
663         *Invalid = true;
664       
665       return getFakeBufferForRecovery();
666     }
667         
668     return Entry.getFile().getContentCache()->getBuffer(Diag, *this, Loc, 
669                                                         Invalid);
670   }
671
672   const llvm::MemoryBuffer *getBuffer(FileID FID, bool *Invalid = 0) const {
673     bool MyInvalid = false;
674     const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid);
675     if (MyInvalid || !Entry.isFile()) {
676       if (Invalid)
677         *Invalid = true;
678       
679       return getFakeBufferForRecovery();
680     }
681
682     return Entry.getFile().getContentCache()->getBuffer(Diag, *this, 
683                                                         SourceLocation(), 
684                                                         Invalid);
685   }
686   
687   /// getFileEntryForID - Returns the FileEntry record for the provided FileID.
688   const FileEntry *getFileEntryForID(FileID FID) const {
689     bool MyInvalid = false;
690     const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid);
691     if (MyInvalid || !Entry.isFile())
692       return 0;
693     
694     return Entry.getFile().getContentCache()->OrigEntry;
695   }
696
697   /// Returns the FileEntry record for the provided SLocEntry.
698   const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
699   {
700     return sloc.getFile().getContentCache()->OrigEntry;
701   }
702
703   /// getBufferData - Return a StringRef to the source buffer data for the
704   /// specified FileID.
705   ///
706   /// \param FID The file ID whose contents will be returned.
707   /// \param Invalid If non-NULL, will be set true if an error occurred.
708   StringRef getBufferData(FileID FID, bool *Invalid = 0) const;
709
710
711   //===--------------------------------------------------------------------===//
712   // SourceLocation manipulation methods.
713   //===--------------------------------------------------------------------===//
714
715   /// getFileID - Return the FileID for a SourceLocation.  This is a very
716   /// hot method that is used for all SourceManager queries that start with a
717   /// SourceLocation object.  It is responsible for finding the entry in
718   /// SLocEntryTable which contains the specified location.
719   ///
720   FileID getFileID(SourceLocation SpellingLoc) const {
721     unsigned SLocOffset = SpellingLoc.getOffset();
722
723     // If our one-entry cache covers this offset, just return it.
724     if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
725       return LastFileIDLookup;
726
727     return getFileIDSlow(SLocOffset);
728   }
729
730   /// getLocForStartOfFile - Return the source location corresponding to the
731   /// first byte of the specified file.
732   SourceLocation getLocForStartOfFile(FileID FID) const {
733     bool Invalid = false;
734     const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
735     if (Invalid || !Entry.isFile())
736       return SourceLocation();
737     
738     unsigned FileOffset = Entry.getOffset();
739     return SourceLocation::getFileLoc(FileOffset);
740   }
741
742   /// getExpansionLoc - Given a SourceLocation object, return the expansion
743   /// location referenced by the ID.
744   SourceLocation getExpansionLoc(SourceLocation Loc) const {
745     // Handle the non-mapped case inline, defer to out of line code to handle
746     // expansions.
747     if (Loc.isFileID()) return Loc;
748     return getExpansionLocSlowCase(Loc);
749   }
750
751   /// getImmediateExpansionRange - Loc is required to be an expansion location.
752   /// Return the start/end of the expansion information.
753   std::pair<SourceLocation,SourceLocation>
754   getImmediateExpansionRange(SourceLocation Loc) const;
755
756   /// getExpansionRange - Given a SourceLocation object, return the range of
757   /// tokens covered by the expansion the ultimate file.
758   std::pair<SourceLocation,SourceLocation>
759   getExpansionRange(SourceLocation Loc) const;
760
761
762   /// getSpellingLoc - Given a SourceLocation object, return the spelling
763   /// location referenced by the ID.  This is the place where the characters
764   /// that make up the lexed token can be found.
765   SourceLocation getSpellingLoc(SourceLocation Loc) const {
766     // Handle the non-mapped case inline, defer to out of line code to handle
767     // expansions.
768     if (Loc.isFileID()) return Loc;
769     return getSpellingLocSlowCase(Loc);
770   }
771
772   /// getImmediateSpellingLoc - Given a SourceLocation object, return the
773   /// spelling location referenced by the ID.  This is the first level down
774   /// towards the place where the characters that make up the lexed token can be
775   /// found.  This should not generally be used by clients.
776   SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const;
777
778   /// getDecomposedLoc - Decompose the specified location into a raw FileID +
779   /// Offset pair.  The first element is the FileID, the second is the
780   /// offset from the start of the buffer of the location.
781   std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const {
782     FileID FID = getFileID(Loc);
783     return std::make_pair(FID, Loc.getOffset()-getSLocEntry(FID).getOffset());
784   }
785
786   /// getDecomposedExpansionLoc - Decompose the specified location into a raw
787   /// FileID + Offset pair. If the location is an expansion record, walk
788   /// through it until we find the final location expanded.
789   std::pair<FileID, unsigned>
790   getDecomposedExpansionLoc(SourceLocation Loc) const {
791     FileID FID = getFileID(Loc);
792     const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
793
794     unsigned Offset = Loc.getOffset()-E->getOffset();
795     if (Loc.isFileID())
796       return std::make_pair(FID, Offset);
797
798     return getDecomposedExpansionLocSlowCase(E);
799   }
800
801   /// getDecomposedSpellingLoc - Decompose the specified location into a raw
802   /// FileID + Offset pair.  If the location is an expansion record, walk
803   /// through it until we find its spelling record.
804   std::pair<FileID, unsigned>
805   getDecomposedSpellingLoc(SourceLocation Loc) const {
806     FileID FID = getFileID(Loc);
807     const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
808
809     unsigned Offset = Loc.getOffset()-E->getOffset();
810     if (Loc.isFileID())
811       return std::make_pair(FID, Offset);
812     return getDecomposedSpellingLocSlowCase(E, Offset);
813   }
814
815   /// getFileOffset - This method returns the offset from the start
816   /// of the file that the specified SourceLocation represents. This is not very
817   /// meaningful for a macro ID.
818   unsigned getFileOffset(SourceLocation SpellingLoc) const {
819     return getDecomposedLoc(SpellingLoc).second;
820   }
821
822   /// isMacroArgExpansion - This method tests whether the given source location
823   /// represents a macro argument's expansion into the function-like macro
824   /// definition. Such source locations only appear inside of the expansion
825   /// locations representing where a particular function-like macro was
826   /// expanded.
827   bool isMacroArgExpansion(SourceLocation Loc) const;
828
829   //===--------------------------------------------------------------------===//
830   // Queries about the code at a SourceLocation.
831   //===--------------------------------------------------------------------===//
832
833   /// getCharacterData - Return a pointer to the start of the specified location
834   /// in the appropriate spelling MemoryBuffer.
835   ///
836   /// \param Invalid If non-NULL, will be set \c true if an error occurs.
837   const char *getCharacterData(SourceLocation SL, bool *Invalid = 0) const;
838
839   /// getColumnNumber - Return the column # for the specified file position.
840   /// This is significantly cheaper to compute than the line number.  This
841   /// returns zero if the column number isn't known.  This may only be called
842   /// on a file sloc, so you must choose a spelling or expansion location
843   /// before calling this method.
844   unsigned getColumnNumber(FileID FID, unsigned FilePos, 
845                            bool *Invalid = 0) const;
846   unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid = 0) const;
847   unsigned getExpansionColumnNumber(SourceLocation Loc,
848                                     bool *Invalid = 0) const;
849   unsigned getPresumedColumnNumber(SourceLocation Loc, bool *Invalid = 0) const;
850
851
852   /// getLineNumber - Given a SourceLocation, return the spelling line number
853   /// for the position indicated.  This requires building and caching a table of
854   /// line offsets for the MemoryBuffer, so this is not cheap: use only when
855   /// about to emit a diagnostic.
856   unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = 0) const;
857   unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
858   unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
859   unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
860
861   /// Return the filename or buffer identifier of the buffer the location is in.
862   /// Note that this name does not respect #line directives.  Use getPresumedLoc
863   /// for normal clients.
864   const char *getBufferName(SourceLocation Loc, bool *Invalid = 0) const;
865
866   /// getFileCharacteristic - return the file characteristic of the specified
867   /// source location, indicating whether this is a normal file, a system
868   /// header, or an "implicit extern C" system header.
869   ///
870   /// This state can be modified with flags on GNU linemarker directives like:
871   ///   # 4 "foo.h" 3
872   /// which changes all source locations in the current file after that to be
873   /// considered to be from a system header.
874   SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const;
875
876   /// getPresumedLoc - This method returns the "presumed" location of a
877   /// SourceLocation specifies.  A "presumed location" can be modified by #line
878   /// or GNU line marker directives.  This provides a view on the data that a
879   /// user should see in diagnostics, for example.
880   ///
881   /// Note that a presumed location is always given as the expansion point of
882   /// an expansion location, not at the spelling location.
883   ///
884   /// \returns The presumed location of the specified SourceLocation. If the
885   /// presumed location cannot be calculate (e.g., because \p Loc is invalid
886   /// or the file containing \p Loc has changed on disk), returns an invalid
887   /// presumed location.
888   PresumedLoc getPresumedLoc(SourceLocation Loc) const;
889
890   /// isFromSameFile - Returns true if both SourceLocations correspond to
891   ///  the same file.
892   bool isFromSameFile(SourceLocation Loc1, SourceLocation Loc2) const {
893     return getFileID(Loc1) == getFileID(Loc2);
894   }
895
896   /// isFromMainFile - Returns true if the file of provided SourceLocation is
897   ///   the main file.
898   bool isFromMainFile(SourceLocation Loc) const {
899     return getFileID(Loc) == getMainFileID();
900   }
901
902   /// isInSystemHeader - Returns if a SourceLocation is in a system header.
903   bool isInSystemHeader(SourceLocation Loc) const {
904     return getFileCharacteristic(Loc) != SrcMgr::C_User;
905   }
906
907   /// isInExternCSystemHeader - Returns if a SourceLocation is in an "extern C"
908   /// system header.
909   bool isInExternCSystemHeader(SourceLocation Loc) const {
910     return getFileCharacteristic(Loc) == SrcMgr::C_ExternCSystem;
911   }
912
913   /// \brief Given a specific chunk of a FileID (FileID with offset+length),
914   /// returns true if \arg Loc is inside that chunk and sets relative offset
915   /// (offset of \arg Loc from beginning of chunk) to \arg relativeOffset.
916   bool isInFileID(SourceLocation Loc,
917                   FileID FID, unsigned offset, unsigned length,
918                   unsigned *relativeOffset = 0) const {
919     assert(!FID.isInvalid());
920     if (Loc.isInvalid())
921       return false;
922
923     unsigned start = getSLocEntry(FID).getOffset() + offset;
924     unsigned end = start + length;
925
926 #ifndef NDEBUG
927     // Make sure offset/length describe a chunk inside the given FileID.
928     unsigned NextOffset;
929     if (FID.ID == -2)
930       NextOffset = 1U << 31U;
931     else if (FID.ID+1 == (int)LocalSLocEntryTable.size())
932       NextOffset = getNextLocalOffset();
933     else
934       NextOffset = getSLocEntryByID(FID.ID+1).getOffset();
935     assert(start < NextOffset);
936     assert(end   < NextOffset);
937 #endif
938
939     if (Loc.getOffset() >= start && Loc.getOffset() < end) {
940       if (relativeOffset)
941         *relativeOffset = Loc.getOffset() - start;
942       return true;
943     }
944
945     return false;
946   }
947
948   //===--------------------------------------------------------------------===//
949   // Line Table Manipulation Routines
950   //===--------------------------------------------------------------------===//
951
952   /// getLineTableFilenameID - Return the uniqued ID for the specified filename.
953   ///
954   unsigned getLineTableFilenameID(StringRef Str);
955
956   /// AddLineNote - Add a line note to the line table for the FileID and offset
957   /// specified by Loc.  If FilenameID is -1, it is considered to be
958   /// unspecified.
959   void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID);
960   void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID,
961                    bool IsFileEntry, bool IsFileExit,
962                    bool IsSystemHeader, bool IsExternCHeader);
963
964   /// \brief Determine if the source manager has a line table.
965   bool hasLineTable() const { return LineTable != 0; }
966
967   /// \brief Retrieve the stored line table.
968   LineTableInfo &getLineTable();
969
970   //===--------------------------------------------------------------------===//
971   // Queries for performance analysis.
972   //===--------------------------------------------------------------------===//
973
974   /// Return the total amount of physical memory allocated by the
975   /// ContentCache allocator.
976   size_t getContentCacheSize() const {
977     return ContentCacheAlloc.getTotalMemory();
978   }
979   
980   struct MemoryBufferSizes {
981     const size_t malloc_bytes;
982     const size_t mmap_bytes;
983     
984     MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
985       : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
986   };
987
988   /// Return the amount of memory used by memory buffers, breaking down
989   /// by heap-backed versus mmap'ed memory.
990   MemoryBufferSizes getMemoryBufferSizes() const;
991   
992   // Return the amount of memory used for various side tables and
993   // data structures in the SourceManager.
994   size_t getDataStructureSizes() const;
995
996   //===--------------------------------------------------------------------===//
997   // Other miscellaneous methods.
998   //===--------------------------------------------------------------------===//
999
1000   /// \brief Get the source location for the given file:line:col triplet.
1001   ///
1002   /// If the source file is included multiple times, the source location will
1003   /// be based upon the first inclusion.
1004   SourceLocation getLocation(const FileEntry *SourceFile,
1005                              unsigned Line, unsigned Col);
1006
1007   /// \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.
1010   bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const;
1011
1012   /// \brief Determines the order of 2 source locations in the "source location
1013   /// address space".
1014   bool isBeforeInSourceLocationOffset(SourceLocation LHS, 
1015                                       SourceLocation RHS) const {
1016     return isBeforeInSourceLocationOffset(LHS, RHS.getOffset());
1017   }
1018
1019   /// \brief Determines the order of a source location and a source location
1020   /// offset in the "source location address space".
1021   ///
1022   /// Note that we always consider source locations loaded from 
1023   bool isBeforeInSourceLocationOffset(SourceLocation LHS, unsigned RHS) const {
1024     unsigned LHSOffset = LHS.getOffset();
1025     bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1026     bool RHSLoaded = RHS >= CurrentLoadedOffset;
1027     if (LHSLoaded == RHSLoaded)
1028       return LHS.getOffset() < RHS;
1029     
1030     return LHSLoaded;
1031   }
1032
1033   // Iterators over FileInfos.
1034   typedef llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>
1035       ::const_iterator fileinfo_iterator;
1036   fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); }
1037   fileinfo_iterator fileinfo_end() const { return FileInfos.end(); }
1038   bool hasFileInfo(const FileEntry *File) const {
1039     return FileInfos.find(File) != FileInfos.end();
1040   }
1041
1042   /// PrintStats - Print statistics to stderr.
1043   ///
1044   void PrintStats() const;
1045
1046   /// \brief Get the number of local SLocEntries we have.
1047   unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); }
1048   
1049   /// \brief Get a local SLocEntry. This is exposed for indexing.
1050   const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index, 
1051                                              bool *Invalid = 0) const {
1052     assert(Index < LocalSLocEntryTable.size() && "Invalid index");
1053     return LocalSLocEntryTable[Index];
1054   }
1055   
1056   /// \brief Get the number of loaded SLocEntries we have.
1057   unsigned loaded_sloc_entry_size() const { return LoadedSLocEntryTable.size();}
1058   
1059   /// \brief Get a loaded SLocEntry. This is exposed for indexing.
1060   const SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index, bool *Invalid=0) const {
1061     assert(Index < LoadedSLocEntryTable.size() && "Invalid index");
1062     if (!SLocEntryLoaded[Index])
1063       ExternalSLocEntries->ReadSLocEntry(-(static_cast<int>(Index) + 2));
1064     return LoadedSLocEntryTable[Index];
1065   }
1066   
1067   const SrcMgr::SLocEntry &getSLocEntry(FileID FID, bool *Invalid = 0) const {
1068     return getSLocEntryByID(FID.ID);
1069   }
1070
1071   unsigned getNextLocalOffset() const { return NextLocalOffset; }
1072   
1073   void setExternalSLocEntrySource(ExternalSLocEntrySource *Source) {
1074     assert(LoadedSLocEntryTable.empty() &&
1075            "Invalidating existing loaded entries");
1076     ExternalSLocEntries = Source;
1077   }
1078   
1079   /// \brief Allocate a number of loaded SLocEntries, which will be actually
1080   /// loaded on demand from the external source.
1081   ///
1082   /// NumSLocEntries will be allocated, which occupy a total of TotalSize space
1083   /// in the global source view. The lowest ID and the base offset of the
1084   /// entries will be returned.
1085   std::pair<int, unsigned>
1086   AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize);
1087   
1088 private:
1089   const llvm::MemoryBuffer *getFakeBufferForRecovery() const;
1090
1091   /// \brief Get the entry with the given unwrapped FileID.
1092   const SrcMgr::SLocEntry &getSLocEntryByID(int ID) const {
1093     assert(ID != -1 && "Using FileID sentinel value");
1094     if (ID < 0)
1095       return getLoadedSLocEntryByID(ID);
1096     return getLocalSLocEntry(static_cast<unsigned>(ID));
1097   }
1098   
1099   const SrcMgr::SLocEntry &getLoadedSLocEntryByID(int ID) const {
1100     return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2));
1101   }
1102   
1103   /// createExpansionLoc - Implements the common elements of storing an
1104   /// expansion info struct into the SLocEntry table and producing a source
1105   /// location that refers to it.
1106   SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion,
1107                                         unsigned TokLength,
1108                                         int LoadedID = 0,
1109                                         unsigned LoadedOffset = 0);
1110
1111   /// isOffsetInFileID - Return true if the specified FileID contains the
1112   /// specified SourceLocation offset.  This is a very hot method.
1113   inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const {
1114     const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);
1115     // If the entry is after the offset, it can't contain it.
1116     if (SLocOffset < Entry.getOffset()) return false;
1117
1118     // If this is the very last entry then it does.
1119     if (FID.ID == -2)
1120       return true;
1121
1122     // If it is the last local entry, then it does if the location is local.
1123     if (static_cast<unsigned>(FID.ID+1) == LocalSLocEntryTable.size()) {
1124       return SLocOffset < NextLocalOffset;
1125     }
1126
1127     // Otherwise, the entry after it has to not include it. This works for both
1128     // local and loaded entries.
1129     return SLocOffset < getSLocEntry(FileID::get(FID.ID+1)).getOffset();
1130   }
1131
1132   /// createFileID - Create a new fileID for the specified ContentCache and
1133   ///  include position.  This works regardless of whether the ContentCache
1134   ///  corresponds to a file or some other input source.
1135   FileID createFileID(const SrcMgr::ContentCache* File,
1136                       SourceLocation IncludePos,
1137                       SrcMgr::CharacteristicKind DirCharacter,
1138                       int LoadedID, unsigned LoadedOffset);
1139
1140   const SrcMgr::ContentCache *
1141     getOrCreateContentCache(const FileEntry *SourceFile);
1142
1143   /// createMemBufferContentCache - Create a new ContentCache for the specified
1144   ///  memory buffer.
1145   const SrcMgr::ContentCache*
1146   createMemBufferContentCache(const llvm::MemoryBuffer *Buf);
1147
1148   FileID getFileIDSlow(unsigned SLocOffset) const;
1149   FileID getFileIDLocal(unsigned SLocOffset) const;
1150   FileID getFileIDLoaded(unsigned SLocOffset) const;
1151
1152   SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const;
1153   SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
1154
1155   std::pair<FileID, unsigned>
1156   getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const;
1157   std::pair<FileID, unsigned>
1158   getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
1159                                    unsigned Offset) const;
1160 };
1161
1162
1163 }  // end namespace clang
1164
1165 #endif