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;
99 mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2>
Buffer;
120 unsigned *SourceLineCache;
132 unsigned BufferOverridden : 1;
136 unsigned IsSystemFile : 1;
141 unsigned IsTransient : 1;
143 ContentCache(
const FileEntry *Ent =
nullptr) : ContentCache(Ent, Ent) {}
146 :
Buffer(
nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
147 SourceLineCache(
nullptr), NumLines(0), BufferOverridden(
false),
148 IsSystemFile(
false), IsTransient(
false) {}
155 ContentCache(
const ContentCache &RHS)
156 :
Buffer(
nullptr,
false), SourceLineCache(
nullptr),
157 BufferOverridden(
false), IsSystemFile(
false), IsTransient(
false) {
158 OrigEntry = RHS.OrigEntry;
159 ContentsEntry = RHS.ContentsEntry;
161 assert(RHS.Buffer.getPointer() ==
nullptr &&
162 RHS.SourceLineCache ==
nullptr &&
163 "Passed ContentCache object cannot own a buffer.");
165 NumLines = RHS.NumLines;
180 bool *Invalid =
nullptr)
const;
188 unsigned getSize()
const;
194 unsigned getSizeBytesMapped()
const;
198 llvm::MemoryBuffer::BufferKind getMemoryBufferKind()
const;
200 void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
201 assert(!
Buffer.getPointer() &&
"MemoryBuffer already set.");
202 Buffer.setPointer(B.release());
208 llvm::MemoryBuffer *getRawBuffer()
const {
return Buffer.getPointer(); }
212 void replaceBuffer(llvm::MemoryBuffer *B,
bool DoNotFree =
false);
215 bool isBufferInvalid()
const {
216 return Buffer.getInt() & InvalidFlag;
220 bool shouldFreeBuffer()
const {
221 return (
Buffer.getInt() & DoNotFreeFlag) == 0;
226 ContentCache &operator=(
const ContentCache& RHS) =
delete;
231 static_assert(llvm::AlignOf<ContentCache>::Alignment >= 8,
232 "ContentCache must be 8-byte aligned.");
253 unsigned NumCreatedFIDs;
268 X.IncludeLoc = IL.getRawEncoding();
269 X.NumCreatedFIDs = 0;
270 X.Data = (uintptr_t)Con;
271 assert((X.Data & 7) == 0 &&
"ContentCache pointer insufficiently aligned");
272 assert((
unsigned)FileCharacter < 4 &&
"invalid file character");
281 return reinterpret_cast<const ContentCache*
>(Data & ~uintptr_t(7));
306 unsigned SpellingLoc;
314 unsigned ExpansionLocStart, ExpansionLocEnd;
398 unsigned IsExpansion : 1;
410 assert(
isFile() &&
"Not a file SLocEntry!");
415 assert(
isExpansion() &&
"Not a macro expansion SLocEntry!");
420 assert(!(
Offset & (1 << 31)) &&
"Offset is too large");
423 E.IsExpansion =
false;
429 assert(!(
Offset & (1 << 31)) &&
"Offset is too large");
432 E.IsExpansion =
true;
466 FileID LQueryFID, RQueryFID;
471 bool IsLQFIDBeforeRQFID;
482 unsigned LCommonOffset, RCommonOffset;
489 return LQueryFID == LHS && RQueryFID == RHS;
497 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
498 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
505 if (LOffset == ROffset)
506 return IsLQFIDBeforeRQFID;
508 return LOffset < ROffset;
516 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
520 LQueryFID = RQueryFID =
FileID();
521 IsLQFIDBeforeRQFID =
false;
525 unsigned rCommonOffset) {
526 CommonFID = commonFID;
527 LCommonOffset = lCommonOffset;
528 RCommonOffset = rCommonOffset;
556 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
564 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
568 bool OverridenFilesKeepOriginalName;
572 bool UserFilesAreVolatile;
577 bool FilesAreTransient;
579 struct OverriddenFilesInfoTy {
582 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
589 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
591 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
592 if (!OverriddenFilesInfo)
593 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
594 return *OverriddenFilesInfo;
601 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
618 unsigned NextLocalOffset;
624 unsigned CurrentLoadedOffset;
628 static const unsigned MaxLoadedOffset = 1U << 31U;
634 llvm::BitVector SLocEntryLoaded;
643 mutable FileID LastFileIDLookup;
652 mutable FileID LastLineNoFileIDQuery;
653 mutable SrcMgr::ContentCache *LastLineNoContentCache;
654 mutable unsigned LastLineNoFilePos;
655 mutable unsigned LastLineNoResult;
664 mutable unsigned NumLinearScans, NumBinaryProbes;
671 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned> > IncludedLocMap;
674 typedef std::pair<FileID, FileID> IsBeforeInTUCacheKey;
678 typedef llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>
682 mutable InBeforeInTUCache IBTUCache;
690 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
692 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
696 typedef std::map<unsigned, SourceLocation> MacroArgsMap;
698 mutable llvm::DenseMap<FileID, MacroArgsMap *> MacroArgsCacheMap;
714 bool UserFilesAreVolatile =
false);
727 OverridenFilesKeepOriginalName = value;
736 return StoredModuleBuildStack;
741 StoredModuleBuildStack.clear();
742 StoredModuleBuildStack.append(stack.begin(), stack.end());
747 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
764 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
765 PreambleFileID = Preamble;
781 int LoadedID = 0,
unsigned LoadedOffset = 0) {
782 const SrcMgr::ContentCache *
783 IR = getOrCreateContentCache(SourceFile,
785 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
786 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
795 int LoadedID = 0,
unsigned LoadedOffset = 0,
797 return createFileID(createMemBufferContentCache(std::move(Buffer)),
798 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
817 unsigned LoadedOffset = 0);
824 bool *Invalid =
nullptr);
837 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
839 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
854 if (OverriddenFilesInfo) {
855 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
857 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
858 OverriddenFilesInfo->OverriddenFiles.end())
876 FilesAreTransient = Transient;
888 bool *Invalid =
nullptr)
const {
889 bool MyInvalid =
false;
891 if (MyInvalid || !Entry.
isFile()) {
895 return getFakeBufferForRecovery();
903 bool MyInvalid =
false;
905 if (MyInvalid || !Entry.
isFile()) {
909 return getFakeBufferForRecovery();
919 bool MyInvalid =
false;
921 if (MyInvalid || !Entry.
isFile())
927 return Content->OrigEntry;
936 return Content->OrigEntry;
949 bool Invalid =
false;
951 if (Invalid || !Entry.
isFile())
954 return Entry.
getFile().NumCreatedFIDs;
960 bool Invalid =
false;
962 if (Invalid || !Entry.
isFile())
965 assert(Entry.
getFile().NumCreatedFIDs == 0 &&
"Already set!");
980 unsigned SLocOffset = SpellingLoc.getOffset();
983 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
984 return LastFileIDLookup;
986 return getFileIDSlow(SLocOffset);
999 bool Invalid =
false;
1001 if (Invalid || !Entry.
isFile())
1004 unsigned FileOffset = Entry.
getOffset();
1005 return SourceLocation::getFileLoc(FileOffset);
1011 bool Invalid =
false;
1013 if (Invalid || !Entry.
isFile())
1016 unsigned FileOffset = Entry.
getOffset();
1017 return SourceLocation::getFileLoc(FileOffset +
getFileIDSize(FID));
1023 bool Invalid =
false;
1025 if (Invalid || !Entry.
isFile())
1034 std::pair<SourceLocation, StringRef>
1052 return getExpansionLocSlowCase(Loc);
1060 return getFileLocSlowCase(Loc);
1067 std::pair<SourceLocation,SourceLocation>
1072 std::pair<SourceLocation,SourceLocation>
1091 return getSpellingLocSlowCase(Loc);
1108 bool Invalid =
false;
1111 return std::make_pair(
FileID(), 0);
1112 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1119 std::pair<FileID, unsigned>
1122 bool Invalid =
false;
1125 return std::make_pair(
FileID(), 0);
1129 return std::make_pair(FID, Offset);
1131 return getDecomposedExpansionLocSlowCase(E);
1138 std::pair<FileID, unsigned>
1141 bool Invalid =
false;
1144 return std::make_pair(
FileID(), 0);
1148 return std::make_pair(FID, Offset);
1149 return getDecomposedSpellingLocSlowCase(E, Offset);
1207 unsigned *RelativeOffset =
nullptr)
const {
1208 assert(((Start.getOffset() < NextLocalOffset &&
1209 Start.getOffset()+Length <= NextLocalOffset) ||
1210 (Start.getOffset() >= CurrentLoadedOffset &&
1211 Start.getOffset()+Length < MaxLoadedOffset)) &&
1212 "Chunk is not valid SLoc address space");
1213 unsigned LocOffs = Loc.getOffset();
1214 unsigned BeginOffs = Start.getOffset();
1215 unsigned EndOffs = BeginOffs +
Length;
1216 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1218 *RelativeOffset = LocOffs - BeginOffs;
1231 int *RelativeOffset)
const {
1232 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1233 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1234 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1236 if (LHSLoaded == RHSLoaded) {
1238 *RelativeOffset = RHSOffs - LHSOffs;
1254 bool *Invalid =
nullptr)
const;
1263 bool *Invalid =
nullptr)
const;
1265 bool *Invalid =
nullptr)
const;
1267 bool *Invalid =
nullptr)
const;
1269 bool *Invalid =
nullptr)
const;
1315 bool UseLineDirectives =
true)
const;
1364 unsigned *RelativeOffset =
nullptr)
const {
1365 unsigned Offs = Loc.getOffset();
1366 if (isOffsetInFileID(FID, Offs)) {
1389 bool IsFileEntry,
bool IsFileExit,
1390 bool IsSystemHeader,
bool IsExternCHeader);
1405 return ContentCacheAlloc.getTotalMemory();
1413 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1433 unsigned Line,
unsigned Col)
const;
1444 unsigned Line,
unsigned Col)
const;
1473 unsigned LHSOffset = LHS.getOffset();
1474 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1475 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1476 if (LHSLoaded == RHSLoaded)
1477 return LHSOffset < RHS;
1483 typedef llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>
1488 return FileInfos.find(File) != FileInfos.end();
1502 bool *Invalid =
nullptr)
const {
1503 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1504 return LocalSLocEntryTable[Index];
1512 bool *Invalid =
nullptr)
const {
1513 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1514 if (SLocEntryLoaded[Index])
1515 return LoadedSLocEntryTable[Index];
1516 return loadSLocEntry(Index, Invalid);
1520 bool *Invalid =
nullptr)
const {
1521 if (FID.ID == 0 || FID.ID == -1) {
1522 if (Invalid) *Invalid =
true;
1523 return LocalSLocEntryTable[0];
1525 return getSLocEntryByID(FID.ID, Invalid);
1531 assert(LoadedSLocEntryTable.empty() &&
1532 "Invalidating existing loaded entries");
1533 ExternalSLocEntries = Source;
1542 std::pair<int, unsigned>
1547 return Loc.getOffset() >= CurrentLoadedOffset;
1552 return Loc.getOffset() < NextLocalOffset;
1557 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1583 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1584 const SrcMgr::ContentCache *getFakeContentCacheForRecovery()
const;
1590 bool *Invalid =
nullptr)
const {
1591 assert(ID != -1 &&
"Using FileID sentinel value");
1593 return getLoadedSLocEntryByID(ID, Invalid);
1597 const SrcMgr::SLocEntry &
1598 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1604 SourceLocation createExpansionLocImpl(
const SrcMgr::ExpansionInfo &Expansion,
1607 unsigned LoadedOffset = 0);
1611 inline bool isOffsetInFileID(FileID FID,
unsigned SLocOffset)
const {
1614 if (SLocOffset < Entry.getOffset())
return false;
1621 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1622 return SLocOffset < NextLocalOffset;
1626 return SLocOffset < getSLocEntryByID(FID.ID+1).
getOffset();
1631 FileID getPreviousFileID(FileID FID)
const;
1635 FileID getNextFileID(FileID FID)
const;
1643 SourceLocation IncludePos,
1645 int LoadedID,
unsigned LoadedOffset);
1647 const SrcMgr::ContentCache *
1648 getOrCreateContentCache(
const FileEntry *SourceFile,
1649 bool isSystemFile =
false);
1652 const SrcMgr::ContentCache *
1653 createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
1655 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1656 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1657 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1659 SourceLocation getExpansionLocSlowCase(SourceLocation Loc)
const;
1660 SourceLocation getSpellingLocSlowCase(SourceLocation Loc)
const;
1661 SourceLocation getFileLocSlowCase(SourceLocation Loc)
const;
1663 std::pair<FileID, unsigned>
1664 getDecomposedExpansionLocSlowCase(
const SrcMgr::SLocEntry *
E)
const;
1665 std::pair<FileID, unsigned>
1666 getDecomposedSpellingLocSlowCase(
const SrcMgr::SLocEntry *
E,
1668 void computeMacroArgsCache(MacroArgsMap *&MacroArgsCache, FileID FID)
const;
1669 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1671 SourceLocation SpellLoc,
1672 SourceLocation ExpansionLoc,
1673 unsigned ExpansionLength)
const;
1679 template<
typename T>
1691 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
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()
ID
Defines the set of possible language-specific address spaces.
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.
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.