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;
238 "ContentCache must be 8-byte aligned.");
263 unsigned NumCreatedFIDs : 31;
266 unsigned HasLineDirectives : 1;
269 llvm::PointerIntPair<const ContentCache*, 3, CharacteristicKind>
281 X.IncludeLoc = IL.getRawEncoding();
282 X.NumCreatedFIDs = 0;
283 X.HasLineDirectives =
false;
284 X.ContentAndKind.setPointer(Con);
285 X.ContentAndKind.setInt(FileCharacter);
295 return ContentAndKind.getPointer();
300 return ContentAndKind.getInt();
309 HasLineDirectives =
true;
324 unsigned SpellingLoc;
332 unsigned ExpansionLocStart, ExpansionLocEnd;
335 bool ExpansionIsTokenRange;
340 return SpellLoc.
isInvalid() ? getExpansionLocStart() : SpellLoc;
350 return EndLoc.
isInvalid() ? getExpansionLocStart() : EndLoc;
354 return ExpansionIsTokenRange;
359 SourceRange(getExpansionLocStart(), getExpansionLocEnd()),
360 isExpansionTokenRange());
365 return getExpansionLocStart().isValid() &&
370 return getExpansionLocStart().isValid() &&
375 return getExpansionLocStart().isValid() &&
376 getExpansionLocStart() != getExpansionLocEnd();
387 bool ExpansionIsTokenRange =
true) {
392 X.ExpansionIsTokenRange = ExpansionIsTokenRange;
431 return create(SpellingLoc, Start, End,
false);
441 unsigned IsExpansion : 1;
453 bool isFile()
const {
return !isExpansion(); }
456 assert(isFile() &&
"Not a file SLocEntry!");
461 assert(isExpansion() &&
"Not a macro expansion SLocEntry!");
466 assert(!(Offset & (1u << 31)) &&
"Offset is too large");
469 E.IsExpansion =
false;
475 assert(!(Offset & (1u << 31)) &&
"Offset is too large");
478 E.IsExpansion =
true;
496 virtual bool ReadSLocEntry(
int ID) = 0;
501 virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(
int ID) = 0;
512 FileID LQueryFID, RQueryFID;
517 bool IsLQFIDBeforeRQFID;
528 unsigned LCommonOffset, RCommonOffset;
536 return LQueryFID == LHS && RQueryFID == RHS;
544 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
545 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
552 if (LOffset == ROffset)
553 return IsLQFIDBeforeRQFID;
555 return LOffset < ROffset;
563 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
567 LQueryFID = RQueryFID =
FileID();
568 IsLQFIDBeforeRQFID =
false;
572 unsigned rCommonOffset) {
573 CommonFID = commonFID;
574 LCommonOffset = lCommonOffset;
575 RCommonOffset = rCommonOffset;
602 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
610 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
614 bool OverridenFilesKeepOriginalName =
true;
618 bool UserFilesAreVolatile;
623 bool FilesAreTransient =
false;
625 struct OverriddenFilesInfoTy {
628 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
636 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
638 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
639 if (!OverriddenFilesInfo)
640 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
641 return *OverriddenFilesInfo;
648 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
665 unsigned NextLocalOffset;
671 unsigned CurrentLoadedOffset;
675 static const unsigned MaxLoadedOffset = 1U << 31U;
681 llvm::BitVector SLocEntryLoaded;
690 mutable FileID LastFileIDLookup;
695 std::unique_ptr<LineTableInfo> LineTable;
699 mutable FileID LastLineNoFileIDQuery;
701 mutable unsigned LastLineNoFilePos;
702 mutable unsigned LastLineNoResult;
711 mutable unsigned NumLinearScans = 0;
712 mutable unsigned NumBinaryProbes = 0;
719 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap;
722 using IsBeforeInTUCacheKey = std::pair<FileID, FileID>;
726 using InBeforeInTUCache =
727 llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>;
730 mutable InBeforeInTUCache IBTUCache;
738 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
740 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
744 using MacroArgsMap = std::map<unsigned, SourceLocation>;
746 mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
760 bool UserFilesAreVolatile =
false);
765 void clearIDTables();
779 OverridenFilesKeepOriginalName = value;
788 return StoredModuleBuildStack;
793 StoredModuleBuildStack.clear();
794 StoredModuleBuildStack.append(stack.begin(), stack.end());
799 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
816 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
817 PreambleFileID = Preamble;
833 int LoadedID = 0,
unsigned LoadedOffset = 0) {
834 assert(SourceFile &&
"Null source file!");
836 getOrCreateContentCache(SourceFile,
isSystem(FileCharacter));
837 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
838 return createFileID(IR, SourceFile->
getName(), IncludePos, FileCharacter,
839 LoadedID, LoadedOffset);
844 int LoadedID = 0,
unsigned LoadedOffset = 0) {
847 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
848 return createFileID(IR, SourceFile.
getName(), IncludePos, FileCharacter,
849 LoadedID, LoadedOffset);
858 int LoadedID = 0,
unsigned LoadedOffset = 0,
860 StringRef Name = Buffer->getBufferIdentifier();
862 createMemBufferContentCache(Buffer.release(),
false),
863 Name, IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
874 int LoadedID = 0,
unsigned LoadedOffset = 0,
876 return createFileID(createMemBufferContentCache(Buffer,
true),
877 Buffer->getBufferIdentifier(), IncludeLoc,
878 FileCharacter, LoadedID, LoadedOffset);
885 FileID ID = translateFile(SourceFile);
905 bool ExpansionIsTokenRange =
true,
907 unsigned LoadedOffset = 0);
919 const llvm::MemoryBuffer *getMemoryBufferForFile(
const FileEntry *File,
920 bool *Invalid =
nullptr);
932 void overrideFileContents(
const FileEntry *SourceFile,
933 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
935 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
936 overrideFileContents(SourceFile, Buffer.release(),
false);
945 void overrideFileContents(
const FileEntry *SourceFile,
950 if (OverriddenFilesInfo) {
951 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
953 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
954 OverriddenFilesInfo->OverriddenFiles.end())
968 void setFileIsTransient(
const FileEntry *SourceFile);
973 FilesAreTransient = Transient;
985 bool *Invalid =
nullptr)
const {
986 bool MyInvalid =
false;
988 if (MyInvalid || !Entry.
isFile()) {
992 return getFakeBufferForRecovery();
1000 bool *Invalid =
nullptr)
const {
1001 bool MyInvalid =
false;
1003 if (MyInvalid || !Entry.
isFile()) {
1007 return getFakeBufferForRecovery();
1016 bool MyInvalid =
false;
1018 if (MyInvalid || !Entry.
isFile())
1029 bool Invalid =
false;
1031 if (Invalid || !Entry.
isFile())
1054 StringRef getBufferData(
FileID FID,
bool *Invalid =
nullptr)
const;
1059 bool Invalid =
false;
1061 if (Invalid || !Entry.
isFile())
1064 return Entry.
getFile().NumCreatedFIDs;
1070 bool Force =
false)
const {
1071 bool Invalid =
false;
1073 if (Invalid || !Entry.
isFile())
1076 assert((Force || Entry.
getFile().NumCreatedFIDs == 0) &&
"Already set!");
1091 unsigned SLocOffset = SpellingLoc.getOffset();
1094 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1095 return LastFileIDLookup;
1097 return getFileIDSlow(SLocOffset);
1102 if (
const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc)))
1103 return F->getName();
1110 bool Invalid =
false;
1112 if (Invalid || !Entry.
isFile())
1115 unsigned FileOffset = Entry.
getOffset();
1116 return SourceLocation::getFileLoc(FileOffset);
1122 bool Invalid =
false;
1124 if (Invalid || !Entry.
isFile())
1127 unsigned FileOffset = Entry.
getOffset();
1128 return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID));
1134 bool Invalid =
false;
1136 if (Invalid || !Entry.
isFile())
1145 std::pair<SourceLocation, StringRef>
1147 FileID FID = getFileID(Loc);
1163 return getExpansionLocSlowCase(Loc);
1171 return getFileLocSlowCase(Loc);
1211 return getSpellingLocSlowCase(Loc);
1224 bool Invalid =
false;
1230 return Entry.
isFile() ? SourceLocation::getFileLoc(GlobalOffset)
1231 : SourceLocation::getMacroLoc(GlobalOffset);
1239 FileID FID = getFileID(Loc);
1240 bool Invalid =
false;
1243 return std::make_pair(
FileID(), 0);
1244 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1251 std::pair<FileID, unsigned>
1253 FileID FID = getFileID(Loc);
1254 bool Invalid =
false;
1257 return std::make_pair(
FileID(), 0);
1261 return std::make_pair(FID, Offset);
1263 return getDecomposedExpansionLocSlowCase(E);
1270 std::pair<FileID, unsigned>
1272 FileID FID = getFileID(Loc);
1273 bool Invalid =
false;
1276 return std::make_pair(
FileID(), 0);
1280 return std::make_pair(FID, Offset);
1281 return getDecomposedSpellingLocSlowCase(E, Offset);
1286 std::pair<FileID, unsigned> getDecomposedIncludedLoc(
FileID FID)
const;
1293 return getDecomposedLoc(SpellingLoc).second;
1339 unsigned *RelativeOffset =
nullptr)
const {
1340 assert(((Start.getOffset() < NextLocalOffset &&
1341 Start.getOffset()+Length <= NextLocalOffset) ||
1342 (Start.getOffset() >= CurrentLoadedOffset &&
1343 Start.getOffset()+Length < MaxLoadedOffset)) &&
1344 "Chunk is not valid SLoc address space");
1345 unsigned LocOffs = Loc.getOffset();
1346 unsigned BeginOffs = Start.getOffset();
1347 unsigned EndOffs = BeginOffs + Length;
1348 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1350 *RelativeOffset = LocOffs - BeginOffs;
1363 int *RelativeOffset)
const {
1364 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1365 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1366 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1368 if (LHSLoaded == RHSLoaded) {
1370 *RelativeOffset = RHSOffs - LHSOffs;
1386 bool *Invalid =
nullptr)
const;
1394 unsigned getColumnNumber(
FileID FID,
unsigned FilePos,
1395 bool *Invalid =
nullptr)
const;
1397 bool *Invalid =
nullptr)
const;
1399 bool *Invalid =
nullptr)
const;
1401 bool *Invalid =
nullptr)
const;
1409 unsigned getLineNumber(
FileID FID,
unsigned FilePos,
bool *Invalid =
nullptr)
const;
1410 unsigned getSpellingLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1411 unsigned getExpansionLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1412 unsigned getPresumedLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1419 StringRef getBufferName(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1447 bool UseLineDirectives =
true)
const;
1463 return getFileID(Loc1) == getFileID(Loc2);
1471 return getFileID(Loc) == getMainFileID();
1476 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1477 return Filename.equals(
"<built-in>");
1482 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1483 return Filename.equals(
"<command line>");
1488 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1489 return Filename.equals(
"<scratch space>");
1494 return isSystem(getFileCharacteristic(Loc));
1510 if (isWrittenInScratchSpace(getSpellingLoc(loc))) {
1512 loc = getImmediateMacroCallerLoc(loc);
1513 }
while (isWrittenInScratchSpace(getSpellingLoc(loc)));
1514 return isInSystemMacro(loc);
1517 return isInSystemHeader(getSpellingLoc(loc));
1521 unsigned getFileIDSize(
FileID FID)
const;
1527 unsigned *RelativeOffset =
nullptr)
const {
1528 unsigned Offs = Loc.getOffset();
1529 if (isOffsetInFileID(FID, Offs)) {
1531 *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
1543 unsigned getLineTableFilenameID(StringRef Str);
1549 void AddLineNote(
SourceLocation Loc,
unsigned LineNo,
int FilenameID,
1550 bool IsFileEntry,
bool IsFileExit,
1566 return ContentCacheAlloc.getTotalMemory();
1574 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1583 size_t getDataStructureSizes()
const;
1594 unsigned Line,
unsigned Col)
const;
1605 unsigned Line,
unsigned Col)
const;
1630 std::pair<bool, bool>
1631 isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs,
1632 std::pair<FileID, unsigned> &ROffs)
const;
1637 return isBeforeInSLocAddrSpace(LHS, RHS.getOffset());
1645 unsigned LHSOffset = LHS.getOffset();
1646 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1647 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1648 if (LHSLoaded == RHSLoaded)
1649 return LHSOffset < RHS;
1657 return Location == Start || Location == End ||
1658 (isBeforeInTranslationUnit(Start, Location) &&
1659 isBeforeInTranslationUnit(Location, End));
1664 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator;
1669 return FileInfos.find(File) != FileInfos.end();
1673 void PrintStats()
const;
1682 bool *Invalid =
nullptr)
const {
1683 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1684 return LocalSLocEntryTable[Index];
1692 bool *Invalid =
nullptr)
const {
1693 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1694 if (SLocEntryLoaded[Index])
1695 return LoadedSLocEntryTable[Index];
1696 return loadSLocEntry(Index, Invalid);
1700 bool *Invalid =
nullptr)
const {
1701 if (FID.ID == 0 || FID.ID == -1) {
1702 if (Invalid) *Invalid =
true;
1703 return LocalSLocEntryTable[0];
1705 return getSLocEntryByID(FID.ID, Invalid);
1711 assert(LoadedSLocEntryTable.empty() &&
1712 "Invalidating existing loaded entries");
1713 ExternalSLocEntries = Source;
1722 std::pair<int, unsigned>
1723 AllocateLoadedSLocEntries(
unsigned NumSLocEntries,
unsigned TotalSize);
1727 return Loc.getOffset() >= CurrentLoadedOffset;
1732 return Loc.getOffset() < NextLocalOffset;
1737 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1743 return !isLoadedFileID(FID);
1754 if (isMacroArgExpansion(Loc))
1755 return getImmediateSpellingLoc(Loc);
1759 return getImmediateExpansionRange(Loc).
getBegin();
1769 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1776 bool *Invalid =
nullptr)
const {
1777 assert(ID != -1 &&
"Using FileID sentinel value");
1779 return getLoadedSLocEntryByID(ID, Invalid);
1780 return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
1784 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1785 return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
1793 unsigned LoadedOffset = 0);
1797 inline bool isOffsetInFileID(
FileID FID,
unsigned SLocOffset)
const {
1800 if (SLocOffset < Entry.
getOffset())
return false;
1807 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1808 return SLocOffset < NextLocalOffset;
1812 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();
1831 unsigned LoadedOffset);
1834 getOrCreateContentCache(
const FileEntry *SourceFile,
1835 bool isSystemFile =
false);
1839 createMemBufferContentCache(
const llvm::MemoryBuffer *Buf,
bool DoNotFree);
1841 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1842 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1843 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1849 std::pair<FileID, unsigned>
1851 std::pair<FileID, unsigned>
1854 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
FileID FID)
const;
1855 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1859 unsigned ExpansionLength)
const;
1863 template<
typename T>
1875 return SM.isBeforeInTranslationUnit(LHS, RHS);
1909 std::unique_ptr<FileManager> FileMgr;
1910 std::unique_ptr<DiagnosticsEngine> Diagnostics;
1911 std::unique_ptr<SourceManager> SourceMgr;
1916 #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.
unsigned IsFileVolatile
True if this content cache was initially created for a source file considered to be volatile (likely ...
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.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
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
const StringRef getName() 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.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
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
Optional< FileEntryRef > getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
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...
StringRef getName() const
Returns the name of the file that was used when the file was loaded from the underlying file system...
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.
static const char * getInvalidBOM(StringRef BufStr)
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.
StringRef getName() const
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...
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)
const llvm::MemoryBuffer * getBuffer(DiagnosticsEngine &Diag, FileManager &FM, SourceLocation Loc=SourceLocation(), bool *Invalid=nullptr) const
Returns the memory buffer for the associated content.
bool hasLineTable() const
Determine if the source manager has a line table.
const FileEntry & getFileEntry() const