34 #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H 35 #define LLVM_CLANG_BASIC_SOURCEMANAGER_H 40 #include "llvm/ADT/ArrayRef.h" 41 #include "llvm/ADT/BitVector.h" 42 #include "llvm/ADT/DenseMap.h" 43 #include "llvm/ADT/DenseSet.h" 44 #include "llvm/ADT/IntrusiveRefCntPtr.h" 45 #include "llvm/ADT/PointerIntPair.h" 46 #include "llvm/ADT/SmallVector.h" 47 #include "llvm/ADT/StringRef.h" 48 #include "llvm/Support/Allocator.h" 49 #include "llvm/Support/Compiler.h" 50 #include "llvm/Support/MemoryBuffer.h" 108 mutable llvm::PointerIntPair<const llvm::MemoryBuffer *, 2> Buffer;
155 : Buffer(nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
167 assert(RHS.Buffer.getPointer() ==
nullptr &&
169 "Passed ContentCache object cannot own a buffer.");
190 bool *Invalid =
nullptr)
const;
213 return Buffer.getPointer();
218 void replaceBuffer(
const llvm::MemoryBuffer *B,
bool DoNotFree =
false);
222 return Buffer.getInt() & InvalidFlag;
227 return (Buffer.getInt() & DoNotFreeFlag) == 0;
234 "ContentCache must be 8-byte aligned.");
259 unsigned NumCreatedFIDs : 31;
262 unsigned HasLineDirectives : 1;
265 llvm::PointerIntPair<const ContentCache*, 3, CharacteristicKind>
273 X.IncludeLoc = IL.getRawEncoding();
274 X.NumCreatedFIDs = 0;
275 X.HasLineDirectives =
false;
276 X.ContentAndKind.setPointer(Con);
277 X.ContentAndKind.setInt(FileCharacter);
286 return ContentAndKind.getPointer();
291 return ContentAndKind.getInt();
300 HasLineDirectives =
true;
311 unsigned SpellingLoc;
319 unsigned ExpansionLocStart, ExpansionLocEnd;
322 bool ExpansionIsTokenRange;
327 return SpellLoc.
isInvalid() ? getExpansionLocStart() : SpellLoc;
337 return EndLoc.
isInvalid() ? getExpansionLocStart() : EndLoc;
341 return ExpansionIsTokenRange;
346 SourceRange(getExpansionLocStart(), getExpansionLocEnd()),
347 isExpansionTokenRange());
352 return getExpansionLocStart().isValid() &&
357 return getExpansionLocStart().isValid() &&
362 return getExpansionLocStart().isValid() &&
363 getExpansionLocStart() != getExpansionLocEnd();
374 bool ExpansionIsTokenRange =
true) {
379 X.ExpansionIsTokenRange = ExpansionIsTokenRange;
418 return create(SpellingLoc, Start, End,
false);
428 unsigned IsExpansion : 1;
440 bool isFile()
const {
return !isExpansion(); }
443 assert(isFile() &&
"Not a file SLocEntry!");
448 assert(isExpansion() &&
"Not a macro expansion SLocEntry!");
453 assert(!(Offset & (1u << 31)) &&
"Offset is too large");
456 E.IsExpansion =
false;
462 assert(!(Offset & (1u << 31)) &&
"Offset is too large");
465 E.IsExpansion =
true;
483 virtual bool ReadSLocEntry(
int ID) = 0;
488 virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(
int ID) = 0;
499 FileID LQueryFID, RQueryFID;
504 bool IsLQFIDBeforeRQFID;
515 unsigned LCommonOffset, RCommonOffset;
523 return LQueryFID == LHS && RQueryFID == RHS;
531 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
532 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
539 if (LOffset == ROffset)
540 return IsLQFIDBeforeRQFID;
542 return LOffset < ROffset;
550 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
554 LQueryFID = RQueryFID =
FileID();
555 IsLQFIDBeforeRQFID =
false;
559 unsigned rCommonOffset) {
560 CommonFID = commonFID;
561 LCommonOffset = lCommonOffset;
562 RCommonOffset = rCommonOffset;
589 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
597 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
601 bool OverridenFilesKeepOriginalName =
true;
605 bool UserFilesAreVolatile;
610 bool FilesAreTransient =
false;
612 struct OverriddenFilesInfoTy {
615 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
623 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
625 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
626 if (!OverriddenFilesInfo)
627 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
628 return *OverriddenFilesInfo;
635 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
652 unsigned NextLocalOffset;
658 unsigned CurrentLoadedOffset;
662 static const unsigned MaxLoadedOffset = 1U << 31U;
668 llvm::BitVector SLocEntryLoaded;
677 mutable FileID LastFileIDLookup;
682 std::unique_ptr<LineTableInfo> LineTable;
686 mutable FileID LastLineNoFileIDQuery;
688 mutable unsigned LastLineNoFilePos;
689 mutable unsigned LastLineNoResult;
698 mutable unsigned NumLinearScans = 0;
699 mutable unsigned NumBinaryProbes = 0;
706 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap;
709 using IsBeforeInTUCacheKey = std::pair<FileID, FileID>;
713 using InBeforeInTUCache =
714 llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>;
717 mutable InBeforeInTUCache IBTUCache;
725 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
727 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
731 using MacroArgsMap = std::map<unsigned, SourceLocation>;
733 mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
747 bool UserFilesAreVolatile =
false);
752 void clearIDTables();
766 OverridenFilesKeepOriginalName = value;
775 return StoredModuleBuildStack;
780 StoredModuleBuildStack.clear();
781 StoredModuleBuildStack.append(stack.begin(), stack.end());
786 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
803 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
804 PreambleFileID = Preamble;
820 int LoadedID = 0,
unsigned LoadedOffset = 0) {
822 getOrCreateContentCache(SourceFile,
isSystem(FileCharacter));
823 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
824 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
833 int LoadedID = 0,
unsigned LoadedOffset = 0,
836 createMemBufferContentCache(Buffer.release(),
false),
837 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
848 int LoadedID = 0,
unsigned LoadedOffset = 0,
850 return createFileID(createMemBufferContentCache(Buffer,
true),
851 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
858 FileID ID = translateFile(SourceFile);
878 bool ExpansionIsTokenRange =
true,
880 unsigned LoadedOffset = 0);
892 const llvm::MemoryBuffer *getMemoryBufferForFile(
const FileEntry *File,
893 bool *Invalid =
nullptr);
905 void overrideFileContents(
const FileEntry *SourceFile,
906 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
908 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
909 overrideFileContents(SourceFile, Buffer.release(),
false);
918 void overrideFileContents(
const FileEntry *SourceFile,
923 if (OverriddenFilesInfo) {
924 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
926 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
927 OverriddenFilesInfo->OverriddenFiles.end())
937 void disableFileContentsOverride(
const FileEntry *File);
940 void setFileIsTransient(
const FileEntry *SourceFile);
945 FilesAreTransient = Transient;
957 bool *Invalid =
nullptr)
const {
958 bool MyInvalid =
false;
960 if (MyInvalid || !Entry.
isFile()) {
964 return getFakeBufferForRecovery();
972 bool *Invalid =
nullptr)
const {
973 bool MyInvalid =
false;
975 if (MyInvalid || !Entry.
isFile()) {
979 return getFakeBufferForRecovery();
989 bool MyInvalid =
false;
991 if (MyInvalid || !Entry.
isFile())
1014 StringRef getBufferData(
FileID FID,
bool *Invalid =
nullptr)
const;
1019 bool Invalid =
false;
1021 if (Invalid || !Entry.
isFile())
1024 return Entry.
getFile().NumCreatedFIDs;
1030 bool Force =
false)
const {
1031 bool Invalid =
false;
1033 if (Invalid || !Entry.
isFile())
1036 assert((Force || Entry.
getFile().NumCreatedFIDs == 0) &&
"Already set!");
1051 unsigned SLocOffset = SpellingLoc.getOffset();
1054 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1055 return LastFileIDLookup;
1057 return getFileIDSlow(SLocOffset);
1062 if (
const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc)))
1063 return F->getName();
1070 bool Invalid =
false;
1072 if (Invalid || !Entry.
isFile())
1075 unsigned FileOffset = Entry.
getOffset();
1076 return SourceLocation::getFileLoc(FileOffset);
1082 bool Invalid =
false;
1084 if (Invalid || !Entry.
isFile())
1087 unsigned FileOffset = Entry.
getOffset();
1088 return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID));
1094 bool Invalid =
false;
1096 if (Invalid || !Entry.
isFile())
1105 std::pair<SourceLocation, StringRef>
1107 FileID FID = getFileID(Loc);
1123 return getExpansionLocSlowCase(Loc);
1131 return getFileLocSlowCase(Loc);
1171 return getSpellingLocSlowCase(Loc);
1184 bool Invalid =
false;
1190 return Entry.
isFile() ? SourceLocation::getFileLoc(GlobalOffset)
1191 : SourceLocation::getMacroLoc(GlobalOffset);
1199 FileID FID = getFileID(Loc);
1200 bool Invalid =
false;
1203 return std::make_pair(
FileID(), 0);
1204 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1211 std::pair<FileID, unsigned>
1213 FileID FID = getFileID(Loc);
1214 bool Invalid =
false;
1217 return std::make_pair(
FileID(), 0);
1221 return std::make_pair(FID, Offset);
1223 return getDecomposedExpansionLocSlowCase(E);
1230 std::pair<FileID, unsigned>
1232 FileID FID = getFileID(Loc);
1233 bool Invalid =
false;
1236 return std::make_pair(
FileID(), 0);
1240 return std::make_pair(FID, Offset);
1241 return getDecomposedSpellingLocSlowCase(E, Offset);
1246 std::pair<FileID, unsigned> getDecomposedIncludedLoc(
FileID FID)
const;
1253 return getDecomposedLoc(SpellingLoc).second;
1299 unsigned *RelativeOffset =
nullptr)
const {
1300 assert(((Start.getOffset() < NextLocalOffset &&
1301 Start.getOffset()+Length <= NextLocalOffset) ||
1302 (Start.getOffset() >= CurrentLoadedOffset &&
1303 Start.getOffset()+Length < MaxLoadedOffset)) &&
1304 "Chunk is not valid SLoc address space");
1305 unsigned LocOffs = Loc.getOffset();
1306 unsigned BeginOffs = Start.getOffset();
1307 unsigned EndOffs = BeginOffs + Length;
1308 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1310 *RelativeOffset = LocOffs - BeginOffs;
1323 int *RelativeOffset)
const {
1324 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1325 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1326 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1328 if (LHSLoaded == RHSLoaded) {
1330 *RelativeOffset = RHSOffs - LHSOffs;
1346 bool *Invalid =
nullptr)
const;
1354 unsigned getColumnNumber(
FileID FID,
unsigned FilePos,
1355 bool *Invalid =
nullptr)
const;
1357 bool *Invalid =
nullptr)
const;
1359 bool *Invalid =
nullptr)
const;
1361 bool *Invalid =
nullptr)
const;
1369 unsigned getLineNumber(
FileID FID,
unsigned FilePos,
bool *Invalid =
nullptr)
const;
1370 unsigned getSpellingLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1371 unsigned getExpansionLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1372 unsigned getPresumedLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1379 StringRef getBufferName(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1407 bool UseLineDirectives =
true)
const;
1423 return getFileID(Loc1) == getFileID(Loc2);
1431 return getFileID(Loc) == getMainFileID();
1436 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1437 return Filename.equals(
"<built-in>");
1442 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1443 return Filename.equals(
"<command line>");
1448 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1449 return Filename.equals(
"<scratch space>");
1454 return isSystem(getFileCharacteristic(Loc));
1470 if (isWrittenInScratchSpace(getSpellingLoc(loc))) {
1472 loc = getImmediateMacroCallerLoc(loc);
1473 }
while (isWrittenInScratchSpace(getSpellingLoc(loc)));
1474 return isInSystemMacro(loc);
1477 return isInSystemHeader(getSpellingLoc(loc));
1481 unsigned getFileIDSize(
FileID FID)
const;
1487 unsigned *RelativeOffset =
nullptr)
const {
1488 unsigned Offs = Loc.getOffset();
1489 if (isOffsetInFileID(FID, Offs)) {
1491 *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
1503 unsigned getLineTableFilenameID(StringRef Str);
1509 void AddLineNote(
SourceLocation Loc,
unsigned LineNo,
int FilenameID,
1510 bool IsFileEntry,
bool IsFileExit,
1526 return ContentCacheAlloc.getTotalMemory();
1534 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1543 size_t getDataStructureSizes()
const;
1554 unsigned Line,
unsigned Col)
const;
1565 unsigned Line,
unsigned Col)
const;
1590 std::pair<bool, bool>
1591 isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs,
1592 std::pair<FileID, unsigned> &ROffs)
const;
1597 return isBeforeInSLocAddrSpace(LHS, RHS.getOffset());
1605 unsigned LHSOffset = LHS.getOffset();
1606 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1607 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1608 if (LHSLoaded == RHSLoaded)
1609 return LHSOffset < RHS;
1617 return Location == Start || Location == End ||
1618 (isBeforeInTranslationUnit(Start, Location) &&
1619 isBeforeInTranslationUnit(Location, End));
1624 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator;
1629 return FileInfos.find(File) != FileInfos.end();
1633 void PrintStats()
const;
1642 bool *Invalid =
nullptr)
const {
1643 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1644 return LocalSLocEntryTable[Index];
1652 bool *Invalid =
nullptr)
const {
1653 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1654 if (SLocEntryLoaded[Index])
1655 return LoadedSLocEntryTable[Index];
1656 return loadSLocEntry(Index, Invalid);
1660 bool *Invalid =
nullptr)
const {
1661 if (FID.ID == 0 || FID.ID == -1) {
1662 if (Invalid) *Invalid =
true;
1663 return LocalSLocEntryTable[0];
1665 return getSLocEntryByID(FID.ID, Invalid);
1671 assert(LoadedSLocEntryTable.empty() &&
1672 "Invalidating existing loaded entries");
1673 ExternalSLocEntries = Source;
1682 std::pair<int, unsigned>
1683 AllocateLoadedSLocEntries(
unsigned NumSLocEntries,
unsigned TotalSize);
1687 return Loc.getOffset() >= CurrentLoadedOffset;
1692 return Loc.getOffset() < NextLocalOffset;
1697 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1703 return !isLoadedFileID(FID);
1714 if (isMacroArgExpansion(Loc))
1715 return getImmediateSpellingLoc(Loc);
1719 return getImmediateExpansionRange(Loc).
getBegin();
1729 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1736 bool *Invalid =
nullptr)
const {
1737 assert(ID != -1 &&
"Using FileID sentinel value");
1739 return getLoadedSLocEntryByID(ID, Invalid);
1740 return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
1744 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1745 return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
1753 unsigned LoadedOffset = 0);
1757 inline bool isOffsetInFileID(
FileID FID,
unsigned SLocOffset)
const {
1760 if (SLocOffset < Entry.
getOffset())
return false;
1767 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1768 return SLocOffset < NextLocalOffset;
1772 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();
1791 int LoadedID,
unsigned LoadedOffset);
1794 getOrCreateContentCache(
const FileEntry *SourceFile,
1795 bool isSystemFile =
false);
1799 createMemBufferContentCache(
const llvm::MemoryBuffer *Buf,
bool DoNotFree);
1801 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1802 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1803 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1809 std::pair<FileID, unsigned>
1811 std::pair<FileID, unsigned>
1814 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
FileID FID)
const;
1815 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1819 unsigned ExpansionLength)
const;
1823 template<
typename T>
1835 return SM.isBeforeInTranslationUnit(LHS, RHS);
1869 std::unique_ptr<FileManager> FileMgr;
1870 std::unique_ptr<DiagnosticsEngine> Diagnostics;
1871 std::unique_ptr<SourceManager> SourceMgr;
1876 #endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const
Returns true if the spelling locations for both SourceLocations are part of the same file buffer...
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.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const
Determines the order of a source location and a source location offset in the "source location addres...
const SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a loaded SLocEntry. This is exposed for indexing.
Implements support for file system lookup, file system caching, and directory search management...
SourceLocation getSpellingLoc() const
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
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.
static ExpansionInfo create(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End, bool ExpansionIsTokenRange=true)
Return a ExpansionInfo for an expansion.
bool isExpansionTokenRange() const
fileinfo_iterator fileinfo_end() const
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
unsigned NumLines
The number of lines in this ContentCache.
bool isCacheValid(FileID LHS, FileID RHS) const
Return true if the currently cached values match up with the specified LHS/RHS query.
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the "source location address space".
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded...
void setHasLineDirectives()
Set the flag that indicates that this FileID has line table entries associated with it...
void setQueryFIDs(FileID LHS, FileID RHS, bool isLFIDBeforeRFID)
Set up a new query.
const llvm::MemoryBuffer * getBuffer(DiagnosticsEngine &Diag, const SourceManager &SM, SourceLocation Loc=SourceLocation(), bool *Invalid=nullptr) const
Returns the memory buffer for the associated content.
void setCommonLoc(FileID commonFID, unsigned lCommonOffset, unsigned rCommonOffset)
SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const
Gets the location of the immediate macro caller, one level up the stack toward the initial macro type...
void setPreambleFileID(FileID Preamble)
Set the file ID for the precompiled preamble.
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...
unsigned getNextLocalOffset() const
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.
bool hasLineDirectives() const
Return true if this FileID has #line directives in it.
BeforeThanCompare(SourceManager &SM)
unsigned getNumCreatedFIDsForFileID(FileID FID) const
Get the number of FileIDs (files and macros) that were created during preprocessing of FID...
void setMainFileID(FileID FID)
Set the file ID for the main source file.
FileManager & getFileManager() const
SourceLocation getBegin() const
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs, bool Force=false) const
Set the number of FileIDs (files and macros) that were created during preprocessing of FID...
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
One instance of this struct is kept for every file loaded or used.
unsigned IsTransient
True if this file may be transient, that is, if it might not exist at some later point in time when t...
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...
const llvm::MemoryBuffer * getRawBuffer() const
Get the underlying buffer, returning NULL if the buffer is not yet available.
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
ModuleBuildStack getModuleBuildStack() const
Retrieve the module build stack.
const FileInfo & getFile() const
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
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...
Concrete class used by the front-end to report problems and issues.
SourceManager and necessary depdencies (e.g.
Defines the Diagnostic-related interfaces.
Comparison function object.
DiagnosticsEngine & getDiagnostics() const
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
void setTokenRange(bool TR)
SourceLocation getIncludeLoc() const
CharSourceRange getExpansionRange(SourceRange Range) const
Given a SourceRange object, return the range of tokens or characters covered by the expansion in the ...
bool isMacroArgExpansion() const
unsigned getSize() const
Returns the size of the content encapsulated by this ContentCache.
unsigned getSizeBytesMapped() const
Returns the number of bytes actually mapped for this ContentCache.
bool isBufferInvalid() const
Determine whether the buffer itself is invalid.
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
FileID getOrCreateFileID(const FileEntry *SourceFile, SrcMgr::CharacteristicKind FileCharacter)
Get the FileID for SourceFile if it exists.
std::pair< SourceLocation, StringRef > getModuleImportLoc(SourceLocation Loc) const
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...
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
FileID createFileID(UnownedTag, const 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.
Represents a character-granular source range.
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 isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
const AnnotatedLine * Line
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...
const FileEntry * ContentsEntry
References the file which the contents were actually loaded from.
bool operator()(SourceLocation LHS, SourceLocation RHS) const
bool isWrittenInMainFile(SourceLocation Loc) const
Returns true if the spelling location for the given location is in the main file buffer.
bool shouldFreeBuffer() const
Determine whether the buffer should be freed.
Represents an unpacked "presumed" location which can be presented to the user.
SourceLocation getEnd() const
static ExpansionInfo createForTokenSplit(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End)
Return a special ExpansionInfo representing a token that ends prematurely.
bool isLocalFileID(FileID FID) const
Returns true if FID did not come from a PCH/Module.
bool hasFileInfo(const FileEntry *File) const
fileinfo_iterator fileinfo_begin() const
const ExpansionInfo & getExpansion() const
unsigned getOffset() const
ContentCache(const ContentCache &RHS)
The copy ctor does not allow copies where source object has either a non-NULL Buffer or SourceLineCac...
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
SourceLocation getExpansionLocEnd() const
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Information about a FileID, basically just the logical file that it represents and include stack info...
const ContentCache * getContentCache() const
std::pair< FileID, unsigned > getDecomposedSpellingLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Encodes a location in the source.
FileID getPreambleFileID() const
Get the file ID for the precompiled preamble if there is one.
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...
unsigned IsSystemFile
True if this content cache was initially created for a source file considered as a system one...
Cached information about one file (either on disk or in the virtual file system). ...
const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a local SLocEntry. This is exposed for indexing.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
bool isModuleMap(CharacteristicKind CK)
Determine whether a file characteristic is for a module map.
ContentCache & operator=(const ContentCache &RHS)=delete
unsigned * SourceLineCache
A bump pointer allocated array of offsets for each source line.
ContentCache(const FileEntry *Ent=nullptr)
llvm::DenseMap< const FileEntry *, SrcMgr::ContentCache * >::const_iterator fileinfo_iterator
void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)
Push an entry to the module build stack.
bool operator()(SourceRange LHS, SourceRange RHS) const
External source of source location entries.
SourceLocation getExpansionLocStart() const
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token.
bool isInExternCSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in an "extern C" system header.
llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const
Returns the kind of memory used to back the memory buffer for this content cache. ...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
const llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
bool isMacroBodyExpansion() const
SourceRange getAsRange() const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
Reads an AST files chain containing the contents of a translation unit.
void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree=false)
Replace the existing buffer (which will be deleted) with the given buffer.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location...
CharSourceRange getExpansionRange(CharSourceRange Range) const
Given a CharSourceRange object, return the range of tokens or characters covered by the expansion in ...
FileID getMainFileID() const
Returns the FileID of the main source file.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
const size_t malloc_bytes
void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
Holds the cache used by isBeforeInTranslationUnit.
void setOverridenFilesKeepOriginalName(bool value)
Set true if the SourceManager should report the original file name for contents of files that were ov...
bool isWrittenInCommandLineFile(SourceLocation Loc) const
Returns whether Loc is located in a <command line>=""> file.
SourceLocation getEnd() const
unsigned loaded_sloc_entry_size() const
Get the number of loaded SLocEntries we have.
unsigned BufferOverridden
Indicates whether the buffer itself was provided to override the actual file contents.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
bool userFilesAreVolatile() const
True if non-system source files should be treated as volatile (likely to change while trying to use t...
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
bool isWrittenInScratchSpace(SourceLocation Loc) const
Returns whether Loc is located in a <scratch space>=""> file.
Defines the clang::SourceLocation class and associated facilities.
static bool isInMainFile(const clang::Diagnostic &D)
void setModuleBuildStack(ModuleBuildStack stack)
Set the module build stack.
void overrideFileContents(const FileEntry *SourceFile, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Writes an AST file containing the contents of a translation unit.
size_t getContentCacheSize() const
Return the total amount of physical memory allocated by the ContentCache allocator.
CharSourceRange getExpansionLocRange() const
A SourceLocation and its associated SourceManager.
const FileEntry * getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
Returns the FileEntry record for the provided SLocEntry.
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 isFunctionMacroExpansion() const
bool isPointWithin(SourceLocation Location, SourceLocation Start, SourceLocation End) const
Return true if the Point is within Start and End.
bool isInSystemMacro(SourceLocation loc) const
Returns whether Loc is expanded from a macro in a system header.
void setAllFilesAreTransient(bool Transient)
Specify that all files that are read during this compilation are transient.
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
A trivial tuple used to represent a source range.
bool isLoadedSourceLocation(SourceLocation Loc) const
Returns true if Loc came from a PCH/Module.
SourceLocation getBegin() const
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.
const llvm::MemoryBuffer * getBuffer(FileID FID, bool *Invalid=nullptr) const
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
BeforeThanCompare(SourceManager &SM)
bool hasLineTable() const
Determine if the source manager has a line table.