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/SmallVector.h"
48 #include "llvm/ADT/StringRef.h"
49 #include "llvm/Support/Allocator.h"
50 #include "llvm/Support/Compiler.h"
51 #include "llvm/Support/MemoryBuffer.h"
66 class DiagnosticsEngine;
112 mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2>
Buffer;
145 unsigned BufferOverridden : 1;
149 unsigned IsSystemFile : 1;
154 unsigned IsTransient : 1;
159 :
Buffer(nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
160 SourceLineCache(nullptr), NumLines(0), BufferOverridden(
false),
167 :
Buffer(nullptr,
false), SourceLineCache(nullptr),
172 assert(RHS.Buffer.getPointer() ==
nullptr &&
174 "Passed ContentCache object cannot own a buffer.");
195 bool *Invalid =
nullptr)
const;
203 unsigned getSize()
const;
209 unsigned getSizeBytesMapped()
const;
213 llvm::MemoryBuffer::BufferKind getMemoryBufferKind()
const;
216 assert(!
Buffer.getPointer() &&
"MemoryBuffer already set.");
217 Buffer.setPointer(B.release());
227 void replaceBuffer(llvm::MemoryBuffer *B,
bool DoNotFree =
false);
231 return Buffer.getInt() & InvalidFlag;
236 return (
Buffer.getInt() & DoNotFreeFlag) == 0;
242 static_assert(
alignof(ContentCache) >= 8,
243 "ContentCache must be 8-byte aligned.");
264 unsigned NumCreatedFIDs : 31;
267 unsigned HasLineDirectives : 1;
270 llvm::PointerIntPair<const ContentCache*, 3, CharacteristicKind>
282 X.IncludeLoc = IL.getRawEncoding();
283 X.NumCreatedFIDs = 0;
284 X.HasLineDirectives =
false;
285 X.ContentAndKind.setPointer(Con);
286 X.ContentAndKind.setInt(FileCharacter);
295 return ContentAndKind.getPointer();
300 return ContentAndKind.getInt();
309 HasLineDirectives =
true;
320 unsigned SpellingLoc;
328 unsigned ExpansionLocStart, ExpansionLocEnd;
414 unsigned IsExpansion : 1;
429 assert(
isFile() &&
"Not a file SLocEntry!");
434 assert(
isExpansion() &&
"Not a macro expansion SLocEntry!");
439 assert(!(
Offset & (1 << 31)) &&
"Offset is too large");
442 E.IsExpansion =
false;
448 assert(!(
Offset & (1 << 31)) &&
"Offset is too large");
451 E.IsExpansion =
true;
485 FileID LQueryFID, RQueryFID;
490 bool IsLQFIDBeforeRQFID;
501 unsigned LCommonOffset, RCommonOffset;
509 return LQueryFID == LHS && RQueryFID == RHS;
517 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
518 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
525 if (LOffset == ROffset)
526 return IsLQFIDBeforeRQFID;
528 return LOffset < ROffset;
536 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
540 LQueryFID = RQueryFID =
FileID();
541 IsLQFIDBeforeRQFID =
false;
545 unsigned rCommonOffset) {
546 CommonFID = commonFID;
547 LCommonOffset = lCommonOffset;
548 RCommonOffset = rCommonOffset;
575 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
583 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
587 bool OverridenFilesKeepOriginalName;
591 bool UserFilesAreVolatile;
596 bool FilesAreTransient;
598 struct OverriddenFilesInfoTy {
601 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
608 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
610 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
611 if (!OverriddenFilesInfo)
612 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
613 return *OverriddenFilesInfo;
620 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
637 unsigned NextLocalOffset;
643 unsigned CurrentLoadedOffset;
647 static const unsigned MaxLoadedOffset = 1U << 31U;
653 llvm::BitVector SLocEntryLoaded;
662 mutable FileID LastFileIDLookup;
671 mutable FileID LastLineNoFileIDQuery;
673 mutable unsigned LastLineNoFilePos;
674 mutable unsigned LastLineNoResult;
683 mutable unsigned NumLinearScans, NumBinaryProbes;
690 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap;
693 typedef std::pair<FileID, FileID> IsBeforeInTUCacheKey;
697 typedef llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>
701 mutable InBeforeInTUCache IBTUCache;
709 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
711 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
715 typedef std::map<unsigned, SourceLocation> MacroArgsMap;
717 mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
731 bool UserFilesAreVolatile =
false);
750 OverridenFilesKeepOriginalName = value;
759 return StoredModuleBuildStack;
764 StoredModuleBuildStack.clear();
765 StoredModuleBuildStack.append(stack.begin(), stack.end());
770 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
787 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
788 PreambleFileID = Preamble;
804 int LoadedID = 0,
unsigned LoadedOffset = 0) {
806 getOrCreateContentCache(SourceFile,
isSystem(FileCharacter));
807 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
808 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
817 int LoadedID = 0,
unsigned LoadedOffset = 0,
819 return createFileID(createMemBufferContentCache(std::move(Buffer)),
820 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
848 unsigned LoadedOffset = 0);
855 bool *Invalid =
nullptr);
868 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
870 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
885 if (OverriddenFilesInfo) {
886 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
888 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
889 OverriddenFilesInfo->OverriddenFiles.end())
907 FilesAreTransient = Transient;
919 bool *Invalid =
nullptr)
const {
920 bool MyInvalid =
false;
922 if (MyInvalid || !Entry.
isFile()) {
926 return getFakeBufferForRecovery();
934 bool MyInvalid =
false;
936 if (MyInvalid || !Entry.
isFile()) {
940 return getFakeBufferForRecovery();
950 bool MyInvalid =
false;
952 if (MyInvalid || !Entry.
isFile())
980 bool Invalid =
false;
982 if (Invalid || !Entry.
isFile())
985 return Entry.
getFile().NumCreatedFIDs;
991 bool Invalid =
false;
993 if (Invalid || !Entry.
isFile())
996 assert(Entry.
getFile().NumCreatedFIDs == 0 &&
"Already set!");
1011 unsigned SLocOffset = SpellingLoc.getOffset();
1014 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1015 return LastFileIDLookup;
1017 return getFileIDSlow(SLocOffset);
1023 return F->getName();
1030 bool Invalid =
false;
1032 if (Invalid || !Entry.
isFile())
1035 unsigned FileOffset = Entry.
getOffset();
1036 return SourceLocation::getFileLoc(FileOffset);
1042 bool Invalid =
false;
1044 if (Invalid || !Entry.
isFile())
1047 unsigned FileOffset = Entry.
getOffset();
1048 return SourceLocation::getFileLoc(FileOffset +
getFileIDSize(FID));
1054 bool Invalid =
false;
1056 if (Invalid || !Entry.
isFile())
1065 std::pair<SourceLocation, StringRef>
1083 return getExpansionLocSlowCase(Loc);
1091 return getFileLocSlowCase(Loc);
1098 std::pair<SourceLocation,SourceLocation>
1103 std::pair<SourceLocation,SourceLocation>
1122 return getSpellingLocSlowCase(Loc);
1139 bool Invalid =
false;
1142 return std::make_pair(
FileID(), 0);
1143 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1150 std::pair<FileID, unsigned>
1153 bool Invalid =
false;
1156 return std::make_pair(
FileID(), 0);
1160 return std::make_pair(FID, Offset);
1162 return getDecomposedExpansionLocSlowCase(E);
1169 std::pair<FileID, unsigned>
1172 bool Invalid =
false;
1175 return std::make_pair(
FileID(), 0);
1179 return std::make_pair(FID, Offset);
1180 return getDecomposedSpellingLocSlowCase(E, Offset);
1238 unsigned *RelativeOffset =
nullptr)
const {
1239 assert(((Start.getOffset() < NextLocalOffset &&
1240 Start.getOffset()+Length <= NextLocalOffset) ||
1241 (Start.getOffset() >= CurrentLoadedOffset &&
1242 Start.getOffset()+Length < MaxLoadedOffset)) &&
1243 "Chunk is not valid SLoc address space");
1244 unsigned LocOffs = Loc.getOffset();
1245 unsigned BeginOffs = Start.getOffset();
1246 unsigned EndOffs = BeginOffs +
Length;
1247 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1249 *RelativeOffset = LocOffs - BeginOffs;
1262 int *RelativeOffset)
const {
1263 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1264 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1265 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1267 if (LHSLoaded == RHSLoaded) {
1269 *RelativeOffset = RHSOffs - LHSOffs;
1285 bool *Invalid =
nullptr)
const;
1294 bool *Invalid =
nullptr)
const;
1296 bool *Invalid =
nullptr)
const;
1298 bool *Invalid =
nullptr)
const;
1300 bool *Invalid =
nullptr)
const;
1346 bool UseLineDirectives =
true)
const;
1395 unsigned *RelativeOffset =
nullptr)
const {
1396 unsigned Offs = Loc.getOffset();
1397 if (isOffsetInFileID(FID, Offs)) {
1419 bool IsFileEntry,
bool IsFileExit,
1435 return ContentCacheAlloc.getTotalMemory();
1443 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1463 unsigned Line,
unsigned Col)
const;
1474 unsigned Line,
unsigned Col)
const;
1499 std::pair<bool, bool>
1501 std::pair<FileID, unsigned> &ROffs)
const;
1514 unsigned LHSOffset = LHS.getOffset();
1515 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1516 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1517 if (LHSLoaded == RHSLoaded)
1518 return LHSOffset < RHS;
1524 typedef llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>
1529 return FileInfos.find(File) != FileInfos.end();
1543 bool *Invalid =
nullptr)
const {
1544 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1545 return LocalSLocEntryTable[Index];
1553 bool *Invalid =
nullptr)
const {
1554 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1555 if (SLocEntryLoaded[Index])
1556 return LoadedSLocEntryTable[Index];
1557 return loadSLocEntry(Index, Invalid);
1561 bool *Invalid =
nullptr)
const {
1562 if (FID.ID == 0 || FID.ID == -1) {
1563 if (Invalid) *Invalid =
true;
1564 return LocalSLocEntryTable[0];
1566 return getSLocEntryByID(FID.ID, Invalid);
1572 assert(LoadedSLocEntryTable.empty() &&
1573 "Invalidating existing loaded entries");
1574 ExternalSLocEntries = Source;
1583 std::pair<int, unsigned>
1588 return Loc.getOffset() >= CurrentLoadedOffset;
1593 return Loc.getOffset() < NextLocalOffset;
1598 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1624 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1631 bool *Invalid =
nullptr)
const {
1632 assert(ID != -1 &&
"Using FileID sentinel value");
1634 return getLoadedSLocEntryByID(ID, Invalid);
1638 const SrcMgr::SLocEntry &
1639 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1645 SourceLocation createExpansionLocImpl(
const SrcMgr::ExpansionInfo &Expansion,
1648 unsigned LoadedOffset = 0);
1652 inline bool isOffsetInFileID(FileID FID,
unsigned SLocOffset)
const {
1655 if (SLocOffset < Entry.getOffset())
return false;
1662 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1663 return SLocOffset < NextLocalOffset;
1667 return SLocOffset < getSLocEntryByID(FID.ID+1).
getOffset();
1672 FileID getPreviousFileID(FileID FID)
const;
1676 FileID getNextFileID(FileID FID)
const;
1684 SourceLocation IncludePos,
1686 int LoadedID,
unsigned LoadedOffset);
1688 const SrcMgr::ContentCache *
1689 getOrCreateContentCache(
const FileEntry *SourceFile,
1690 bool isSystemFile =
false);
1693 const SrcMgr::ContentCache *
1694 createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
1696 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1697 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1698 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1700 SourceLocation getExpansionLocSlowCase(SourceLocation Loc)
const;
1701 SourceLocation getSpellingLocSlowCase(SourceLocation Loc)
const;
1702 SourceLocation getFileLocSlowCase(SourceLocation Loc)
const;
1704 std::pair<FileID, unsigned>
1705 getDecomposedExpansionLocSlowCase(
const SrcMgr::SLocEntry *
E)
const;
1706 std::pair<FileID, unsigned>
1707 getDecomposedSpellingLocSlowCase(
const SrcMgr::SLocEntry *
E,
1709 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID)
const;
1710 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1712 SourceLocation SpellLoc,
1713 SourceLocation ExpansionLoc,
1714 unsigned ExpansionLength)
const;
1720 template<
typename T>
1732 return SM.isBeforeInTranslationUnit(LHS, RHS);
1751 #endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H
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
const FileEntry * OrigEntry
Reference to the file entry representing this ContentCache.
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
unsigned NumLines
The number of lines in this ContentCache.
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.
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)
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.
llvm::MemoryBuffer * getRawBuffer() const
Get the underlying buffer, returning NULL if the buffer is not yet available.
One instance of this struct is kept for every file loaded or used.
StringRef getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
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
void initializeForReplay(const SourceManager &Old)
Initialize this source manager suitably to replay the compilation described by Old.
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...
const FileEntry * ContentsEntry
References the file which the contents were actually loaded from.
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.
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.
bool isInSystemMacro(SourceLocation loc) const
Returns whether Loc is expanded from a macro in a system header.
ContentCache(const ContentCache &RHS)
The copy ctor does not allow copies where source object has either a non-NULL Buffer or SourceLineCac...
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.
SourceManager & operator=(const SourceManager &)=delete
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
bool isModuleMap(CharacteristicKind CK)
Determine whether a file characteristic is for a module map.
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...
unsigned * SourceLineCache
A bump pointer allocated array of offsets for each source line.
SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, bool UserFilesAreVolatile=false)
SourceLocation getBegin() const
ContentCache(const FileEntry *Ent=nullptr)
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 ...
ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
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
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
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
bool shouldFreeBuffer() const
Determine whether the buffer should be freed.
llvm::DenseMap< const FileEntry *, SrcMgr::ContentCache * >::const_iterator fileinfo_iterator
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
void setBuffer(std::unique_ptr< llvm::MemoryBuffer > B)
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 ...
std::pair< bool, bool > isInTheSameTranslationUnit(std::pair< FileID, unsigned > &LOffs, std::pair< FileID, unsigned > &ROffs) const
Determines whether the two decomposed source location is in the same translation unit.
Defines the clang::SourceLocation class and associated facilities.
bool isBufferInvalid() const
Determine whether the buffer itself is invalid.
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. ...
llvm::MemoryBuffer * getBuffer(DiagnosticsEngine &Diag, const SourceManager &SM, SourceLocation Loc=SourceLocation(), bool *Invalid=nullptr) const
Returns the memory buffer for the associated content.
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.
bool isFileOverridden(const FileEntry *File) const
Returns true if the file contents have been overridden.
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.
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
This class handles loading and caching of source files into memory.
BeforeThanCompare(SourceManager &SM)
SourceLocation getSpellingLoc() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.