SourceManager.h revision 464c4b3fdd473c9722cc00e7ef5f9929578f9c46
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/SourceLocation.h"
18#include "llvm/Bitcode/SerializationFwd.h"
19#include "llvm/Support/DataTypes.h"
20#include <vector>
21#include <set>
22#include <list>
23#include <cassert>
24
25namespace llvm {
26class MemoryBuffer;
27}
28
29namespace clang {
30
31class SourceManager;
32class FileManager;
33class FileEntry;
34class IdentifierTokenInfo;
35class LineTableInfo;
36
37/// SrcMgr - Public enums and private classes that are part of the
38/// SourceManager implementation.
39///
40namespace SrcMgr {
41  /// CharacteristicKind - This is used to represent whether a file or directory
42  /// holds normal user code, system code, or system code which is implicitly
43  /// 'extern "C"' in C++ mode.  Entire directories can be tagged with this
44  /// (this is maintained by DirectoryLookup and friends) as can specific
45  /// FileIDInfos when a #pragma system_header is seen or various other cases.
46  ///
47  enum CharacteristicKind {
48    C_User, C_System, C_ExternCSystem
49  };
50
51  /// ContentCache - Once instance of this struct is kept for every file
52  /// loaded or used.  This object owns the MemoryBuffer object.
53  class ContentCache {
54    /// Buffer - The actual buffer containing the characters from the input
55    /// file.  This is owned by the ContentCache object.
56    mutable const llvm::MemoryBuffer *Buffer;
57
58  public:
59    /// Reference to the file entry.  This reference does not own
60    /// the FileEntry object.  It is possible for this to be NULL if
61    /// the ContentCache encapsulates an imaginary text buffer.
62    const FileEntry *Entry;
63
64    /// SourceLineCache - A new[]'d array of offsets for each source line.  This
65    /// is lazily computed.  This is owned by the ContentCache object.
66    unsigned *SourceLineCache;
67
68    /// NumLines - The number of lines in this ContentCache.  This is only valid
69    /// if SourceLineCache is non-null.
70    unsigned NumLines;
71
72    /// getBuffer - Returns the memory buffer for the associated content.
73    const llvm::MemoryBuffer *getBuffer() const;
74
75    /// getSize - Returns the size of the content encapsulated by this
76    ///  ContentCache. This can be the size of the source file or the size of an
77    ///  arbitrary scratch buffer.  If the ContentCache encapsulates a source
78    ///  file this size is retrieved from the file's FileEntry.
79    unsigned getSize() const;
80
81    /// getSizeBytesMapped - Returns the number of bytes actually mapped for
82    ///  this ContentCache.  This can be 0 if the MemBuffer was not actually
83    ///  instantiated.
84    unsigned getSizeBytesMapped() const;
85
86    void setBuffer(const llvm::MemoryBuffer *B) {
87      assert(!Buffer && "MemoryBuffer already set.");
88      Buffer = B;
89    }
90
91    ContentCache(const FileEntry *e = NULL)
92      : Buffer(NULL), Entry(e), SourceLineCache(NULL), NumLines(0) {}
93
94    ~ContentCache();
95
96    /// The copy ctor does not allow copies where source object has either
97    ///  a non-NULL Buffer or SourceLineCache.  Ownership of allocated memory
98    ///  is not transfered, so this is a logical error.
99    ContentCache(const ContentCache &RHS) : Buffer(NULL),SourceLineCache(NULL) {
100      Entry = RHS.Entry;
101
102      assert (RHS.Buffer == NULL && RHS.SourceLineCache == NULL
103              && "Passed ContentCache object cannot own a buffer.");
104
105      NumLines = RHS.NumLines;
106    }
107
108    /// Emit - Emit this ContentCache to Bitcode.
109    void Emit(llvm::Serializer &S) const;
110
111    /// ReadToSourceManager - Reconstitute a ContentCache from Bitcode
112    //   and store it in the specified SourceManager.
113    static void ReadToSourceManager(llvm::Deserializer &D, SourceManager &SM,
114                                    FileManager *FMgr, std::vector<char> &Buf);
115
116  private:
117    // Disable assignments.
118    ContentCache &operator=(const ContentCache& RHS);
119  };
120
121  /// FileInfo - Information about a FileID, basically just the logical file
122  /// that it represents and include stack information.
123  ///
124  /// Each FileInfo has include stack information, indicating where it came
125  /// from.  This information encodes the #include chain that a token was
126  /// instantiated from.  The main include file has an invalid IncludeLoc.
127  ///
128  /// FileInfos contain a "ContentCache *", with the contents of the file.
129  ///
130  class FileInfo {
131    /// IncludeLoc - The location of the #include that brought in this file.
132    /// This is an invalid SLOC for the main file (top of the #include chain).
133    unsigned IncludeLoc;  // Really a SourceLocation
134
135    /// Data - This contains the ContentCache* and the bits indicating the
136    /// characteristic of the file and whether it has #line info, all bitmangled
137    /// together.
138    uintptr_t Data;
139  public:
140    /// get - Return a FileInfo object.
141    static FileInfo get(SourceLocation IL, const ContentCache *Con,
142                        CharacteristicKind FileCharacter) {
143      FileInfo X;
144      X.IncludeLoc = IL.getRawEncoding();
145      X.Data = (uintptr_t)Con;
146      assert((X.Data & 7) == 0 &&"ContentCache pointer insufficiently aligned");
147      assert((unsigned)FileCharacter < 4 && "invalid file character");
148      X.Data |= (unsigned)FileCharacter;
149      return X;
150    }
151
152    SourceLocation getIncludeLoc() const {
153      return SourceLocation::getFromRawEncoding(IncludeLoc);
154    }
155    const ContentCache* getContentCache() const {
156      return reinterpret_cast<const ContentCache*>(Data & ~7UL);
157    }
158
159    /// getCharacteristic - Return whether this is a system header or not.
160    CharacteristicKind getFileCharacteristic() const {
161      return (CharacteristicKind)(Data & 3);
162    }
163  };
164
165  /// InstantiationInfo - Each InstantiationInfo encodes the Instantiation
166  /// location - where the token was ultimately instantiated, and the
167  /// SpellingLoc - where the actual character data for the token came from.
168  class InstantiationInfo {
169    unsigned InstantiationLoc, SpellingLoc; // Really these are SourceLocations.
170  public:
171    SourceLocation getInstantiationLoc() const {
172      return SourceLocation::getFromRawEncoding(InstantiationLoc);
173    }
174    SourceLocation getSpellingLoc() const {
175      return SourceLocation::getFromRawEncoding(SpellingLoc);
176    }
177
178    /// get - Return a InstantiationInfo for an expansion.  VL specifies
179    /// the instantiation location (where the macro is expanded), and SL
180    /// specifies the spelling location (where the characters from the token
181    /// come from).  Both VL and PL refer to normal File SLocs.
182    static InstantiationInfo get(SourceLocation IL, SourceLocation SL) {
183      InstantiationInfo X;
184      X.InstantiationLoc = IL.getRawEncoding();
185      X.SpellingLoc = SL.getRawEncoding();
186      return X;
187    }
188  };
189
190  /// SLocEntry - This is a discriminated union of FileInfo and
191  /// InstantiationInfo.  SourceManager keeps an array of these objects, and
192  /// they are uniquely identified by the FileID datatype.
193  class SLocEntry {
194    unsigned Offset;   // low bit is set for instantiation info.
195    union {
196      FileInfo File;
197      InstantiationInfo Instantiation;
198    };
199  public:
200    unsigned getOffset() const { return Offset >> 1; }
201
202    bool isInstantiation() const { return Offset & 1; }
203    bool isFile() const { return !isInstantiation(); }
204
205    const FileInfo &getFile() const {
206      assert(isFile() && "Not a file SLocEntry!");
207      return File;
208    }
209
210    const InstantiationInfo &getInstantiation() const {
211      assert(isInstantiation() && "Not an instantiation SLocEntry!");
212      return Instantiation;
213    }
214
215    static SLocEntry get(unsigned Offset, const FileInfo &FI) {
216      SLocEntry E;
217      E.Offset = Offset << 1;
218      E.File = FI;
219      return E;
220    }
221
222    static SLocEntry get(unsigned Offset, const InstantiationInfo &II) {
223      SLocEntry E;
224      E.Offset = (Offset << 1) | 1;
225      E.Instantiation = II;
226      return E;
227    }
228  };
229}  // end SrcMgr namespace.
230} // end clang namespace
231
232namespace std {
233template <> struct less<clang::SrcMgr::ContentCache> {
234  inline bool operator()(const clang::SrcMgr::ContentCache& L,
235                         const clang::SrcMgr::ContentCache& R) const {
236    return L.Entry < R.Entry;
237  }
238};
239} // end std namespace
240
241namespace clang {
242
243/// SourceManager - This file handles loading and caching of source files into
244/// memory.  This object owns the MemoryBuffer objects for all of the loaded
245/// files and assigns unique FileID's for each unique #include chain.
246///
247/// The SourceManager can be queried for information about SourceLocation
248/// objects, turning them into either spelling or instantiation locations.
249/// Spelling locations represent where the bytes corresponding to a token came
250/// from and instantiation locations represent where the location is in the
251/// user's view.  In the case of a macro expansion, for example, the spelling
252/// location indicates where the expanded token came from and the instantiation
253/// location specifies where it was expanded.
254class SourceManager {
255  /// FileInfos - Memoized information about all of the files tracked by this
256  /// SourceManager.  This set allows us to merge ContentCache entries based
257  /// on their FileEntry*.  All ContentCache objects will thus have unique,
258  /// non-null, FileEntry pointers.
259  std::set<SrcMgr::ContentCache> FileInfos;
260
261  /// MemBufferInfos - Information about various memory buffers that we have
262  /// read in.  This is a list, instead of a vector, because we need pointers to
263  /// the ContentCache objects to be stable.  All FileEntry* within the
264  /// stored ContentCache objects are NULL, as they do not refer to a file.
265  std::list<SrcMgr::ContentCache> MemBufferInfos;
266
267  /// SLocEntryTable - This is an array of SLocEntry's that we have created.
268  /// FileID is an index into this vector.  This array is sorted by the offset.
269  std::vector<SrcMgr::SLocEntry> SLocEntryTable;
270  /// NextOffset - This is the next available offset that a new SLocEntry can
271  /// start at.  It is SLocEntryTable.back().getOffset()+size of back() entry.
272  unsigned NextOffset;
273
274  /// LastFileIDLookup - This is a one-entry cache to speed up getFileID.
275  /// LastFileIDLookup records the last FileID looked up or created, because it
276  /// is very common to look up many tokens from the same file.
277  mutable FileID LastFileIDLookup;
278
279  /// LineTable - This holds information for #line directives.  It is referenced
280  /// by indices from SLocEntryTable.
281  LineTableInfo *LineTable;
282
283  /// LastLineNo - These ivars serve as a cache used in the getLineNumber
284  /// method which is used to speedup getLineNumber calls to nearby locations.
285  mutable FileID LastLineNoFileIDQuery;
286  mutable SrcMgr::ContentCache *LastLineNoContentCache;
287  mutable unsigned LastLineNoFilePos;
288  mutable unsigned LastLineNoResult;
289
290  /// MainFileID - The file ID for the main source file of the translation unit.
291  FileID MainFileID;
292
293  // Statistics for -print-stats.
294  mutable unsigned NumLinearScans, NumBinaryProbes;
295
296  // SourceManager doesn't support copy construction.
297  explicit SourceManager(const SourceManager&);
298  void operator=(const SourceManager&);
299public:
300  SourceManager() : LineTable(0), NumLinearScans(0), NumBinaryProbes(0) {
301    clearIDTables();
302  }
303  ~SourceManager();
304
305  void clearIDTables();
306
307  //===--------------------------------------------------------------------===//
308  // MainFileID creation and querying methods.
309  //===--------------------------------------------------------------------===//
310
311  /// getMainFileID - Returns the FileID of the main source file.
312  FileID getMainFileID() const { return MainFileID; }
313
314  /// createMainFileID - Create the FileID for the main source file.
315  FileID createMainFileID(const FileEntry *SourceFile,
316                          SourceLocation IncludePos) {
317    assert(MainFileID.isInvalid() && "MainFileID already set!");
318    MainFileID = createFileID(SourceFile, IncludePos, SrcMgr::C_User);
319    return MainFileID;
320  }
321
322  //===--------------------------------------------------------------------===//
323  // Methods to create new FileID's and instantiations.
324  //===--------------------------------------------------------------------===//
325
326  /// createFileID - Create a new FileID that represents the specified file
327  /// being #included from the specified IncludePosition.  This returns 0 on
328  /// error and translates NULL into standard input.
329  FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos,
330                      SrcMgr::CharacteristicKind FileCharacter) {
331    const SrcMgr::ContentCache *IR = getOrCreateContentCache(SourceFile);
332    if (IR == 0) return FileID();    // Error opening file?
333    return createFileID(IR, IncludePos, FileCharacter);
334  }
335
336  /// createFileIDForMemBuffer - Create a new FileID that represents the
337  /// specified memory buffer.  This does no caching of the buffer and takes
338  /// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.
339  FileID createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
340    return createFileID(createMemBufferContentCache(Buffer), SourceLocation(),
341                        SrcMgr::C_User);
342  }
343
344  /// createMainFileIDForMembuffer - Create the FileID for a memory buffer
345  ///  that will represent the FileID for the main source.  One example
346  ///  of when this would be used is when the main source is read from STDIN.
347  FileID createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
348    assert(MainFileID.isInvalid() && "MainFileID already set!");
349    MainFileID = createFileIDForMemBuffer(Buffer);
350    return MainFileID;
351  }
352
353  /// createInstantiationLoc - Return a new SourceLocation that encodes the fact
354  /// that a token at Loc should actually be referenced from InstantiationLoc.
355  /// TokLength is the length of the token being instantiated.
356  SourceLocation createInstantiationLoc(SourceLocation Loc,
357                                        SourceLocation InstantiationLoc,
358                                        unsigned TokLength);
359
360  //===--------------------------------------------------------------------===//
361  // FileID manipulation methods.
362  //===--------------------------------------------------------------------===//
363
364  /// getBuffer - Return the buffer for the specified FileID.
365  ///
366  const llvm::MemoryBuffer *getBuffer(FileID FID) const {
367    return getSLocEntry(FID).getFile().getContentCache()->getBuffer();
368  }
369
370  /// getFileEntryForID - Returns the FileEntry record for the provided FileID.
371  const FileEntry *getFileEntryForID(FileID FID) const {
372    return getSLocEntry(FID).getFile().getContentCache()->Entry;
373  }
374
375  /// getBufferData - Return a pointer to the start and end of the source buffer
376  /// data for the specified FileID.
377  std::pair<const char*, const char*> getBufferData(FileID FID) const;
378
379
380  //===--------------------------------------------------------------------===//
381  // SourceLocation manipulation methods.
382  //===--------------------------------------------------------------------===//
383
384  /// getFileIDSlow - Return the FileID for a SourceLocation.  This is a very
385  /// hot method that is used for all SourceManager queries that start with a
386  /// SourceLocation object.  It is responsible for finding the entry in
387  /// SLocEntryTable which contains the specified location.
388  ///
389  FileID getFileID(SourceLocation SpellingLoc) const {
390    unsigned SLocOffset = SpellingLoc.getOffset();
391
392    // If our one-entry cache covers this offset, just return it.
393    if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
394      return LastFileIDLookup;
395
396    return getFileIDSlow(SLocOffset);
397  }
398
399  /// getLocForStartOfFile - Return the source location corresponding to the
400  /// first byte of the specified file.
401  SourceLocation getLocForStartOfFile(FileID FID) const {
402    assert(FID.ID < SLocEntryTable.size() && SLocEntryTable[FID.ID].isFile());
403    unsigned FileOffset = SLocEntryTable[FID.ID].getOffset();
404    return SourceLocation::getFileLoc(FileOffset);
405  }
406
407  /// getIncludeLoc - Return the location of the #include for the specified
408  /// SourceLocation.  If this is a macro expansion, this transparently figures
409  /// out which file includes the file being expanded into.
410  SourceLocation getIncludeLoc(SourceLocation ID) const {
411    return getSLocEntry(getFileID(getInstantiationLoc(ID)))
412                    .getFile().getIncludeLoc();
413  }
414
415  /// Given a SourceLocation object, return the instantiation location
416  /// referenced by the ID.
417  SourceLocation getInstantiationLoc(SourceLocation Loc) const {
418    // File locations work!
419    if (Loc.isFileID()) return Loc;
420
421    std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
422    Loc = getSLocEntry(LocInfo.first).getInstantiation().getInstantiationLoc();
423    return Loc.getFileLocWithOffset(LocInfo.second);
424  }
425
426  /// getSpellingLoc - Given a SourceLocation object, return the spelling
427  /// location referenced by the ID.  This is the place where the characters
428  /// that make up the lexed token can be found.
429  SourceLocation getSpellingLoc(SourceLocation Loc) const {
430    // File locations work!
431    if (Loc.isFileID()) return Loc;
432
433    std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc);
434    Loc = getSLocEntry(LocInfo.first).getInstantiation().getSpellingLoc();
435    return Loc.getFileLocWithOffset(LocInfo.second);
436  }
437
438  /// getDecomposedLoc - Decompose the specified location into a raw FileID +
439  /// Offset pair.  The first element is the FileID, the second is the
440  /// offset from the start of the buffer of the location.
441  std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const {
442    FileID FID = getFileID(Loc);
443    return std::make_pair(FID, Loc.getOffset()-getSLocEntry(FID).getOffset());
444  }
445
446  /// getDecomposedInstantiationLoc - Decompose the specified location into a
447  /// raw FileID + Offset pair.  If the location is an instantiation record,
448  /// walk through it until we find the final location instantiated.
449  std::pair<FileID, unsigned>
450  getDecomposedInstantiationLoc(SourceLocation Loc) const {
451    FileID FID = getFileID(Loc);
452    const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
453
454    unsigned Offset = Loc.getOffset()-E->getOffset();
455    if (Loc.isFileID())
456      return std::make_pair(FID, Offset);
457
458    return getDecomposedInstantiationLocSlowCase(E, Offset);
459  }
460
461  /// getDecomposedSpellingLoc - Decompose the specified location into a raw
462  /// FileID + Offset pair.  If the location is an instantiation record, walk
463  /// through it until we find its spelling record.
464  std::pair<FileID, unsigned>
465  getDecomposedSpellingLoc(SourceLocation Loc) const {
466    FileID FID = getFileID(Loc);
467    const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
468
469    unsigned Offset = Loc.getOffset()-E->getOffset();
470    if (Loc.isFileID())
471      return std::make_pair(FID, Offset);
472    return getDecomposedSpellingLocSlowCase(E, Offset);
473  }
474
475  /// getFullFilePos - This (efficient) method returns the offset from the start
476  /// of the file that the specified spelling SourceLocation represents.  This
477  /// returns the location of the actual character data, not the instantiation
478  /// position.
479  unsigned getFullFilePos(SourceLocation SpellingLoc) const {
480    return getDecomposedLoc(SpellingLoc).second;
481  }
482
483
484  //===--------------------------------------------------------------------===//
485  // Queries about the code at a SourceLocation.
486  //===--------------------------------------------------------------------===//
487
488  /// getCharacterData - Return a pointer to the start of the specified location
489  /// in the appropriate spelling MemoryBuffer.
490  const char *getCharacterData(SourceLocation SL) const;
491
492  /// getColumnNumber - Return the column # for the specified file position.
493  /// This is significantly cheaper to compute than the line number.  This
494  /// returns zero if the column number isn't known.  This may only be called on
495  /// a file sloc, so you must choose a spelling or instantiation location
496  /// before calling this method.
497  unsigned getColumnNumber(SourceLocation Loc) const;
498
499  unsigned getSpellingColumnNumber(SourceLocation Loc) const {
500    return getColumnNumber(getSpellingLoc(Loc));
501  }
502  unsigned getInstantiationColumnNumber(SourceLocation Loc) const {
503    return getColumnNumber(getInstantiationLoc(Loc));
504  }
505
506
507  /// getLineNumber - Given a SourceLocation, return the spelling line number
508  /// for the position indicated.  This requires building and caching a table of
509  /// line offsets for the MemoryBuffer, so this is not cheap: use only when
510  /// about to emit a diagnostic.
511  unsigned getLineNumber(SourceLocation Loc) const;
512
513  unsigned getInstantiationLineNumber(SourceLocation Loc) const {
514    return getLineNumber(getInstantiationLoc(Loc));
515  }
516  unsigned getSpellingLineNumber(SourceLocation Loc) const {
517    return getLineNumber(getSpellingLoc(Loc));
518  }
519
520  // FIXME: This should handle #line.
521  SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const {
522    FileID FID = getFileID(getSpellingLoc(Loc));
523    return getSLocEntry(FID).getFile().getFileCharacteristic();
524  }
525
526  /// getSourceName - This method returns the name of the file or buffer that
527  /// the SourceLocation specifies.  This can be modified with #line directives,
528  /// etc.
529  const char *getSourceName(SourceLocation Loc) const;
530
531
532
533  /// isFromSameFile - Returns true if both SourceLocations correspond to
534  ///  the same file.
535  bool isFromSameFile(SourceLocation Loc1, SourceLocation Loc2) const {
536    return getFileID(Loc1) == getFileID(Loc2);
537  }
538
539  /// isFromMainFile - Returns true if the file of provided SourceLocation is
540  ///   the main file.
541  bool isFromMainFile(SourceLocation Loc) const {
542    return getFileID(Loc) == getMainFileID();
543  }
544
545  /// isInSystemHeader - Returns if a SourceLocation is in a system header.
546  bool isInSystemHeader(SourceLocation Loc) const {
547    return getFileCharacteristic(Loc) != SrcMgr::C_User;
548  }
549
550  //===--------------------------------------------------------------------===//
551  // Line Table Manipulation Routines
552  //===--------------------------------------------------------------------===//
553
554  /// getLineTableFilenameID - Return the uniqued ID for the specified filename.
555  ///
556  unsigned getLineTableFilenameID(const char *Ptr, unsigned Len);
557
558
559  //===--------------------------------------------------------------------===//
560  // Other miscellaneous methods.
561  //===--------------------------------------------------------------------===//
562
563  // Iterators over FileInfos.
564  typedef std::set<SrcMgr::ContentCache>::const_iterator fileinfo_iterator;
565  fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); }
566  fileinfo_iterator fileinfo_end() const { return FileInfos.end(); }
567
568  /// PrintStats - Print statistics to stderr.
569  ///
570  void PrintStats() const;
571
572  /// Emit - Emit this SourceManager to Bitcode.
573  void Emit(llvm::Serializer& S) const;
574
575  /// Read - Reconstitute a SourceManager from Bitcode.
576  static SourceManager* CreateAndRegister(llvm::Deserializer& S,
577                                          FileManager &FMgr);
578
579private:
580  friend struct SrcMgr::ContentCache; // Used for deserialization.
581
582  /// isOffsetInFileID - Return true if the specified FileID contains the
583  /// specified SourceLocation offset.  This is a very hot method.
584  inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const {
585    const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);
586    // If the entry is after the offset, it can't contain it.
587    if (SLocOffset < Entry.getOffset()) return false;
588
589    // If this is the last entry than it does.  Otherwise, the entry after it
590    // has to not include it.
591    if (FID.ID+1 == SLocEntryTable.size()) return true;
592    return SLocOffset < SLocEntryTable[FID.ID+1].getOffset();
593  }
594
595  /// createFileID - Create a new fileID for the specified ContentCache and
596  ///  include position.  This works regardless of whether the ContentCache
597  ///  corresponds to a file or some other input source.
598  FileID createFileID(const SrcMgr::ContentCache* File,
599                      SourceLocation IncludePos,
600                      SrcMgr::CharacteristicKind DirCharacter);
601
602  const SrcMgr::ContentCache *
603    getOrCreateContentCache(const FileEntry *SourceFile);
604
605  /// createMemBufferContentCache - Create a new ContentCache for the specified
606  ///  memory buffer.
607  const SrcMgr::ContentCache*
608  createMemBufferContentCache(const llvm::MemoryBuffer *Buf);
609
610  const SrcMgr::SLocEntry &getSLocEntry(FileID FID) const {
611    assert(FID.ID < SLocEntryTable.size() && "Invalid id");
612    return SLocEntryTable[FID.ID];
613  }
614
615  FileID getFileIDSlow(unsigned SLocOffset) const;
616
617  std::pair<FileID, unsigned>
618  getDecomposedInstantiationLocSlowCase(const SrcMgr::SLocEntry *E,
619                                        unsigned Offset) const;
620  std::pair<FileID, unsigned>
621  getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
622                                   unsigned Offset) const;
623};
624
625
626}  // end namespace clang
627
628#endif
629