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" 109 mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2> Buffer;
156 : Buffer(nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
168 assert(RHS.Buffer.getPointer() ==
nullptr &&
170 "Passed ContentCache object cannot own a buffer.");
191 bool *Invalid =
nullptr)
const;
213 llvm::MemoryBuffer *
getRawBuffer()
const {
return Buffer.getPointer(); }
217 void replaceBuffer(llvm::MemoryBuffer *B,
bool DoNotFree =
false);
221 return Buffer.getInt() & InvalidFlag;
226 return (Buffer.getInt() & DoNotFreeFlag) == 0;
233 "ContentCache must be 8-byte aligned.");
258 unsigned NumCreatedFIDs : 31;
261 unsigned HasLineDirectives : 1;
264 llvm::PointerIntPair<const ContentCache*, 3, CharacteristicKind>
272 X.IncludeLoc = IL.getRawEncoding();
273 X.NumCreatedFIDs = 0;
274 X.HasLineDirectives =
false;
275 X.ContentAndKind.setPointer(Con);
276 X.ContentAndKind.setInt(FileCharacter);
285 return ContentAndKind.getPointer();
290 return ContentAndKind.getInt();
299 HasLineDirectives =
true;
310 unsigned SpellingLoc;
318 unsigned ExpansionLocStart, ExpansionLocEnd;
321 bool ExpansionIsTokenRange;
326 return SpellLoc.
isInvalid() ? getExpansionLocStart() : SpellLoc;
336 return EndLoc.
isInvalid() ? getExpansionLocStart() : EndLoc;
340 return ExpansionIsTokenRange;
345 SourceRange(getExpansionLocStart(), getExpansionLocEnd()),
346 isExpansionTokenRange());
351 return getExpansionLocStart().isValid() &&
356 return getExpansionLocStart().isValid() &&
361 return getExpansionLocStart().isValid() &&
362 getExpansionLocStart() != getExpansionLocEnd();
373 bool ExpansionIsTokenRange =
true) {
378 X.ExpansionIsTokenRange = ExpansionIsTokenRange;
417 return create(SpellingLoc, Start, End,
false);
427 unsigned IsExpansion : 1;
439 bool isFile()
const {
return !isExpansion(); }
442 assert(isFile() &&
"Not a file SLocEntry!");
447 assert(isExpansion() &&
"Not a macro expansion SLocEntry!");
452 assert(!(Offset & (1 << 31)) &&
"Offset is too large");
455 E.IsExpansion =
false;
461 assert(!(Offset & (1 << 31)) &&
"Offset is too large");
464 E.IsExpansion =
true;
482 virtual bool ReadSLocEntry(
int ID) = 0;
487 virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(
int ID) = 0;
498 FileID LQueryFID, RQueryFID;
503 bool IsLQFIDBeforeRQFID;
514 unsigned LCommonOffset, RCommonOffset;
522 return LQueryFID == LHS && RQueryFID == RHS;
530 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
531 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
538 if (LOffset == ROffset)
539 return IsLQFIDBeforeRQFID;
541 return LOffset < ROffset;
549 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
553 LQueryFID = RQueryFID =
FileID();
554 IsLQFIDBeforeRQFID =
false;
558 unsigned rCommonOffset) {
559 CommonFID = commonFID;
560 LCommonOffset = lCommonOffset;
561 RCommonOffset = rCommonOffset;
588 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
596 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
600 bool OverridenFilesKeepOriginalName =
true;
604 bool UserFilesAreVolatile;
609 bool FilesAreTransient =
false;
611 struct OverriddenFilesInfoTy {
614 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
622 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
624 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
625 if (!OverriddenFilesInfo)
626 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
627 return *OverriddenFilesInfo;
634 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
651 unsigned NextLocalOffset;
657 unsigned CurrentLoadedOffset;
661 static const unsigned MaxLoadedOffset = 1U << 31U;
667 llvm::BitVector SLocEntryLoaded;
676 mutable FileID LastFileIDLookup;
685 mutable FileID LastLineNoFileIDQuery;
687 mutable unsigned LastLineNoFilePos;
688 mutable unsigned LastLineNoResult;
697 mutable unsigned NumLinearScans = 0;
698 mutable unsigned NumBinaryProbes = 0;
705 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap;
708 using IsBeforeInTUCacheKey = std::pair<FileID, FileID>;
712 using InBeforeInTUCache =
713 llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>;
716 mutable InBeforeInTUCache IBTUCache;
724 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
726 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
730 using MacroArgsMap = std::map<unsigned, SourceLocation>;
732 mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
746 bool UserFilesAreVolatile =
false);
751 void clearIDTables();
765 OverridenFilesKeepOriginalName = value;
774 return StoredModuleBuildStack;
779 StoredModuleBuildStack.clear();
780 StoredModuleBuildStack.append(stack.begin(), stack.end());
785 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
802 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
803 PreambleFileID = Preamble;
819 int LoadedID = 0,
unsigned LoadedOffset = 0) {
821 getOrCreateContentCache(SourceFile,
isSystem(FileCharacter));
822 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
823 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
832 int LoadedID = 0,
unsigned LoadedOffset = 0,
835 createMemBufferContentCache(Buffer.release(),
false),
836 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
847 int LoadedID = 0,
unsigned LoadedOffset = 0,
849 return createFileID(createMemBufferContentCache(Buffer,
true),
850 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
857 FileID ID = translateFile(SourceFile);
877 bool ExpansionIsTokenRange =
true,
879 unsigned LoadedOffset = 0);
891 llvm::MemoryBuffer *getMemoryBufferForFile(
const FileEntry *File,
892 bool *Invalid =
nullptr);
904 void overrideFileContents(
const FileEntry *SourceFile,
905 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
907 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
908 overrideFileContents(SourceFile, Buffer.release(),
false);
917 void overrideFileContents(
const FileEntry *SourceFile,
922 if (OverriddenFilesInfo) {
923 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
925 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
926 OverriddenFilesInfo->OverriddenFiles.end())
936 void disableFileContentsOverride(
const FileEntry *File);
939 void setFileIsTransient(
const FileEntry *SourceFile);
944 FilesAreTransient = Transient;
956 bool *Invalid =
nullptr)
const {
957 bool MyInvalid =
false;
959 if (MyInvalid || !Entry.
isFile()) {
963 return getFakeBufferForRecovery();
971 bool MyInvalid =
false;
973 if (MyInvalid || !Entry.
isFile()) {
977 return getFakeBufferForRecovery();
987 bool MyInvalid =
false;
989 if (MyInvalid || !Entry.
isFile())
1012 StringRef getBufferData(
FileID FID,
bool *Invalid =
nullptr)
const;
1017 bool Invalid =
false;
1019 if (Invalid || !Entry.
isFile())
1022 return Entry.
getFile().NumCreatedFIDs;
1028 bool Invalid =
false;
1030 if (Invalid || !Entry.
isFile())
1033 assert(Entry.
getFile().NumCreatedFIDs == 0 &&
"Already set!");
1048 unsigned SLocOffset = SpellingLoc.getOffset();
1051 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1052 return LastFileIDLookup;
1054 return getFileIDSlow(SLocOffset);
1059 if (
const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc)))
1060 return F->getName();
1067 bool Invalid =
false;
1069 if (Invalid || !Entry.
isFile())
1072 unsigned FileOffset = Entry.
getOffset();
1073 return SourceLocation::getFileLoc(FileOffset);
1079 bool Invalid =
false;
1081 if (Invalid || !Entry.
isFile())
1084 unsigned FileOffset = Entry.
getOffset();
1085 return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID));
1091 bool Invalid =
false;
1093 if (Invalid || !Entry.
isFile())
1102 std::pair<SourceLocation, StringRef>
1104 FileID FID = getFileID(Loc);
1120 return getExpansionLocSlowCase(Loc);
1128 return getFileLocSlowCase(Loc);
1168 return getSpellingLocSlowCase(Loc);
1181 bool Invalid =
false;
1187 return Entry.
isFile() ? SourceLocation::getFileLoc(GlobalOffset)
1188 : SourceLocation::getMacroLoc(GlobalOffset);
1196 FileID FID = getFileID(Loc);
1197 bool Invalid =
false;
1200 return std::make_pair(
FileID(), 0);
1201 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1208 std::pair<FileID, unsigned>
1210 FileID FID = getFileID(Loc);
1211 bool Invalid =
false;
1214 return std::make_pair(
FileID(), 0);
1218 return std::make_pair(FID, Offset);
1220 return getDecomposedExpansionLocSlowCase(E);
1227 std::pair<FileID, unsigned>
1229 FileID FID = getFileID(Loc);
1230 bool Invalid =
false;
1233 return std::make_pair(
FileID(), 0);
1237 return std::make_pair(FID, Offset);
1238 return getDecomposedSpellingLocSlowCase(E, Offset);
1243 std::pair<FileID, unsigned> getDecomposedIncludedLoc(
FileID FID)
const;
1250 return getDecomposedLoc(SpellingLoc).second;
1296 unsigned *RelativeOffset =
nullptr)
const {
1297 assert(((Start.getOffset() < NextLocalOffset &&
1298 Start.getOffset()+Length <= NextLocalOffset) ||
1299 (Start.getOffset() >= CurrentLoadedOffset &&
1300 Start.getOffset()+Length < MaxLoadedOffset)) &&
1301 "Chunk is not valid SLoc address space");
1302 unsigned LocOffs = Loc.getOffset();
1303 unsigned BeginOffs = Start.getOffset();
1304 unsigned EndOffs = BeginOffs + Length;
1305 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1307 *RelativeOffset = LocOffs - BeginOffs;
1320 int *RelativeOffset)
const {
1321 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1322 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1323 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1325 if (LHSLoaded == RHSLoaded) {
1327 *RelativeOffset = RHSOffs - LHSOffs;
1343 bool *Invalid =
nullptr)
const;
1351 unsigned getColumnNumber(
FileID FID,
unsigned FilePos,
1352 bool *Invalid =
nullptr)
const;
1354 bool *Invalid =
nullptr)
const;
1356 bool *Invalid =
nullptr)
const;
1358 bool *Invalid =
nullptr)
const;
1366 unsigned getLineNumber(
FileID FID,
unsigned FilePos,
bool *Invalid =
nullptr)
const;
1367 unsigned getSpellingLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1368 unsigned getExpansionLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1369 unsigned getPresumedLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1376 StringRef getBufferName(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1404 bool UseLineDirectives =
true)
const;
1420 return getFileID(Loc1) == getFileID(Loc2);
1428 return getFileID(Loc) == getMainFileID();
1433 return isSystem(getFileCharacteristic(Loc));
1443 return loc.
isMacroID() && isInSystemHeader(getSpellingLoc(loc));
1447 unsigned getFileIDSize(
FileID FID)
const;
1453 unsigned *RelativeOffset =
nullptr)
const {
1454 unsigned Offs = Loc.getOffset();
1455 if (isOffsetInFileID(FID, Offs)) {
1457 *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
1469 unsigned getLineTableFilenameID(StringRef Str);
1475 void AddLineNote(
SourceLocation Loc,
unsigned LineNo,
int FilenameID,
1476 bool IsFileEntry,
bool IsFileExit,
1492 return ContentCacheAlloc.getTotalMemory();
1500 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1509 size_t getDataStructureSizes()
const;
1520 unsigned Line,
unsigned Col)
const;
1531 unsigned Line,
unsigned Col)
const;
1556 std::pair<bool, bool>
1557 isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs,
1558 std::pair<FileID, unsigned> &ROffs)
const;
1563 return isBeforeInSLocAddrSpace(LHS, RHS.getOffset());
1571 unsigned LHSOffset = LHS.getOffset();
1572 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1573 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1574 if (LHSLoaded == RHSLoaded)
1575 return LHSOffset < RHS;
1583 return Location == Start || Location == End ||
1584 (isBeforeInTranslationUnit(Start, Location) &&
1585 isBeforeInTranslationUnit(Location, End));
1590 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator;
1595 return FileInfos.find(File) != FileInfos.end();
1599 void PrintStats()
const;
1608 bool *Invalid =
nullptr)
const {
1609 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1610 return LocalSLocEntryTable[Index];
1618 bool *Invalid =
nullptr)
const {
1619 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1620 if (SLocEntryLoaded[Index])
1621 return LoadedSLocEntryTable[Index];
1622 return loadSLocEntry(Index, Invalid);
1626 bool *Invalid =
nullptr)
const {
1627 if (FID.ID == 0 || FID.ID == -1) {
1628 if (Invalid) *Invalid =
true;
1629 return LocalSLocEntryTable[0];
1631 return getSLocEntryByID(FID.ID, Invalid);
1637 assert(LoadedSLocEntryTable.empty() &&
1638 "Invalidating existing loaded entries");
1639 ExternalSLocEntries = Source;
1648 std::pair<int, unsigned>
1649 AllocateLoadedSLocEntries(
unsigned NumSLocEntries,
unsigned TotalSize);
1653 return Loc.getOffset() >= CurrentLoadedOffset;
1658 return Loc.getOffset() < NextLocalOffset;
1663 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1669 return !isLoadedFileID(FID);
1680 if (isMacroArgExpansion(Loc))
1681 return getImmediateSpellingLoc(Loc);
1685 return getImmediateExpansionRange(Loc).
getBegin();
1695 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1702 bool *Invalid =
nullptr)
const {
1703 assert(ID != -1 &&
"Using FileID sentinel value");
1705 return getLoadedSLocEntryByID(ID, Invalid);
1706 return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
1710 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1711 return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
1719 unsigned LoadedOffset = 0);
1723 inline bool isOffsetInFileID(
FileID FID,
unsigned SLocOffset)
const {
1726 if (SLocOffset < Entry.
getOffset())
return false;
1733 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1734 return SLocOffset < NextLocalOffset;
1738 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();
1757 int LoadedID,
unsigned LoadedOffset);
1760 getOrCreateContentCache(
const FileEntry *SourceFile,
1761 bool isSystemFile =
false);
1765 createMemBufferContentCache(llvm::MemoryBuffer *Buf,
bool DoNotFree);
1767 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1768 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1769 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1775 std::pair<FileID, unsigned>
1777 std::pair<FileID, unsigned>
1780 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
FileID FID)
const;
1781 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1785 unsigned ExpansionLength)
const;
1789 template<
typename T>
1801 return SM.isBeforeInTranslationUnit(LHS, RHS);
1835 std::unique_ptr<FileManager> FileMgr;
1836 std::unique_ptr<DiagnosticsEngine> Diagnostics;
1837 std::unique_ptr<SourceManager> SourceMgr;
1842 #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.
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const
Set the number of FileIDs (files and macros) that were created during preprocessing of FID...
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.
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
FileID createFileID(UnownedTag, 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.
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
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...
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.
llvm::MemoryBuffer * getBuffer(DiagnosticsEngine &Diag, const SourceManager &SM, SourceLocation Loc=SourceLocation(), bool *Invalid=nullptr) const
Returns the memory buffer for the associated content.
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...
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
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.
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
void replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree=false)
Replace the existing buffer (which will be deleted) with the given buffer.
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. ...
llvm::MemoryBuffer * getRawBuffer() const
Get the underlying buffer, returning NULL if the buffer is not yet available.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
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.
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...
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 ...
Defines the clang::SourceLocation class and associated facilities.
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.
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.
llvm::MemoryBuffer * getBuffer(FileID FID, bool *Invalid=nullptr) const