SourceManager.h revision 099b4747042352f69184481a48508b599a8d3f73
17f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//===--- SourceManager.h - Track and cache source files ---------*- C++ -*-===// 27f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// 37f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// The LLVM Compiler Infrastructure 47f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// 57f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// This file was developed by Chris Lattner and is distributed under 67f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// the University of Illinois Open Source License. See LICENSE.TXT for details. 77f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// 87f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//===----------------------------------------------------------------------===// 97f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// 107f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// This file defines the SourceManager interface. 117f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei// 127f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei//===----------------------------------------------------------------------===// 137f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 147f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#ifndef LLVM_CLANG_SOURCEMANAGER_H 157f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#define LLVM_CLANG_SOURCEMANAGER_H 167f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 177f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include "clang/Basic/SourceLocation.h" 187f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include "llvm/Bitcode/SerializationFwd.h" 197f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include <vector> 207f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include <set> 2113c976710415041fca5aba25cc02d3813c74b990Eric Christopher#include <list> 227f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei#include <cassert> 237f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 247f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeinamespace llvm { 257f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiclass MemoryBuffer; 267f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei} 277f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 287f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeinamespace clang { 297f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 307f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiclass SourceManager; 317f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiclass FileManager; 327f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiclass FileEntry; 337f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiclass IdentifierTokenInfo; 347f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 357f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei/// SrcMgr - Private classes that are part of the SourceManager implementation. 364919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl/// 377f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeinamespace SrcMgr { 387f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// ContentCache - Once instance of this struct is kept for every file 399faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// loaded or used. This object owns the MemoryBuffer object. 407f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei struct ContentCache { 417f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Reference to the file entry. This reference does not own 427f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// the FileEntry object. It is possible for this to be NULL if 437f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// the ContentCache encapsulates an imaginary text buffer. 447f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const FileEntry* Entry; 457f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 467f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Buffer - The actual buffer containing the characters from the input 477f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// file. This is owned by the ContentCache object. 487f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const llvm::MemoryBuffer* Buffer; 497f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 50ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl /// SourceLineCache - A new[]'d array of offsets for each source line. This 51b061ce2c7af5bb19294e16dbaf19a6b37ed2f716Adrian Prantl /// is lazily computed. This is owned by the ContentCache object. 527f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned* SourceLineCache; 533a7d82c4852dfd1e78f7ce7bdd94cc5eb1e4a0bcEric Christopher 547f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// NumLines - The number of lines in this ContentCache. This is only valid 557f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// if SourceLineCache is non-null. 567f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned NumLines; 577f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 587f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei ContentCache(const FileEntry* e = NULL) 59f068c92f22cc5c42433f5bd37b000a714a56670fEric Christopher : Entry(e), Buffer(NULL), SourceLineCache(NULL), NumLines(0) {} 607f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 61b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei ~ContentCache(); 62b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei 63b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei /// The copy ctor does not allow copies where source object has either 64e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei /// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory 65688cf5b05713055d27bf53460f7c20a776440767Eric Christopher /// is not transfered, so this is a logical error. 667c811dc4874124ea083a2f812d227cf53027290bEric Christopher ContentCache(const ContentCache& RHS) : Buffer(NULL),SourceLineCache(NULL) { 677f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei Entry = RHS.Entry; 687f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 697f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei assert (RHS.Buffer == NULL && RHS.SourceLineCache == NULL 704919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl && "Passed ContentCache object cannot own a buffer."); 714919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl 720f855a9c2517fc80803ab81a4aa0bb015918cf21Eric Christopher NumLines = RHS.NumLines; 734919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl } 74ebbd7e07aa0f22722da6ed8dd3a55beed9699171Adrian Prantl 75ebbd7e07aa0f22722da6ed8dd3a55beed9699171Adrian Prantl /// Emit - Emit this ContentCache to Bitcode. 76ebbd7e07aa0f22722da6ed8dd3a55beed9699171Adrian Prantl void Emit(llvm::Serializer& S) const; 777f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 787f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// ReadToSourceManager - Reconstitute a ContentCache from Bitcode 797f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei // and store it in the specified SourceManager. 807f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei static void ReadToSourceManager(llvm::Deserializer& D, SourceManager& SMgr, 817f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei FileManager* FMgr, std::vector<char>& Buf); 827f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 837f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei private: 847f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei // Disable assignments. 857f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei ContentCache& operator=(const ContentCache& RHS); 867f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei }; 877f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 887f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// FileIDInfo - Information about a FileID, basically just the logical file 897f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// that it represents and include stack information. A File SourceLocation 907f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// is a byte offset from the start of this. 917f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// 927f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// FileID's are used to compute the location of a character in memory as well 937f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// as the logical source location, which can be differ from the physical 947f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// location. It is different when #line's are active or when macros have 957f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// been expanded. 967f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// 977f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Each FileID has include stack information, indicating where it came from. 987f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// For the primary translation unit, it comes from SourceLocation() aka 0. 999faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// This information encodes the #include chain that a token was instantiated 1009faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// from. 1019faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// 1027f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// FileIDInfos contain a "ContentCache *", describing the source file, 103fc46ebc2b1345723a894ae352cfb206c1d930295David Blaikie /// and a Chunk number, which allows a SourceLocation to index into very 1040395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher /// large files (those which there are not enough FilePosBits to address). 1057f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// 1067f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei struct FileIDInfo { 1074919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl private: 1087f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// IncludeLoc - The location of the #include that brought in this file. 1097f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// This SourceLocation object has an invalid SLOC for the main file. 1105f6e2f4010e1ebbc07231eff7c92e474e8912350David Blaikie SourceLocation IncludeLoc; 1115f6e2f4010e1ebbc07231eff7c92e474e8912350David Blaikie 1127f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// ChunkNo - Really large buffers are broken up into chunks that are 1137f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// each (1 << SourceLocation::FilePosBits) in size. This specifies the 1147f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// chunk number of this FileID. 1157f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned ChunkNo; 1167f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1175f6e2f4010e1ebbc07231eff7c92e474e8912350David Blaikie /// Content - Information about the source buffer itself. 1187f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const ContentCache* Content; 1197f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1207f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei public: 1217f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// get - Return a FileIDInfo object. 1227f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei static FileIDInfo get(SourceLocation IL, unsigned CN, 1237f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const ContentCache *Con) { 1247f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei FileIDInfo X; 1257f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei X.IncludeLoc = IL; 1267f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei X.ChunkNo = CN; 1277f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei X.Content = Con; 128e86fcc46f560b8e0e13e13a7a1854658b231b2eaAdrian Prantl return X; 1297f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 1307f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1319a84529ed075d8047bb93f278a9da5e417fd71f3David Blaikie SourceLocation getIncludeLoc() const { return IncludeLoc; } 1329a84529ed075d8047bb93f278a9da5e417fd71f3David Blaikie unsigned getChunkNo() const { return ChunkNo; } 1339a84529ed075d8047bb93f278a9da5e417fd71f3David Blaikie const ContentCache* getContentCache() const { return Content; } 1349c78f9bddc42dbdeb05a7183b4770d33b0bda7d3David Blaikie 1359a84529ed075d8047bb93f278a9da5e417fd71f3David Blaikie /// Emit - Emit this FileIDInfo to Bitcode. 1369a84529ed075d8047bb93f278a9da5e417fd71f3David Blaikie void Emit(llvm::Serializer& S) const; 1377f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1387f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// ReadVal - Reconstitute a FileIDInfo from Bitcode. 139b0f77b065761670921fdf9c56029856cb5d9c306David Blaikie static FileIDInfo ReadVal(llvm::Deserializer& S); 1407f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei }; 1417f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1427f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// MacroIDInfo - Macro SourceLocations refer to these records by their ID. 143b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei /// Each MacroIDInfo encodes the Instantiation location - where the macro was 144ebbd7e07aa0f22722da6ed8dd3a55beed9699171Adrian Prantl /// instantiated, and the PhysicalLoc - where the actual character data for 145b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei /// the token came from. An actual macro SourceLocation stores deltas from 146b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei /// these positions. 1477f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei class MacroIDInfo { 1487f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation VirtualLoc, PhysicalLoc; 1497f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei public: 1507c811dc4874124ea083a2f812d227cf53027290bEric Christopher SourceLocation getVirtualLoc() const { return VirtualLoc; } 1517f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation getPhysicalLoc() const { return PhysicalLoc; } 1527f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1537f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// get - Return a MacroID for a macro expansion. VL specifies 1547f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// the instantiation location (where the macro is expanded), and PL 1557f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// specifies the physical location (where the characters from the token 1567f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// come from). Both VL and PL refer to normal File SLocs. 1577f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei static MacroIDInfo get(SourceLocation VL, SourceLocation PL) { 1587f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei MacroIDInfo X; 1597f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei X.VirtualLoc = VL; 1607f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei X.PhysicalLoc = PL; 1617f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return X; 1627f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 1637f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1647f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Emit - Emit this MacroIDInfo to Bitcode. 1657c811dc4874124ea083a2f812d227cf53027290bEric Christopher void Emit(llvm::Serializer& S) const; 1667f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 1677f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// ReadVal - Reconstitute a MacroIDInfo from Bitcode. 16835178dc09d97bb2e0612813def09833866e3ad82David Blaikie static MacroIDInfo ReadVal(llvm::Deserializer& S); 1697f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei }; 1707f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei} // end SrcMgr namespace. 1717f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei} // end clang namespace 1727c811dc4874124ea083a2f812d227cf53027290bEric Christopher 1737f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeinamespace std { 1747f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeitemplate <> struct less<clang::SrcMgr::ContentCache> { 1757f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei inline bool operator()(const clang::SrcMgr::ContentCache& L, 1767f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const clang::SrcMgr::ContentCache& R) const { 1777f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return L.Entry < R.Entry; 1787f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 1797f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei}; 1807f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei} // end std namespace 1810395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher 1820395de36004a718e265cc256b1bbee3bd3a791dcEric Christophernamespace clang { 1830395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher 1840395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// SourceManager - This file handles loading and caching of source files into 1850395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// memory. This object owns the MemoryBuffer objects for all of the loaded 1860395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// files and assigns unique FileID's for each unique #include chain. 1870395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// 1880395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// The SourceManager can be queried for information about SourceLocation 1890395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// objects, turning them into either physical or logical locations. Physical 1900395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// locations represent where the bytes corresponding to a token came from and 1910395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// logical locations represent where the location is in the user's view. In 1920395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher/// the case of a macro expansion, for example, the physical location indicates 1937f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei/// where the expanded token came from and the logical location specifies where 1947f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei/// it was expanded. Logical locations are also influenced by #line directives, 1957f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei/// etc. 1967f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiclass SourceManager { 1977f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// FileInfos - Memoized information about all of the files tracked by this 1987f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// SourceManager. This set allows us to merge ContentCache entries based 1997f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// on their FileEntry*. All ContentCache objects will thus have unique, 2007f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// non-null, FileEntry pointers. 2017f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei std::set<SrcMgr::ContentCache> FileInfos; 2027f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2037f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// MemBufferInfos - Information about various memory buffers that we have 2047c811dc4874124ea083a2f812d227cf53027290bEric Christopher /// read in. This is a list, instead of a vector, because we need pointers to 2057f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// the ContentCache objects to be stable. All FileEntry* within the 2067f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// stored ContentCache objects are NULL, as they do not refer to a file. 2077f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei std::list<SrcMgr::ContentCache> MemBufferInfos; 2087f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2097f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// FileIDs - Information about each FileID. FileID #0 is not valid, so all 2107f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// entries are off by one. 2117f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei std::vector<SrcMgr::FileIDInfo> FileIDs; 2127f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2137f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// MacroIDs - Information about each MacroID. 2147f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei std::vector<SrcMgr::MacroIDInfo> MacroIDs; 21559f0a5a5481a6dcfafd092dd944e6cfb7d146d4cAdrian Prantl 21659f0a5a5481a6dcfafd092dd944e6cfb7d146d4cAdrian Prantl /// LastLineNo - These ivars serve as a cache used in the getLineNumber 21759f0a5a5481a6dcfafd092dd944e6cfb7d146d4cAdrian Prantl /// method which is used to speedup getLineNumber calls to nearby locations. 2187f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned LastLineNoFileIDQuery; 2197f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SrcMgr::ContentCache *LastLineNoContentCache; 22000df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl unsigned LastLineNoFilePos; 22100df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl unsigned LastLineNoResult; 22200df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl 2237f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeipublic: 2247f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceManager() : LastLineNoFileIDQuery(~0U) {} 2257f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei ~SourceManager() {} 2267f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2277f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei void clearIDTables() { 2287f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei FileIDs.clear(); 2297f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei MacroIDs.clear(); 2307f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei LastLineNoFileIDQuery = ~0U; 2317f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei LastLineNoContentCache = 0; 2327f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 2337f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2347f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// createFileID - Create a new FileID that represents the specified file 2357f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// being #included from the specified IncludePosition. This returns 0 on 2367f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// error and translates NULL into standard input. 2377f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned createFileID(const FileEntry *SourceFile, SourceLocation IncludePos){ 2387f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const SrcMgr::ContentCache *IR = getContentCache(SourceFile); 2397f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei if (IR == 0) return 0; // Error opening file? 2407f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return createFileID(IR, IncludePos); 2417f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 2427f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2437f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// createFileIDForMemBuffer - Create a new FileID that represents the 2447f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// specified memory buffer. This does no caching of the buffer and takes 2457f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once. 2467f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) { 2477f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return createFileID(createMemBufferContentCache(Buffer), SourceLocation()); 2487f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 2497f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2507f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getInstantiationLoc - Return a new SourceLocation that encodes the fact 2517f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// that a token at Loc should actually be referenced from InstantiationLoc. 2527f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation getInstantiationLoc(SourceLocation Loc, 2537f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation InstantiationLoc); 2547f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2557f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getBuffer - Return the buffer for the specified FileID. 2567f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// 2577f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const llvm::MemoryBuffer *getBuffer(unsigned FileID) const { 2587f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return getContentCache(FileID)->Buffer; 2597f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 2607f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 261836e7c9357b312fd1ee5c90898ce2c81bb384997Adrian Prantl /// getBufferData - Return a pointer to the start and end of the character 262836e7c9357b312fd1ee5c90898ce2c81bb384997Adrian Prantl /// data for the specified FileID. 2637f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei std::pair<const char*, const char*> getBufferData(unsigned FileID) const; 2647f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2657f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getIncludeLoc - Return the location of the #include for the specified 2667f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// SourceLocation. If this is a macro expansion, this transparently figures 2677f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// out which file includes the file being expanded into. 2687f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation getIncludeLoc(SourceLocation ID) const { 2697f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return getFIDInfo(getLogicalLoc(ID).getFileID())->getIncludeLoc(); 2707f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 2717f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2727f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getCharacterData - Return a pointer to the start of the specified location 2737f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// in the appropriate MemoryBuffer. 274957dac5b6d826bc0c10011c8b5c3f1b8007fda41David Blaikie const char *getCharacterData(SourceLocation SL) const; 275957dac5b6d826bc0c10011c8b5c3f1b8007fda41David Blaikie 276957dac5b6d826bc0c10011c8b5c3f1b8007fda41David Blaikie /// getColumnNumber - Return the column # for the specified file position. 2779faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// This is significantly cheaper to compute than the line number. This 2789faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// returns zero if the column number isn't known. This may only be called on 2799faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// a file sloc, so you must choose a physical or logical location before 280fc46ebc2b1345723a894ae352cfb206c1d930295David Blaikie /// calling this method. 281fc46ebc2b1345723a894ae352cfb206c1d930295David Blaikie unsigned getColumnNumber(SourceLocation Loc) const; 282fc46ebc2b1345723a894ae352cfb206c1d930295David Blaikie 2837c811dc4874124ea083a2f812d227cf53027290bEric Christopher unsigned getPhysicalColumnNumber(SourceLocation Loc) const { 2847f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return getColumnNumber(getPhysicalLoc(Loc)); 2857f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 2867f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned getLogicalColumnNumber(SourceLocation Loc) const { 2877f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return getColumnNumber(getLogicalLoc(Loc)); 2887f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 28913c976710415041fca5aba25cc02d3813c74b990Eric Christopher 2907f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 291076f51fd1f306cafc3b1f1d323d25ac81bf7d4f7David Blaikie /// getLineNumber - Given a SourceLocation, return the physical line number 292eab6a36cf1eed9a7fec0babd2206048e28dedd02David Blaikie /// for the position indicated. This requires building and caching a table of 2937f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// line offsets for the MemoryBuffer, so this is not cheap: use only when 2947f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// about to emit a diagnostic. 2957f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned getLineNumber(SourceLocation Loc); 2967f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 2977f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned getLogicalLineNumber(SourceLocation Loc) { 2987c811dc4874124ea083a2f812d227cf53027290bEric Christopher return getLineNumber(getLogicalLoc(Loc)); 2997f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 3007f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned getPhysicalLineNumber(SourceLocation Loc) { 3017f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return getLineNumber(getPhysicalLoc(Loc)); 3027f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 3037f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 304bb00079d2ca77815efa0ab50cb10f302d1ae69e4David Blaikie /// getSourceName - This method returns the name of the file or buffer that 3057f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// the SourceLocation specifies. This can be modified with #line directives, 3069faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie /// etc. 3079faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie const char *getSourceName(SourceLocation Loc) const; 3087f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3097f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Given a SourceLocation object, return the logical location referenced by 3107f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// the ID. This logical location is subject to #line directives, etc. 3117c811dc4874124ea083a2f812d227cf53027290bEric Christopher SourceLocation getLogicalLoc(SourceLocation Loc) const { 3127f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei // File locations are both physical and logical. 3137f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei if (Loc.isFileID()) return Loc; 3147f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3157f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return MacroIDs[Loc.getMacroID()].getVirtualLoc(); 3167f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 3177f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3187f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getPhysicalLoc - Given a SourceLocation object, return the physical 3197f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// location referenced by the ID. 3207f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation getPhysicalLoc(SourceLocation Loc) const { 3217c811dc4874124ea083a2f812d227cf53027290bEric Christopher // File locations are both physical and logical. 3227f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei if (Loc.isFileID()) return Loc; 3237f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3247f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation PLoc = MacroIDs[Loc.getMacroID()].getPhysicalLoc(); 3257f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return PLoc.getFileLocWithOffset(Loc.getMacroPhysOffs()); 3267f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 3277f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3287f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getContentCacheForLoc - Return the ContentCache for the physloc of the 3297f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// specified SourceLocation, if one exists. 3305f6e2f4010e1ebbc07231eff7c92e474e8912350David Blaikie const SrcMgr::ContentCache* getContentCacheForLoc(SourceLocation Loc) const { 3317f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei Loc = getPhysicalLoc(Loc); 3327f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned FileID = Loc.getFileID(); 3337f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei assert(FileID-1 < FileIDs.size() && "Invalid FileID!"); 3347f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return FileIDs[FileID-1].getContentCache(); 3357f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei } 3367f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3375f6e2f4010e1ebbc07231eff7c92e474e8912350David Blaikie /// getFileEntryForLoc - Return the FileEntry record for the physloc of the 3387f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// specified SourceLocation, if one exists. 3394919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl const FileEntry* getFileEntryForLoc(SourceLocation Loc) const { 3404919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl return getContentCacheForLoc(Loc)->Entry; 3414919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl } 3424919de6a53a007487c6d6b173921b5e7152a2004Adrian Prantl 3437f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getDecomposedFileLoc - Decompose the specified file location into a raw 3447f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// FileID + Offset pair. The first element is the FileID, the second is the 3457f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// offset from the start of the buffer of the location. 3467f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei std::pair<unsigned, unsigned> getDecomposedFileLoc(SourceLocation Loc) const { 3477f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei assert(Loc.isFileID() && "Isn't a File SourceLocation"); 3487f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3497f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei // TODO: Add a flag "is first chunk" to SLOC. 3507f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(Loc.getFileID()); 3519faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie 3529faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie // If this file has been split up into chunks, factor in the chunk number 3539faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie // that the FileID references. 3549faebd23fd69ac1591520e811dfa5b25f73012f3David Blaikie unsigned ChunkNo = FIDInfo->getChunkNo(); 3557f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned Offset = Loc.getRawFilePos(); 3567f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei Offset += (ChunkNo << SourceLocation::FilePosBits); 3577f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3587f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return std::pair<unsigned,unsigned>(Loc.getFileID()-ChunkNo, Offset); 3590395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher } 3600395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher 3610395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher /// PrintStats - Print statistics to stderr. 3620395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher /// 3630395de36004a718e265cc256b1bbee3bd3a791dcEric Christopher void PrintStats() const; 3647f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3657f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Emit - Emit this SourceManager to Bitcode. 3667f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei void Emit(llvm::Serializer& S) const; 3677f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3687f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// Read - Reconstitute a SourceManager from Bitcode. 3697f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei void Read(llvm::Deserializer& S, FileManager &FMgr); 3707c811dc4874124ea083a2f812d227cf53027290bEric Christopher 3717f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyeiprivate: 3727f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei friend class SrcMgr::ContentCache; // Used for deserialization. 3737f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3747f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// createFileID - Create a new fileID for the specified ContentCache and 3757f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// include position. This works regardless of whether the ContentCache 3767f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// corresponds to a file or some other input source. 3777f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei unsigned createFileID(const SrcMgr::ContentCache* File, 3787f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei SourceLocation IncludePos); 3797f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3807f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// getContentCache - Create or return a cached ContentCache for the specified 3817f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// file. This returns null on failure. 3827f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const SrcMgr::ContentCache* getContentCache(const FileEntry* SourceFile); 3837f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 3847f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// createMemBufferContentCache - Create a new ContentCache for the specified 3857f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei /// memory buffer. 3867f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei const SrcMgr::ContentCache* 3877c811dc4874124ea083a2f812d227cf53027290bEric Christopher createMemBufferContentCache(const llvm::MemoryBuffer* Buf); 3887f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei 38900df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl const SrcMgr::FileIDInfo* getFIDInfo(unsigned FileID) const { 39000df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl assert(FileID-1 < FileIDs.size() && "Invalid FileID!"); 3917f92f2d8d9b7a07900c030183bc13a9ff60057ccGuy Benyei return &FileIDs[FileID-1]; 392ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl } 393ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl 394ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl const SrcMgr::ContentCache *getContentCache(unsigned FileID) const { 395ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl return getContentCache(getFIDInfo(FileID)); 396ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl } 397ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl 398ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl /// Return the ContentCache structure for the specified FileID. 399ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl /// This is always the physical reference for the ID. 400ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl const SrcMgr::ContentCache* 401ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl getContentCache(const SrcMgr::FileIDInfo* FIDInfo) const { 402ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl return FIDInfo->getContentCache(); 403ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl } 404ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl 405ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl /// getFullFilePos - This (efficient) method returns the offset from the start 406b061ce2c7af5bb19294e16dbaf19a6b37ed2f716Adrian Prantl /// of the file that the specified physical SourceLocation represents. This 407b061ce2c7af5bb19294e16dbaf19a6b37ed2f716Adrian Prantl /// returns the location of the physical character data, not the logical file 408ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl /// position. 409ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl unsigned getFullFilePos(SourceLocation PhysLoc) const { 410b6cdc96e7679f0344a36395a87c249930fac8a9fAdrian Prantl return getDecomposedFileLoc(PhysLoc).second; 411b6cdc96e7679f0344a36395a87c249930fac8a9fAdrian Prantl } 412b6cdc96e7679f0344a36395a87c249930fac8a9fAdrian Prantl}; 413ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl 414b6cdc96e7679f0344a36395a87c249930fac8a9fAdrian Prantl 415ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl} // end namespace clang 416ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl 417b061ce2c7af5bb19294e16dbaf19a6b37ed2f716Adrian Prantl#endif 418ed6bbe4ab8d06cd09fdfd294e2b2f8ab3808f84aAdrian Prantl