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 & (1u << 31)) &&
"Offset is too large");
455 E.IsExpansion =
false;
461 assert(!(Offset & (1u << 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 Force =
false)
const {
1029 bool Invalid =
false;
1031 if (Invalid || !Entry.
isFile())
1034 assert((Force || Entry.
getFile().NumCreatedFIDs == 0) &&
"Already set!");
1049 unsigned SLocOffset = SpellingLoc.getOffset();
1052 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1053 return LastFileIDLookup;
1055 return getFileIDSlow(SLocOffset);
1060 if (
const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc)))
1061 return F->getName();
1068 bool Invalid =
false;
1070 if (Invalid || !Entry.
isFile())
1073 unsigned FileOffset = Entry.
getOffset();
1074 return SourceLocation::getFileLoc(FileOffset);
1080 bool Invalid =
false;
1082 if (Invalid || !Entry.
isFile())
1085 unsigned FileOffset = Entry.
getOffset();
1086 return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID));
1092 bool Invalid =
false;
1094 if (Invalid || !Entry.
isFile())
1103 std::pair<SourceLocation, StringRef>
1105 FileID FID = getFileID(Loc);
1121 return getExpansionLocSlowCase(Loc);
1129 return getFileLocSlowCase(Loc);
1169 return getSpellingLocSlowCase(Loc);
1182 bool Invalid =
false;
1188 return Entry.
isFile() ? SourceLocation::getFileLoc(GlobalOffset)
1189 : SourceLocation::getMacroLoc(GlobalOffset);
1197 FileID FID = getFileID(Loc);
1198 bool Invalid =
false;
1201 return std::make_pair(
FileID(), 0);
1202 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1209 std::pair<FileID, unsigned>
1211 FileID FID = getFileID(Loc);
1212 bool Invalid =
false;
1215 return std::make_pair(
FileID(), 0);
1219 return std::make_pair(FID, Offset);
1221 return getDecomposedExpansionLocSlowCase(E);
1228 std::pair<FileID, unsigned>
1230 FileID FID = getFileID(Loc);
1231 bool Invalid =
false;
1234 return std::make_pair(
FileID(), 0);
1238 return std::make_pair(FID, Offset);
1239 return getDecomposedSpellingLocSlowCase(E, Offset);
1244 std::pair<FileID, unsigned> getDecomposedIncludedLoc(
FileID FID)
const;
1251 return getDecomposedLoc(SpellingLoc).second;
1297 unsigned *RelativeOffset =
nullptr)
const {
1298 assert(((Start.getOffset() < NextLocalOffset &&
1299 Start.getOffset()+Length <= NextLocalOffset) ||
1300 (Start.getOffset() >= CurrentLoadedOffset &&
1301 Start.getOffset()+Length < MaxLoadedOffset)) &&
1302 "Chunk is not valid SLoc address space");
1303 unsigned LocOffs = Loc.getOffset();
1304 unsigned BeginOffs = Start.getOffset();
1305 unsigned EndOffs = BeginOffs + Length;
1306 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1308 *RelativeOffset = LocOffs - BeginOffs;
1321 int *RelativeOffset)
const {
1322 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1323 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1324 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1326 if (LHSLoaded == RHSLoaded) {
1328 *RelativeOffset = RHSOffs - LHSOffs;
1344 bool *Invalid =
nullptr)
const;
1352 unsigned getColumnNumber(
FileID FID,
unsigned FilePos,
1353 bool *Invalid =
nullptr)
const;
1355 bool *Invalid =
nullptr)
const;
1357 bool *Invalid =
nullptr)
const;
1359 bool *Invalid =
nullptr)
const;
1367 unsigned getLineNumber(
FileID FID,
unsigned FilePos,
bool *Invalid =
nullptr)
const;
1368 unsigned getSpellingLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1369 unsigned getExpansionLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1370 unsigned getPresumedLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1377 StringRef getBufferName(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1405 bool UseLineDirectives =
true)
const;
1421 return getFileID(Loc1) == getFileID(Loc2);
1429 return getFileID(Loc) == getMainFileID();
1434 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1435 return Filename.equals(
"<built-in>");
1440 StringRef
Filename(getPresumedLoc(Loc).getFilename());
1441 return Filename.equals(
"<command line>");
1446 return isSystem(getFileCharacteristic(Loc));
1456 return loc.
isMacroID() && isInSystemHeader(getSpellingLoc(loc));
1460 unsigned getFileIDSize(
FileID FID)
const;
1466 unsigned *RelativeOffset =
nullptr)
const {
1467 unsigned Offs = Loc.getOffset();
1468 if (isOffsetInFileID(FID, Offs)) {
1470 *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
1482 unsigned getLineTableFilenameID(StringRef Str);
1488 void AddLineNote(
SourceLocation Loc,
unsigned LineNo,
int FilenameID,
1489 bool IsFileEntry,
bool IsFileExit,
1505 return ContentCacheAlloc.getTotalMemory();
1513 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1522 size_t getDataStructureSizes()
const;
1533 unsigned Line,
unsigned Col)
const;
1544 unsigned Line,
unsigned Col)
const;
1569 std::pair<bool, bool>
1570 isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs,
1571 std::pair<FileID, unsigned> &ROffs)
const;
1576 return isBeforeInSLocAddrSpace(LHS, RHS.getOffset());
1584 unsigned LHSOffset = LHS.getOffset();
1585 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1586 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1587 if (LHSLoaded == RHSLoaded)
1588 return LHSOffset < RHS;
1596 return Location == Start || Location == End ||
1597 (isBeforeInTranslationUnit(Start, Location) &&
1598 isBeforeInTranslationUnit(Location, End));
1603 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator;
1608 return FileInfos.find(File) != FileInfos.end();
1612 void PrintStats()
const;
1621 bool *Invalid =
nullptr)
const {
1622 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1623 return LocalSLocEntryTable[Index];
1631 bool *Invalid =
nullptr)
const {
1632 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1633 if (SLocEntryLoaded[Index])
1634 return LoadedSLocEntryTable[Index];
1635 return loadSLocEntry(Index, Invalid);
1639 bool *Invalid =
nullptr)
const {
1640 if (FID.ID == 0 || FID.ID == -1) {
1641 if (Invalid) *Invalid =
true;
1642 return LocalSLocEntryTable[0];
1644 return getSLocEntryByID(FID.ID, Invalid);
1650 assert(LoadedSLocEntryTable.empty() &&
1651 "Invalidating existing loaded entries");
1652 ExternalSLocEntries = Source;
1661 std::pair<int, unsigned>
1662 AllocateLoadedSLocEntries(
unsigned NumSLocEntries,
unsigned TotalSize);
1666 return Loc.getOffset() >= CurrentLoadedOffset;
1671 return Loc.getOffset() < NextLocalOffset;
1676 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1682 return !isLoadedFileID(FID);
1693 if (isMacroArgExpansion(Loc))
1694 return getImmediateSpellingLoc(Loc);
1698 return getImmediateExpansionRange(Loc).
getBegin();
1708 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1715 bool *Invalid =
nullptr)
const {
1716 assert(ID != -1 &&
"Using FileID sentinel value");
1718 return getLoadedSLocEntryByID(ID, Invalid);
1719 return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
1723 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1724 return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
1732 unsigned LoadedOffset = 0);
1736 inline bool isOffsetInFileID(
FileID FID,
unsigned SLocOffset)
const {
1739 if (SLocOffset < Entry.
getOffset())
return false;
1746 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1747 return SLocOffset < NextLocalOffset;
1751 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();
1770 int LoadedID,
unsigned LoadedOffset);
1773 getOrCreateContentCache(
const FileEntry *SourceFile,
1774 bool isSystemFile =
false);
1778 createMemBufferContentCache(llvm::MemoryBuffer *Buf,
bool DoNotFree);
1780 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1781 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1782 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1788 std::pair<FileID, unsigned>
1790 std::pair<FileID, unsigned>
1793 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
FileID FID)
const;
1794 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1798 unsigned ExpansionLength)
const;
1802 template<
typename T>
1814 return SM.isBeforeInTranslationUnit(LHS, RHS);
1848 std::unique_ptr<FileManager> FileMgr;
1849 std::unique_ptr<DiagnosticsEngine> Diagnostics;
1850 std::unique_ptr<SourceManager> SourceMgr;
1855 #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.
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
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...
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.
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
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...
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 ...
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