35 #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H
36 #define LLVM_CLANG_BASIC_SOURCEMANAGER_H
41 #include "llvm/ADT/ArrayRef.h"
42 #include "llvm/ADT/BitVector.h"
43 #include "llvm/ADT/DenseMap.h"
44 #include "llvm/ADT/DenseSet.h"
45 #include "llvm/ADT/IntrusiveRefCntPtr.h"
46 #include "llvm/ADT/PointerIntPair.h"
47 #include "llvm/ADT/PointerUnion.h"
48 #include "llvm/Support/AlignOf.h"
49 #include "llvm/Support/Allocator.h"
50 #include "llvm/Support/DataTypes.h"
51 #include "llvm/Support/MemoryBuffer.h"
59 class DiagnosticsEngine;
98 mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2>
Buffer;
119 unsigned *SourceLineCache;
131 unsigned BufferOverridden : 1;
135 unsigned IsSystemFile : 1;
140 unsigned IsTransient : 1;
142 ContentCache(
const FileEntry *Ent =
nullptr) : ContentCache(Ent, Ent) {}
145 :
Buffer(
nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
146 SourceLineCache(
nullptr), NumLines(0), BufferOverridden(
false),
147 IsSystemFile(
false), IsTransient(
false) {}
154 ContentCache(
const ContentCache &RHS)
155 :
Buffer(
nullptr,
false), SourceLineCache(
nullptr),
156 BufferOverridden(
false), IsSystemFile(
false), IsTransient(
false) {
157 OrigEntry = RHS.OrigEntry;
158 ContentsEntry = RHS.ContentsEntry;
160 assert(RHS.Buffer.getPointer() ==
nullptr &&
161 RHS.SourceLineCache ==
nullptr &&
162 "Passed ContentCache object cannot own a buffer.");
164 NumLines = RHS.NumLines;
179 bool *Invalid =
nullptr)
const;
187 unsigned getSize()
const;
193 unsigned getSizeBytesMapped()
const;
197 llvm::MemoryBuffer::BufferKind getMemoryBufferKind()
const;
199 void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
200 assert(!
Buffer.getPointer() &&
"MemoryBuffer already set.");
201 Buffer.setPointer(B.release());
207 llvm::MemoryBuffer *getRawBuffer()
const {
return Buffer.getPointer(); }
211 void replaceBuffer(llvm::MemoryBuffer *B,
bool DoNotFree =
false);
214 bool isBufferInvalid()
const {
215 return Buffer.getInt() & InvalidFlag;
219 bool shouldFreeBuffer()
const {
220 return (
Buffer.getInt() & DoNotFreeFlag) == 0;
225 ContentCache &operator=(
const ContentCache& RHS) =
delete;
230 static_assert(llvm::AlignOf<ContentCache>::Alignment >= 8,
231 "ContentCache must be 8-byte aligned.");
252 unsigned NumCreatedFIDs;
267 X.IncludeLoc = IL.getRawEncoding();
268 X.NumCreatedFIDs = 0;
270 assert((X.Data & 7) == 0 &&
"ContentCache pointer insufficiently aligned");
271 assert((
unsigned)FileCharacter < 4 &&
"invalid file character");
280 return reinterpret_cast<const ContentCache*
>(Data & ~
uintptr_t(7));
305 unsigned SpellingLoc;
313 unsigned ExpansionLocStart, ExpansionLocEnd;
397 unsigned IsExpansion : 1;
409 assert(
isFile() &&
"Not a file SLocEntry!");
414 assert(
isExpansion() &&
"Not a macro expansion SLocEntry!");
419 assert(!(
Offset & (1 << 31)) &&
"Offset is too large");
422 E.IsExpansion =
false;
428 assert(!(
Offset & (1 << 31)) &&
"Offset is too large");
431 E.IsExpansion =
true;
465 FileID LQueryFID, RQueryFID;
470 bool IsLQFIDBeforeRQFID;
481 unsigned LCommonOffset, RCommonOffset;
488 return LQueryFID == LHS && RQueryFID == RHS;
496 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
497 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
504 if (LOffset == ROffset)
505 return IsLQFIDBeforeRQFID;
507 return LOffset < ROffset;
515 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
519 LQueryFID = RQueryFID =
FileID();
520 IsLQFIDBeforeRQFID =
false;
524 unsigned rCommonOffset) {
525 CommonFID = commonFID;
526 LCommonOffset = lCommonOffset;
527 RCommonOffset = rCommonOffset;
555 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
563 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
567 bool OverridenFilesKeepOriginalName;
571 bool UserFilesAreVolatile;
576 bool FilesAreTransient;
578 struct OverriddenFilesInfoTy {
581 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
588 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
590 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
591 if (!OverriddenFilesInfo)
592 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
593 return *OverriddenFilesInfo;
600 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
617 unsigned NextLocalOffset;
623 unsigned CurrentLoadedOffset;
627 static const unsigned MaxLoadedOffset = 1U << 31U;
633 llvm::BitVector SLocEntryLoaded;
642 mutable FileID LastFileIDLookup;
651 mutable FileID LastLineNoFileIDQuery;
652 mutable SrcMgr::ContentCache *LastLineNoContentCache;
653 mutable unsigned LastLineNoFilePos;
654 mutable unsigned LastLineNoResult;
663 mutable unsigned NumLinearScans, NumBinaryProbes;
670 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned> > IncludedLocMap;
673 typedef std::pair<FileID, FileID> IsBeforeInTUCacheKey;
677 typedef llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>
681 mutable InBeforeInTUCache IBTUCache;
689 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
691 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
695 typedef std::map<unsigned, SourceLocation> MacroArgsMap;
697 mutable llvm::DenseMap<FileID, MacroArgsMap *> MacroArgsCacheMap;
713 bool UserFilesAreVolatile =
false);
726 OverridenFilesKeepOriginalName = value;
735 return StoredModuleBuildStack;
740 StoredModuleBuildStack.clear();
741 StoredModuleBuildStack.append(stack.begin(), stack.end());
746 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
763 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
764 PreambleFileID = Preamble;
780 int LoadedID = 0,
unsigned LoadedOffset = 0) {
781 const SrcMgr::ContentCache *
782 IR = getOrCreateContentCache(SourceFile,
784 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
785 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
794 int LoadedID = 0,
unsigned LoadedOffset = 0,
796 return createFileID(createMemBufferContentCache(std::move(Buffer)),
797 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
825 unsigned LoadedOffset = 0);
832 bool *Invalid =
nullptr);
845 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
847 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
862 if (OverriddenFilesInfo) {
863 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
865 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
866 OverriddenFilesInfo->OverriddenFiles.end())
884 FilesAreTransient = Transient;
896 bool *Invalid =
nullptr)
const {
897 bool MyInvalid =
false;
899 if (MyInvalid || !Entry.
isFile()) {
903 return getFakeBufferForRecovery();
911 bool MyInvalid =
false;
913 if (MyInvalid || !Entry.
isFile()) {
917 return getFakeBufferForRecovery();
927 bool MyInvalid =
false;
929 if (MyInvalid || !Entry.
isFile())
935 return Content->OrigEntry;
944 return Content->OrigEntry;
957 bool Invalid =
false;
959 if (Invalid || !Entry.
isFile())
962 return Entry.
getFile().NumCreatedFIDs;
968 bool Invalid =
false;
970 if (Invalid || !Entry.
isFile())
973 assert(Entry.
getFile().NumCreatedFIDs == 0 &&
"Already set!");
988 unsigned SLocOffset = SpellingLoc.getOffset();
991 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
992 return LastFileIDLookup;
994 return getFileIDSlow(SLocOffset);
1000 return F->getName();
1007 bool Invalid =
false;
1009 if (Invalid || !Entry.
isFile())
1012 unsigned FileOffset = Entry.
getOffset();
1013 return SourceLocation::getFileLoc(FileOffset);
1019 bool Invalid =
false;
1021 if (Invalid || !Entry.
isFile())
1024 unsigned FileOffset = Entry.
getOffset();
1025 return SourceLocation::getFileLoc(FileOffset +
getFileIDSize(FID));
1031 bool Invalid =
false;
1033 if (Invalid || !Entry.
isFile())
1042 std::pair<SourceLocation, StringRef>
1060 return getExpansionLocSlowCase(Loc);
1068 return getFileLocSlowCase(Loc);
1075 std::pair<SourceLocation,SourceLocation>
1080 std::pair<SourceLocation,SourceLocation>
1099 return getSpellingLocSlowCase(Loc);
1116 bool Invalid =
false;
1119 return std::make_pair(
FileID(), 0);
1120 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1127 std::pair<FileID, unsigned>
1130 bool Invalid =
false;
1133 return std::make_pair(
FileID(), 0);
1137 return std::make_pair(FID, Offset);
1139 return getDecomposedExpansionLocSlowCase(E);
1146 std::pair<FileID, unsigned>
1149 bool Invalid =
false;
1152 return std::make_pair(
FileID(), 0);
1156 return std::make_pair(FID, Offset);
1157 return getDecomposedSpellingLocSlowCase(E, Offset);
1215 unsigned *RelativeOffset =
nullptr)
const {
1216 assert(((Start.getOffset() < NextLocalOffset &&
1217 Start.getOffset()+Length <= NextLocalOffset) ||
1218 (Start.getOffset() >= CurrentLoadedOffset &&
1219 Start.getOffset()+Length < MaxLoadedOffset)) &&
1220 "Chunk is not valid SLoc address space");
1221 unsigned LocOffs = Loc.getOffset();
1222 unsigned BeginOffs = Start.getOffset();
1223 unsigned EndOffs = BeginOffs +
Length;
1224 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1226 *RelativeOffset = LocOffs - BeginOffs;
1239 int *RelativeOffset)
const {
1240 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1241 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1242 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1244 if (LHSLoaded == RHSLoaded) {
1246 *RelativeOffset = RHSOffs - LHSOffs;
1262 bool *Invalid =
nullptr)
const;
1271 bool *Invalid =
nullptr)
const;
1273 bool *Invalid =
nullptr)
const;
1275 bool *Invalid =
nullptr)
const;
1277 bool *Invalid =
nullptr)
const;
1323 bool UseLineDirectives =
true)
const;
1372 unsigned *RelativeOffset =
nullptr)
const {
1373 unsigned Offs = Loc.getOffset();
1374 if (isOffsetInFileID(FID, Offs)) {
1397 bool IsFileEntry,
bool IsFileExit,
1398 bool IsSystemHeader,
bool IsExternCHeader);
1413 return ContentCacheAlloc.getTotalMemory();
1421 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1441 unsigned Line,
unsigned Col)
const;
1452 unsigned Line,
unsigned Col)
const;
1481 unsigned LHSOffset = LHS.getOffset();
1482 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1483 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1484 if (LHSLoaded == RHSLoaded)
1485 return LHSOffset < RHS;
1491 typedef llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>
1496 return FileInfos.find(File) != FileInfos.end();
1510 bool *Invalid =
nullptr)
const {
1511 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1512 return LocalSLocEntryTable[Index];
1520 bool *Invalid =
nullptr)
const {
1521 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1522 if (SLocEntryLoaded[Index])
1523 return LoadedSLocEntryTable[Index];
1524 return loadSLocEntry(Index, Invalid);
1528 bool *Invalid =
nullptr)
const {
1529 if (FID.ID == 0 || FID.ID == -1) {
1530 if (Invalid) *Invalid =
true;
1531 return LocalSLocEntryTable[0];
1533 return getSLocEntryByID(FID.ID, Invalid);
1539 assert(LoadedSLocEntryTable.empty() &&
1540 "Invalidating existing loaded entries");
1541 ExternalSLocEntries = Source;
1550 std::pair<int, unsigned>
1555 return Loc.getOffset() >= CurrentLoadedOffset;
1560 return Loc.getOffset() < NextLocalOffset;
1565 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1591 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1592 const SrcMgr::ContentCache *getFakeContentCacheForRecovery()
const;
1598 bool *Invalid =
nullptr)
const {
1599 assert(ID != -1 &&
"Using FileID sentinel value");
1601 return getLoadedSLocEntryByID(ID, Invalid);
1605 const SrcMgr::SLocEntry &
1606 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1612 SourceLocation createExpansionLocImpl(
const SrcMgr::ExpansionInfo &Expansion,
1615 unsigned LoadedOffset = 0);
1619 inline bool isOffsetInFileID(FileID FID,
unsigned SLocOffset)
const {
1622 if (SLocOffset < Entry.getOffset())
return false;
1629 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1630 return SLocOffset < NextLocalOffset;
1634 return SLocOffset < getSLocEntryByID(FID.ID+1).
getOffset();
1639 FileID getPreviousFileID(FileID FID)
const;
1643 FileID getNextFileID(FileID FID)
const;
1651 SourceLocation IncludePos,
1653 int LoadedID,
unsigned LoadedOffset);
1655 const SrcMgr::ContentCache *
1656 getOrCreateContentCache(
const FileEntry *SourceFile,
1657 bool isSystemFile =
false);
1660 const SrcMgr::ContentCache *
1661 createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
1663 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1664 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1665 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1667 SourceLocation getExpansionLocSlowCase(SourceLocation Loc)
const;
1668 SourceLocation getSpellingLocSlowCase(SourceLocation Loc)
const;
1669 SourceLocation getFileLocSlowCase(SourceLocation Loc)
const;
1671 std::pair<FileID, unsigned>
1672 getDecomposedExpansionLocSlowCase(
const SrcMgr::SLocEntry *
E)
const;
1673 std::pair<FileID, unsigned>
1674 getDecomposedSpellingLocSlowCase(
const SrcMgr::SLocEntry *
E,
1676 void computeMacroArgsCache(MacroArgsMap *&MacroArgsCache, FileID FID)
const;
1677 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1679 SourceLocation SpellLoc,
1680 SourceLocation ExpansionLoc,
1681 unsigned ExpansionLength)
const;
1687 template<
typename T>
1699 return SM.isBeforeInTranslationUnit(LHS, RHS);
bool hasLineDirectives() const
Return true if this FileID has #line directives in it.
bool isMacroArgExpansion(SourceLocation Loc, SourceLocation *StartLoc=nullptr) const
Tests whether the given source location represents a macro argument's expansion into the function-lik...
SourceLocation getEnd() const
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
This is a discriminated union of FileInfo and ExpansionInfo.
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Implements support for file system lookup, file system caching, and directory search management...
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
Defines the clang::FileManager interface and associated types.
FileID createFileID(std::unique_ptr< llvm::MemoryBuffer > Buffer, SrcMgr::CharacteristicKind FileCharacter=SrcMgr::C_User, int LoadedID=0, unsigned LoadedOffset=0, SourceLocation IncludeLoc=SourceLocation())
Create a new FileID that represents the specified memory buffer.
SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
bool operator()(SourceRange LHS, SourceRange RHS) const
unsigned getNextLocalOffset() const
unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded...
const ExpansionInfo & getExpansion() const
void setHasLineDirectives()
Set the flag that indicates that this FileID has line table entries associated with it...
std::unique_ptr< llvm::MemoryBuffer > Buffer
SourceRange getExpansionRange(SourceRange Range) const
Given a SourceRange object, return the range of tokens covered by the expansion in the ultimate file...
void setQueryFIDs(FileID LHS, FileID RHS, bool isLFIDBeforeRFID)
Set up a new query.
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID)
Add a line note to the line table for the FileID and offset specified by Loc.
fileinfo_iterator fileinfo_begin() const
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void setCommonLoc(FileID commonFID, unsigned lCommonOffset, unsigned rCommonOffset)
bool isInSystemMacro(SourceLocation loc)
Returns whether Loc is expanded from a macro in a system header.
SourceLocation getIncludeLoc() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
virtual bool ReadSLocEntry(int ID)=0
Read the source location entry with index ID, which will always be less than -1.
void setPreambleFileID(FileID Preamble)
Set the file ID for the precompiled preamble.
size_t getContentCacheSize() const
Return the total amount of physical memory allocated by the ContentCache allocator.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Used to hold and unique data used to represent #line information.
BeforeThanCompare(SourceManager &SM)
bool hasFileInfo(const FileEntry *File) const
bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const
Determines the order of a source location and a source location offset in the "source location addres...
void disableFileContentsOverride(const FileEntry *File)
Disable overridding the contents of a file, previously enabled with overrideFileContents.
void setMainFileID(FileID FID)
Set the file ID for the main source file.
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
std::pair< SourceLocation, SourceLocation > getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
bool isFileOverridden(const FileEntry *File)
Returns true if the file contents have been overridden.
virtual std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID)=0
Retrieve the module import location and name for the given ID, if in fact it was loaded from a module...
unsigned getExpansionColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
std::pair< FileID, unsigned > getDecomposedSpellingLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const
Gets the location of the immediate macro caller, one level up the stack toward the initial macro type...
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body. ...
Concrete class used by the front-end to report problems and issues.
unsigned getNumCreatedFIDsForFileID(FileID FID) const
Get the number of FileIDs (files and macros) that were created during preprocessing of FID...
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
Comparison function object.
bool isLoadedSourceLocation(SourceLocation Loc) const
Returns true if Loc came from a PCH/Module.
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
bool operator()(SourceLocation LHS, SourceLocation RHS) const
FileID getOrCreateFileID(const FileEntry *SourceFile, SrcMgr::CharacteristicKind FileCharacter)
Get the FileID for SourceFile if it exists.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
bool isMacroBodyExpansion() const
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
unsigned getPresumedColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
virtual ~ExternalSLocEntrySource()
SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col) const
Get the source location in FID for the given line:col.
void setFileIsTransient(const FileEntry *SourceFile)
Specify that a file is transient.
size_t getDataStructureSizes() const
Return the amount of memory used for various side tables and data structures in the SourceManager...
bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const
Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (of...
SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const
If Loc points inside a function macro argument, the returned location will be the macro location in w...
bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const
Returns true if the spelling locations for both SourceLocations are part of the same file buffer...
ModuleBuildStack getModuleBuildStack() const
Retrieve the module build stack.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
bool hasLineTable() const
Determine if the source manager has a line table.
FileManager & getFileManager() const
SourceLocation createMacroArgExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLoc, unsigned TokLength)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
std::pair< SourceLocation, StringRef > getModuleImportLoc(SourceLocation Loc) const
const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a local SLocEntry. This is exposed for indexing.
const char * getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
FileID getPreambleFileID() const
Get the file ID for the precompiled preamble if there is one.
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isWrittenInMainFile(SourceLocation Loc) const
Returns true if the spelling location for the given location is in the main file buffer.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location...
llvm::MemoryBuffer * getBuffer(FileID FID, bool *Invalid=nullptr) const
Represents an unpacked "presumed" location which can be presented to the user.
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
SourceLocation getExpansionLocEnd() const
bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the "source location address space".
unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Return the column # for the specified file position.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
void overrideFileContents(const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree)
Override the contents of the given source file by providing an already-allocated buffer.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
Information about a FileID, basically just the logical file that it represents and include stack info...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getOffset() const
Cached information about one file (either on disk or in the virtual file system). ...
bool isAtEndOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroEnd=nullptr) const
Returns true if the given MacroID location points at the character end of the immediate macro expansi...
bool isLocalFileID(FileID FID) const
Returns true if FID did not come from a PCH/Module.
unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
DiagnosticsEngine & getDiagnostics() const
llvm::MemoryBuffer * getMemoryBufferForFile(const FileEntry *File, bool *Invalid=nullptr)
Retrieve the memory buffer associated with the given file.
const FileEntry * getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
Returns the FileEntry record for the provided SLocEntry.
bool isCacheValid(FileID LHS, FileID RHS) const
Return true if the currently cached values match up with the specified LHS/RHS query.
const FileInfo & getFile() const
ArrayRef< std::pair< std::string, FullSourceLoc > > ModuleBuildStack
The stack used when building modules on demand, which is used to provide a link between the source ma...
SourceLocation getBegin() const
void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)
Push an entry to the module build stack.
FileID getMainFileID() const
Returns the FileID of the main source file.
External source of source location entries.
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
bool isInSLocAddrSpace(SourceLocation Loc, SourceLocation Start, unsigned Length, unsigned *RelativeOffset=nullptr) const
Returns true if Loc is inside the [Start, +Length) chunk of the source location address space...
bool getCachedResult(unsigned LOffset, unsigned ROffset) const
If the cache is valid, compute the result given the specified offsets in the LHS/RHS FileID's...
static ExpansionInfo create(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End)
Return a ExpansionInfo for an expansion.
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const
Return the file characteristic of the specified source location, indicating whether this is a normal ...
unsigned getLineTableFilenameID(StringRef Str)
Return the uniqued ID for the specified filename.
Reads an AST files chain containing the contents of a translation unit.
bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the beginning of the immediate macro expansion...
std::pair< SourceLocation, SourceLocation > getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
const ContentCache * getContentCache() const
fileinfo_iterator fileinfo_end() const
unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Given a SourceLocation, return the spelling line number for the position indicated.
const size_t malloc_bytes
detail::InMemoryDirectory::const_iterator E
void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)
SourceLocation getExpansionLocStart() const
llvm::DenseMap< const FileEntry *, SrcMgr::ContentCache * >::const_iterator fileinfo_iterator
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
bool userFilesAreVolatile() const
True if non-system source files should be treated as volatile (likely to change while trying to use t...
bool isMacroArgExpansion() const
Holds the cache used by isBeforeInTranslationUnit.
bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, int *RelativeOffset) const
Return true if both LHS and RHS are in the local source location address space or the loaded one...
void setOverridenFilesKeepOriginalName(bool value)
Set true if the SourceManager should report the original file name for contents of files that were ov...
std::pair< int, unsigned > AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize)
Allocate a number of loaded SLocEntries, which will be actually loaded on demand from the external so...
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Defines the clang::SourceLocation class and associated facilities.
void setModuleBuildStack(ModuleBuildStack stack)
Set the module build stack.
bool isFunctionMacroExpansion() const
void overrideFileContents(const FileEntry *SourceFile, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Writes an AST file containing the contents of a translation unit.
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const
Set the number of FileIDs (files and macros) that were created during preprocessing of FID...
void PrintStats() const
Print statistics to stderr.
LineTableInfo & getLineTable()
Retrieve the stored line table.
A SourceLocation and its associated SourceManager.
unsigned loaded_sloc_entry_size() const
Get the number of loaded SLocEntries we have.
static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc, SourceLocation ExpansionLoc)
Return a special ExpansionInfo for the expansion of a macro argument into a function-like macro's bod...
bool isInExternCSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in an "extern C" system header.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
void setAllFilesAreTransient(bool Transient)
Specify that all files that are read during this compilation are transient.
std::pair< SourceLocation, SourceLocation > getExpansionLocRange() const
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
const SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a loaded SLocEntry. This is exposed for indexing.
std::pair< FileID, unsigned > getDecomposedIncludedLoc(FileID FID) const
Returns the "included/expanded in" decomposed location of the given FileID.
A trivial tuple used to represent a source range.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
This class handles loading and caching of source files into memory.
BeforeThanCompare(SourceManager &SM)
SourceLocation getSpellingLoc() const
class LLVM_ALIGNAS(8) ContentCache
One instance of this struct is kept for every file loaded or used.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.