SourceManager.h revision 52c29081281955d3db9e11d10573b2d38f709099
1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch//===--- SourceManager.h - Track and cache source files ---------*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)//===----------------------------------------------------------------------===// 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file defines the SourceManager interface. 116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// 126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)//===----------------------------------------------------------------------===// 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_SOURCEMANAGER_H 15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define LLVM_CLANG_SOURCEMANAGER_H 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/Basic/SourceLocation.h" 186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "llvm/Bitcode/SerializationFwd.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "llvm/Support/DataTypes.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <list> 236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include <cassert> 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 25f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace llvm { 26f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class MemoryBuffer; 27f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 28f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace clang { 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 31f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class SourceManager; 32f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class FileManager; 33f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class FileEntry; 34f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class IdentifierTokenInfo; 35f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class LineTableInfo; 36f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 37f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// SrcMgr - Public enums and private classes that are part of the 38f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// SourceManager implementation. 39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace SrcMgr { 41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// CharacteristicKind - This is used to represent whether a file or directory 42f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// holds normal user code, system code, or system code which is implicitly 43f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// 'extern "C"' in C++ mode. Entire directories can be tagged with this 44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// (this is maintained by DirectoryLookup and friends) as can specific 45f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// FileIDInfos when a #pragma system_header is seen or various other cases. 46f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// 47f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) enum CharacteristicKind { 48f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) C_User, C_System, C_ExternCSystem 49f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) }; 50f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 51f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// ContentCache - Once instance of this struct is kept for every file 52f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// loaded or used. This object owns the MemoryBuffer object. 53f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) class ContentCache { 54f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// Buffer - The actual buffer containing the characters from the input 55f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// file. This is owned by the ContentCache object. 56f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) mutable const llvm::MemoryBuffer *Buffer; 57f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public: 59f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// Reference to the file entry. This reference does not own 60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// the FileEntry object. It is possible for this to be NULL if 61f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// the ContentCache encapsulates an imaginary text buffer. 62f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const FileEntry *Entry; 63f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 64f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// SourceLineCache - A new[]'d array of offsets for each source line. This 65f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// is lazily computed. This is owned by the ContentCache object. 66f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) unsigned *SourceLineCache; 67f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 68f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// NumLines - The number of lines in this ContentCache. This is only valid 69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// if SourceLineCache is non-null. 70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) unsigned NumLines; 71f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 72f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// getBuffer - Returns the memory buffer for the associated content. 73f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const llvm::MemoryBuffer *getBuffer() const; 74f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 75f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// getSize - Returns the size of the content encapsulated by this 76f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// ContentCache. This can be the size of the source file or the size of an 77f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// arbitrary scratch buffer. If the ContentCache encapsulates a source 78f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// file this size is retrieved from the file's FileEntry. 79f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) unsigned getSize() const; 80f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 81f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// getSizeBytesMapped - Returns the number of bytes actually mapped for 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// this ContentCache. This can be 0 if the MemBuffer was not actually 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// instantiated. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned getSizeBytesMapped() const; 85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 86f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void setBuffer(const llvm::MemoryBuffer *B) { 87f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) assert(!Buffer && "MemoryBuffer already set."); 88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) Buffer = B; 89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 91f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ContentCache(const FileEntry *e = NULL) 92f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) : Buffer(NULL), Entry(e), SourceLineCache(NULL), NumLines(0) {} 93f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~ContentCache(); 95f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// The copy ctor does not allow copies where source object has either 97f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory 98f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// is not transfered, so this is a logical error. 99f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ContentCache(const ContentCache &RHS) : Buffer(NULL),SourceLineCache(NULL) { 100f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) Entry = RHS.Entry; 101f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 102f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) assert (RHS.Buffer == NULL && RHS.SourceLineCache == NULL 103f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) && "Passed ContentCache object cannot own a buffer."); 104f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 105f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) NumLines = RHS.NumLines; 106f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 107f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// Emit - Emit this ContentCache to Bitcode. 109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void Emit(llvm::Serializer &S) const; 110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// ReadToSourceManager - Reconstitute a ContentCache from Bitcode 112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // and store it in the specified SourceManager. 113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) static void ReadToSourceManager(llvm::Deserializer &D, SourceManager &SM, 114f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) FileManager *FMgr, std::vector<char> &Buf); 115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) private: 117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Disable assignments. 118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ContentCache &operator=(const ContentCache& RHS); 119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) }; 120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// FileInfo - Information about a FileID, basically just the logical file 122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// that it represents and include stack information. 123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// 124f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// Each FileInfo has include stack information, indicating where it came 125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// from. This information encodes the #include chain that a token was 126f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// instantiated from. The main include file has an invalid IncludeLoc. 127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// 128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// FileInfos contain a "ContentCache *", with the contents of the file. 129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// 130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) class FileInfo { 131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// IncludeLoc - The location of the #include that brought in this file. 132f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// This is an invalid SLOC for the main file (top of the #include chain). 133f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) unsigned IncludeLoc; // Really a SourceLocation 134f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// Data - This contains the ContentCache* and the bits indicating the 136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// characteristic of the file and whether it has #line info, all bitmangled 137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// together. 138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) uintptr_t Data; 139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public: 140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// get - Return a FileInfo object. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static FileInfo get(SourceLocation IL, const ContentCache *Con, 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CharacteristicKind FileCharacter) { 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FileInfo X; 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) X.IncludeLoc = IL.getRawEncoding(); 145a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) X.Data = (uintptr_t)Con; 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) assert((X.Data & 7) == 0 &&"ContentCache pointer insufficiently aligned"); 1476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) assert((unsigned)FileCharacter < 4 && "invalid file character"); 148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch X.Data |= (unsigned)FileCharacter; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return X; 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getIncludeLoc() const { 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SourceLocation::getFromRawEncoding(IncludeLoc); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 155a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ContentCache* getContentCache() const { 1566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) return reinterpret_cast<const ContentCache*>(Data & ~7UL); 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 159f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// getCharacteristic - Return whether this is a system header or not. 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CharacteristicKind getFileCharacteristic() const { 161f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return (CharacteristicKind)(Data & 3); 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 163f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) }; 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 165f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// InstantiationInfo - Each InstantiationInfo encodes the Instantiation 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// location - where the token was ultimately instantiated, and the 167f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// SpellingLoc - where the actual character data for the token came from. 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) class InstantiationInfo { 169f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) unsigned InstantiationLoc, SpellingLoc; // Really these are SourceLocations. 170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public: 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getInstantiationLoc() const { 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SourceLocation::getFromRawEncoding(InstantiationLoc); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SourceLocation getSpellingLoc() const { 175a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return SourceLocation::getFromRawEncoding(SpellingLoc); 176d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch } 1776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 178116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// get - Return a InstantiationInfo for an expansion. VL specifies 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// the instantiation location (where the macro is expanded), and SL 180f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// specifies the spelling location (where the characters from the token 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// come from). Both VL and PL refer to normal File SLocs. 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static InstantiationInfo get(SourceLocation IL, SourceLocation SL) { 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstantiationInfo X; 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) X.InstantiationLoc = IL.getRawEncoding(); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) X.SpellingLoc = SL.getRawEncoding(); 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return X; 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) /// SLocEntry - This is a discriminated union of FileInfo and 191116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// InstantiationInfo. SourceManager keeps an array of these objects, and 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// they are uniquely identified by the FileID datatype. 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class SLocEntry { 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned Offset; // low bit is set for instantiation info. 1955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu union { 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FileInfo File; 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InstantiationInfo Instantiation; 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned getOffset() const { return Offset >> 1; } 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool isInstantiation() const { return Offset & 1; } 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isFile() const { return !isInstantiation(); } 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const FileInfo &getFile() const { 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) assert(isFile() && "Not a file SLocEntry!"); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return File; 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const InstantiationInfo &getInstantiation() const { 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) assert(isInstantiation() && "Not an instantiation SLocEntry!"); 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Instantiation; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static SLocEntry get(unsigned Offset, const FileInfo &FI) { 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SLocEntry E; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) E.Offset = Offset << 1; 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) E.File = FI; 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return E; 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static SLocEntry get(unsigned Offset, const InstantiationInfo &II) { 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SLocEntry E; 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) E.Offset = (Offset << 1) | 1; 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) E.Instantiation = II; 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return E; 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // end SrcMgr namespace. 230116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} // end clang namespace 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace std { 233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)template <> struct less<clang::SrcMgr::ContentCache> { 234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) inline bool operator()(const clang::SrcMgr::ContentCache& L, 2356d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) const clang::SrcMgr::ContentCache& R) const { 236116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return L.Entry < R.Entry; 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // end std namespace 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang { 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// SourceManager - This file handles loading and caching of source files into 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// memory. This object owns the MemoryBuffer objects for all of the loaded 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// files and assigns unique FileID's for each unique #include chain. 246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)/// 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// The SourceManager can be queried for information about SourceLocation 248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)/// objects, turning them into either spelling or instantiation locations. 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// Spelling locations represent where the bytes corresponding to a token came 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// from and instantiation locations represent where the location is in the 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)/// user's view. In the case of a macro expansion, for example, the spelling 252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)/// location indicates where the expanded token came from and the instantiation 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// location specifies where it was expanded. 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SourceManager { 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// FileInfos - Memoized information about all of the files tracked by this 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// SourceManager. This set allows us to merge ContentCache entries based 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// on their FileEntry*. All ContentCache objects will thus have unique, 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// non-null, FileEntry pointers. 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::set<SrcMgr::ContentCache> FileInfos; 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// MemBufferInfos - Information about various memory buffers that we have 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// read in. This is a list, instead of a vector, because we need pointers to 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// the ContentCache objects to be stable. All FileEntry* within the 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// stored ContentCache objects are NULL, as they do not refer to a file. 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::list<SrcMgr::ContentCache> MemBufferInfos; 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// SLocEntryTable - This is an array of SLocEntry's that we have created. 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// FileID is an index into this vector. This array is sorted by the offset. 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<SrcMgr::SLocEntry> SLocEntryTable; 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// NextOffset - This is the next available offset that a new SLocEntry can 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// start at. It is SLocEntryTable.back().getOffset()+size of back() entry. 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) unsigned NextOffset; 273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) /// LastFileIDLookup - This is a one-entry cache to speed up getFileID. 275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// LastFileIDLookup records the last FileID looked up or created, because it 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// is very common to look up many tokens from the same file. 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) mutable FileID LastFileIDLookup; 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// LineTable - This holds information for #line directives. It is referenced 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// 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 // Handle the non-mapped case inline, defer to out of line code to handle 419 // instantiations. 420 if (Loc.isFileID()) return Loc; 421 return getInstantiationLocSlowCase(Loc); 422 } 423 424 /// getSpellingLoc - Given a SourceLocation object, return the spelling 425 /// location referenced by the ID. This is the place where the characters 426 /// that make up the lexed token can be found. 427 SourceLocation getSpellingLoc(SourceLocation Loc) const { 428 // Handle the non-mapped case inline, defer to out of line code to handle 429 // instantiations. 430 if (Loc.isFileID()) return Loc; 431 return getSpellingLocSlowCase(Loc); 432 } 433 434 /// getDecomposedLoc - Decompose the specified location into a raw FileID + 435 /// Offset pair. The first element is the FileID, the second is the 436 /// offset from the start of the buffer of the location. 437 std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const { 438 FileID FID = getFileID(Loc); 439 return std::make_pair(FID, Loc.getOffset()-getSLocEntry(FID).getOffset()); 440 } 441 442 /// getDecomposedInstantiationLoc - Decompose the specified location into a 443 /// raw FileID + Offset pair. If the location is an instantiation record, 444 /// walk through it until we find the final location instantiated. 445 std::pair<FileID, unsigned> 446 getDecomposedInstantiationLoc(SourceLocation Loc) const { 447 FileID FID = getFileID(Loc); 448 const SrcMgr::SLocEntry *E = &getSLocEntry(FID); 449 450 unsigned Offset = Loc.getOffset()-E->getOffset(); 451 if (Loc.isFileID()) 452 return std::make_pair(FID, Offset); 453 454 return getDecomposedInstantiationLocSlowCase(E, Offset); 455 } 456 457 /// getDecomposedSpellingLoc - Decompose the specified location into a raw 458 /// FileID + Offset pair. If the location is an instantiation record, walk 459 /// through it until we find its spelling record. 460 std::pair<FileID, unsigned> 461 getDecomposedSpellingLoc(SourceLocation Loc) const { 462 FileID FID = getFileID(Loc); 463 const SrcMgr::SLocEntry *E = &getSLocEntry(FID); 464 465 unsigned Offset = Loc.getOffset()-E->getOffset(); 466 if (Loc.isFileID()) 467 return std::make_pair(FID, Offset); 468 return getDecomposedSpellingLocSlowCase(E, Offset); 469 } 470 471 /// getFileOffset - This method returns the offset from the start 472 /// of the file that the specified SourceLocation represents. This is not very 473 /// meaningful for a macro ID. 474 unsigned getFileOffset(SourceLocation SpellingLoc) const { 475 return getDecomposedLoc(SpellingLoc).second; 476 } 477 478 479 //===--------------------------------------------------------------------===// 480 // Queries about the code at a SourceLocation. 481 //===--------------------------------------------------------------------===// 482 483 /// getCharacterData - Return a pointer to the start of the specified location 484 /// in the appropriate spelling MemoryBuffer. 485 const char *getCharacterData(SourceLocation SL) const; 486 487 /// getColumnNumber - Return the column # for the specified file position. 488 /// This is significantly cheaper to compute than the line number. This 489 /// returns zero if the column number isn't known. This may only be called on 490 /// a file sloc, so you must choose a spelling or instantiation location 491 /// before calling this method. 492 unsigned getColumnNumber(SourceLocation Loc) const; 493 494 unsigned getSpellingColumnNumber(SourceLocation Loc) const { 495 return getColumnNumber(getSpellingLoc(Loc)); 496 } 497 unsigned getInstantiationColumnNumber(SourceLocation Loc) const { 498 return getColumnNumber(getInstantiationLoc(Loc)); 499 } 500 501 502 /// getLineNumber - Given a SourceLocation, return the spelling line number 503 /// for the position indicated. This requires building and caching a table of 504 /// line offsets for the MemoryBuffer, so this is not cheap: use only when 505 /// about to emit a diagnostic. 506 unsigned getLineNumber(SourceLocation Loc) const; 507 508 unsigned getInstantiationLineNumber(SourceLocation Loc) const { 509 return getLineNumber(getInstantiationLoc(Loc)); 510 } 511 unsigned getSpellingLineNumber(SourceLocation Loc) const { 512 return getLineNumber(getSpellingLoc(Loc)); 513 } 514 515 // FIXME: This should handle #line. 516 SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const { 517 FileID FID = getFileID(getSpellingLoc(Loc)); 518 return getSLocEntry(FID).getFile().getFileCharacteristic(); 519 } 520 521 /// getSourceName - This method returns the name of the file or buffer that 522 /// the SourceLocation specifies. This can be modified with #line directives, 523 /// etc. 524 const char *getSourceName(SourceLocation Loc) const; 525 526 527 528 /// isFromSameFile - Returns true if both SourceLocations correspond to 529 /// the same file. 530 bool isFromSameFile(SourceLocation Loc1, SourceLocation Loc2) const { 531 return getFileID(Loc1) == getFileID(Loc2); 532 } 533 534 /// isFromMainFile - Returns true if the file of provided SourceLocation is 535 /// the main file. 536 bool isFromMainFile(SourceLocation Loc) const { 537 return getFileID(Loc) == getMainFileID(); 538 } 539 540 /// isInSystemHeader - Returns if a SourceLocation is in a system header. 541 bool isInSystemHeader(SourceLocation Loc) const { 542 return getFileCharacteristic(Loc) != SrcMgr::C_User; 543 } 544 545 //===--------------------------------------------------------------------===// 546 // Line Table Manipulation Routines 547 //===--------------------------------------------------------------------===// 548 549 /// getLineTableFilenameID - Return the uniqued ID for the specified filename. 550 /// 551 unsigned getLineTableFilenameID(const char *Ptr, unsigned Len); 552 553 554 //===--------------------------------------------------------------------===// 555 // Other miscellaneous methods. 556 //===--------------------------------------------------------------------===// 557 558 // Iterators over FileInfos. 559 typedef std::set<SrcMgr::ContentCache>::const_iterator fileinfo_iterator; 560 fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); } 561 fileinfo_iterator fileinfo_end() const { return FileInfos.end(); } 562 563 /// PrintStats - Print statistics to stderr. 564 /// 565 void PrintStats() const; 566 567 /// Emit - Emit this SourceManager to Bitcode. 568 void Emit(llvm::Serializer& S) const; 569 570 /// Read - Reconstitute a SourceManager from Bitcode. 571 static SourceManager* CreateAndRegister(llvm::Deserializer& S, 572 FileManager &FMgr); 573 574private: 575 friend struct SrcMgr::ContentCache; // Used for deserialization. 576 577 /// isOffsetInFileID - Return true if the specified FileID contains the 578 /// specified SourceLocation offset. This is a very hot method. 579 inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const { 580 const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); 581 // If the entry is after the offset, it can't contain it. 582 if (SLocOffset < Entry.getOffset()) return false; 583 584 // If this is the last entry than it does. Otherwise, the entry after it 585 // has to not include it. 586 if (FID.ID+1 == SLocEntryTable.size()) return true; 587 return SLocOffset < SLocEntryTable[FID.ID+1].getOffset(); 588 } 589 590 /// createFileID - Create a new fileID for the specified ContentCache and 591 /// include position. This works regardless of whether the ContentCache 592 /// corresponds to a file or some other input source. 593 FileID createFileID(const SrcMgr::ContentCache* File, 594 SourceLocation IncludePos, 595 SrcMgr::CharacteristicKind DirCharacter); 596 597 const SrcMgr::ContentCache * 598 getOrCreateContentCache(const FileEntry *SourceFile); 599 600 /// createMemBufferContentCache - Create a new ContentCache for the specified 601 /// memory buffer. 602 const SrcMgr::ContentCache* 603 createMemBufferContentCache(const llvm::MemoryBuffer *Buf); 604 605 const SrcMgr::SLocEntry &getSLocEntry(FileID FID) const { 606 assert(FID.ID < SLocEntryTable.size() && "Invalid id"); 607 return SLocEntryTable[FID.ID]; 608 } 609 610 FileID getFileIDSlow(unsigned SLocOffset) const; 611 612 SourceLocation getInstantiationLocSlowCase(SourceLocation Loc) const; 613 SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const; 614 615 std::pair<FileID, unsigned> 616 getDecomposedInstantiationLocSlowCase(const SrcMgr::SLocEntry *E, 617 unsigned Offset) const; 618 std::pair<FileID, unsigned> 619 getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E, 620 unsigned Offset) const; 621}; 622 623 624} // end namespace clang 625 626#endif 627