35 #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H
36 #define LLVM_CLANG_BASIC_SOURCEMANAGER_H
41 #include "llvm/ADT/ArrayRef.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/PointerUnion.h"
47 #include "llvm/Support/AlignOf.h"
48 #include "llvm/Support/Allocator.h"
49 #include "llvm/Support/DataTypes.h"
50 #include "llvm/Support/MemoryBuffer.h"
58 class DiagnosticsEngine;
98 mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2> Buffer;
119 unsigned *SourceLineCache;
124 unsigned NumLines : 31;
131 unsigned BufferOverridden : 1;
135 unsigned IsSystemFile : 1;
137 ContentCache(
const FileEntry *Ent =
nullptr) : ContentCache(Ent, Ent) {}
140 : Buffer(
nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
141 SourceLineCache(
nullptr), NumLines(0), BufferOverridden(
false),
142 IsSystemFile(
false) {}
149 ContentCache(
const ContentCache &RHS)
150 : Buffer(
nullptr,
false), SourceLineCache(
nullptr),
151 BufferOverridden(
false), IsSystemFile(
false) {
152 OrigEntry = RHS.OrigEntry;
153 ContentsEntry = RHS.ContentsEntry;
155 assert(RHS.Buffer.getPointer() ==
nullptr &&
156 RHS.SourceLineCache ==
nullptr &&
157 "Passed ContentCache object cannot own a buffer.");
159 NumLines = RHS.NumLines;
174 bool *Invalid =
nullptr)
const;
182 unsigned getSize()
const;
188 unsigned getSizeBytesMapped()
const;
192 llvm::MemoryBuffer::BufferKind getMemoryBufferKind()
const;
194 void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
195 assert(!Buffer.getPointer() &&
"MemoryBuffer already set.");
196 Buffer.setPointer(B.release());
202 llvm::MemoryBuffer *getRawBuffer()
const {
return Buffer.getPointer(); }
206 void replaceBuffer(llvm::MemoryBuffer *B,
bool DoNotFree =
false);
209 bool isBufferInvalid()
const {
210 return Buffer.getInt() & InvalidFlag;
214 bool shouldFreeBuffer()
const {
215 return (Buffer.getInt() & DoNotFreeFlag) == 0;
220 ContentCache &operator=(
const ContentCache& RHS) =
delete;
225 static_assert(llvm::AlignOf<ContentCache>::Alignment >= 8,
226 "ContentCache must be 8-byte aligned.");
247 unsigned NumCreatedFIDs;
262 X.IncludeLoc = IL.getRawEncoding();
263 X.NumCreatedFIDs = 0;
264 X.Data = (uintptr_t)Con;
265 assert((X.Data & 7) == 0 &&
"ContentCache pointer insufficiently aligned");
266 assert((
unsigned)FileCharacter < 4 &&
"invalid file character");
275 return reinterpret_cast<const ContentCache*
>(Data & ~uintptr_t(7));
300 unsigned SpellingLoc;
308 unsigned ExpansionLocStart, ExpansionLocEnd;
403 assert(
isFile() &&
"Not a file SLocEntry!");
408 assert(
isExpansion() &&
"Not a macro expansion SLocEntry!");
421 E.Offset = (
Offset << 1) | 1;
455 FileID LQueryFID, RQueryFID;
460 bool IsLQFIDBeforeRQFID;
471 unsigned LCommonOffset, RCommonOffset;
478 return LQueryFID == LHS && RQueryFID == RHS;
486 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
487 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
494 if (LOffset == ROffset)
495 return IsLQFIDBeforeRQFID;
497 return LOffset < ROffset;
505 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
509 LQueryFID = RQueryFID =
FileID();
510 IsLQFIDBeforeRQFID =
false;
514 unsigned rCommonOffset) {
515 CommonFID = commonFID;
516 LCommonOffset = lCommonOffset;
517 RCommonOffset = rCommonOffset;
545 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
553 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
557 bool OverridenFilesKeepOriginalName;
561 bool UserFilesAreVolatile;
563 struct OverriddenFilesInfoTy {
566 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
573 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
575 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
576 if (!OverriddenFilesInfo)
577 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
578 return *OverriddenFilesInfo;
585 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
602 unsigned NextLocalOffset;
608 unsigned CurrentLoadedOffset;
612 static const unsigned MaxLoadedOffset = 1U << 31U;
618 std::vector<bool> SLocEntryLoaded;
627 mutable FileID LastFileIDLookup;
636 mutable FileID LastLineNoFileIDQuery;
637 mutable SrcMgr::ContentCache *LastLineNoContentCache;
638 mutable unsigned LastLineNoFilePos;
639 mutable unsigned LastLineNoResult;
648 mutable unsigned NumLinearScans, NumBinaryProbes;
655 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned> > IncludedLocMap;
658 typedef std::pair<FileID, FileID> IsBeforeInTUCacheKey;
662 typedef llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>
666 mutable InBeforeInTUCache IBTUCache;
674 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
676 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
680 typedef std::map<unsigned, SourceLocation> MacroArgsMap;
682 mutable llvm::DenseMap<FileID, MacroArgsMap *> MacroArgsCacheMap;
698 bool UserFilesAreVolatile =
false);
711 OverridenFilesKeepOriginalName = value;
720 return StoredModuleBuildStack;
725 StoredModuleBuildStack.clear();
726 StoredModuleBuildStack.append(stack.begin(), stack.end());
731 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
748 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
749 PreambleFileID = Preamble;
765 int LoadedID = 0,
unsigned LoadedOffset = 0) {
766 const SrcMgr::ContentCache *
767 IR = getOrCreateContentCache(SourceFile,
769 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
770 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
779 int LoadedID = 0,
unsigned LoadedOffset = 0,
781 return createFileID(createMemBufferContentCache(std::move(Buffer)),
782 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
801 unsigned LoadedOffset = 0);
808 bool *Invalid =
nullptr);
821 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
823 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
838 if (OverriddenFilesInfo) {
839 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
841 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
842 OverriddenFilesInfo->OverriddenFiles.end())
863 bool *Invalid =
nullptr)
const {
864 bool MyInvalid =
false;
866 if (MyInvalid || !Entry.
isFile()) {
870 return getFakeBufferForRecovery();
878 bool MyInvalid =
false;
880 if (MyInvalid || !Entry.
isFile()) {
884 return getFakeBufferForRecovery();
894 bool MyInvalid =
false;
896 if (MyInvalid || !Entry.
isFile())
902 return Content->OrigEntry;
911 return Content->OrigEntry;
924 bool Invalid =
false;
926 if (Invalid || !Entry.
isFile())
929 return Entry.
getFile().NumCreatedFIDs;
935 bool Invalid =
false;
937 if (Invalid || !Entry.
isFile())
940 assert(Entry.
getFile().NumCreatedFIDs == 0 &&
"Already set!");
955 unsigned SLocOffset = SpellingLoc.getOffset();
958 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
959 return LastFileIDLookup;
961 return getFileIDSlow(SLocOffset);
974 bool Invalid =
false;
976 if (Invalid || !Entry.
isFile())
980 return SourceLocation::getFileLoc(FileOffset);
986 bool Invalid =
false;
988 if (Invalid || !Entry.
isFile())
992 return SourceLocation::getFileLoc(FileOffset +
getFileIDSize(FID));
998 bool Invalid =
false;
1000 if (Invalid || !Entry.
isFile())
1009 std::pair<SourceLocation, StringRef>
1027 return getExpansionLocSlowCase(Loc);
1035 return getFileLocSlowCase(Loc);
1042 std::pair<SourceLocation,SourceLocation>
1047 std::pair<SourceLocation,SourceLocation>
1066 return getSpellingLocSlowCase(Loc);
1083 bool Invalid =
false;
1086 return std::make_pair(
FileID(), 0);
1087 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1094 std::pair<FileID, unsigned>
1097 bool Invalid =
false;
1100 return std::make_pair(
FileID(), 0);
1104 return std::make_pair(FID, Offset);
1106 return getDecomposedExpansionLocSlowCase(E);
1113 std::pair<FileID, unsigned>
1116 bool Invalid =
false;
1119 return std::make_pair(
FileID(), 0);
1123 return std::make_pair(FID, Offset);
1124 return getDecomposedSpellingLocSlowCase(E, Offset);
1178 unsigned *RelativeOffset =
nullptr)
const {
1179 assert(((Start.getOffset() < NextLocalOffset &&
1180 Start.getOffset()+Length <= NextLocalOffset) ||
1181 (Start.getOffset() >= CurrentLoadedOffset &&
1182 Start.getOffset()+Length < MaxLoadedOffset)) &&
1183 "Chunk is not valid SLoc address space");
1184 unsigned LocOffs = Loc.getOffset();
1185 unsigned BeginOffs = Start.getOffset();
1186 unsigned EndOffs = BeginOffs + Length;
1187 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1189 *RelativeOffset = LocOffs - BeginOffs;
1202 int *RelativeOffset)
const {
1203 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1204 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1205 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1207 if (LHSLoaded == RHSLoaded) {
1209 *RelativeOffset = RHSOffs - LHSOffs;
1225 bool *Invalid =
nullptr)
const;
1234 bool *Invalid =
nullptr)
const;
1236 bool *Invalid =
nullptr)
const;
1238 bool *Invalid =
nullptr)
const;
1240 bool *Invalid =
nullptr)
const;
1286 bool UseLineDirectives =
true)
const;
1335 unsigned *RelativeOffset =
nullptr)
const {
1336 unsigned Offs = Loc.getOffset();
1337 if (isOffsetInFileID(FID, Offs)) {
1360 bool IsFileEntry,
bool IsFileExit,
1361 bool IsSystemHeader,
bool IsExternCHeader);
1376 return ContentCacheAlloc.getTotalMemory();
1384 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1404 unsigned Line,
unsigned Col)
const;
1415 unsigned Line,
unsigned Col)
const;
1444 unsigned LHSOffset = LHS.getOffset();
1445 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1446 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1447 if (LHSLoaded == RHSLoaded)
1448 return LHSOffset < RHS;
1454 typedef llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>
1459 return FileInfos.find(File) != FileInfos.end();
1471 bool *Invalid =
nullptr)
const {
1472 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1473 return LocalSLocEntryTable[Index];
1481 bool *Invalid =
nullptr)
const {
1482 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1483 if (SLocEntryLoaded[Index])
1484 return LoadedSLocEntryTable[Index];
1485 return loadSLocEntry(Index, Invalid);
1489 bool *Invalid =
nullptr)
const {
1490 if (FID.ID == 0 || FID.ID == -1) {
1491 if (Invalid) *Invalid =
true;
1492 return LocalSLocEntryTable[0];
1494 return getSLocEntryByID(FID.ID, Invalid);
1500 assert(LoadedSLocEntryTable.empty() &&
1501 "Invalidating existing loaded entries");
1502 ExternalSLocEntries = Source;
1511 std::pair<int, unsigned>
1516 return Loc.getOffset() >= CurrentLoadedOffset;
1521 return Loc.getOffset() < NextLocalOffset;
1526 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1552 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1553 const SrcMgr::ContentCache *getFakeContentCacheForRecovery()
const;
1559 bool *Invalid =
nullptr)
const {
1560 assert(ID != -1 &&
"Using FileID sentinel value");
1562 return getLoadedSLocEntryByID(ID, Invalid);
1566 const SrcMgr::SLocEntry &
1567 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1573 SourceLocation createExpansionLocImpl(
const SrcMgr::ExpansionInfo &Expansion,
1576 unsigned LoadedOffset = 0);
1580 inline bool isOffsetInFileID(FileID FID,
unsigned SLocOffset)
const {
1583 if (SLocOffset < Entry.getOffset())
return false;
1590 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1591 return SLocOffset < NextLocalOffset;
1595 return SLocOffset < getSLocEntryByID(FID.ID+1).
getOffset();
1600 FileID getPreviousFileID(FileID FID)
const;
1604 FileID getNextFileID(FileID FID)
const;
1612 SourceLocation IncludePos,
1614 int LoadedID,
unsigned LoadedOffset);
1616 const SrcMgr::ContentCache *
1617 getOrCreateContentCache(
const FileEntry *SourceFile,
1618 bool isSystemFile =
false);
1621 const SrcMgr::ContentCache *
1622 createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
1624 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1625 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1626 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1628 SourceLocation getExpansionLocSlowCase(SourceLocation Loc)
const;
1629 SourceLocation getSpellingLocSlowCase(SourceLocation Loc)
const;
1630 SourceLocation getFileLocSlowCase(SourceLocation Loc)
const;
1632 std::pair<FileID, unsigned>
1633 getDecomposedExpansionLocSlowCase(
const SrcMgr::SLocEntry *E)
const;
1634 std::pair<FileID, unsigned>
1635 getDecomposedSpellingLocSlowCase(
const SrcMgr::SLocEntry *E,
1637 void computeMacroArgsCache(MacroArgsMap *&MacroArgsCache, FileID FID)
const;
1638 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1640 SourceLocation SpellLoc,
1641 SourceLocation ExpansionLoc,
1642 unsigned ExpansionLength)
const;
1648 template<
typename T>
1660 return SM.isBeforeInTranslationUnit(LHS, RHS);
bool hasLineDirectives() const
Return true if this FileID has #line directives in it.
SourceLocation getEnd() const
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
This is a discriminated union of FileInfo and ExpansionInfo.
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Implements support for file system lookup, file system caching, and directory search management...
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
Defines the clang::FileManager interface and associated types.
FileID createFileID(std::unique_ptr< llvm::MemoryBuffer > Buffer, SrcMgr::CharacteristicKind FileCharacter=SrcMgr::C_User, int LoadedID=0, unsigned LoadedOffset=0, SourceLocation IncludeLoc=SourceLocation())
Create a new FileID that represents the specified memory buffer.
SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
bool operator()(SourceRange LHS, SourceRange RHS) const
unsigned getNextLocalOffset() const
unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded...
const ExpansionInfo & getExpansion() const
void setHasLineDirectives()
Set the flag that indicates that this FileID has line table entries associated with it...
SourceRange getExpansionRange(SourceRange Range) const
Given a SourceRange object, return the range of tokens covered by the expansion in the ultimate file...
void setQueryFIDs(FileID LHS, FileID RHS, bool isLFIDBeforeRFID)
Set up a new query.
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID)
Add a line note to the line table for the FileID and offset specified by Loc.
fileinfo_iterator fileinfo_begin() const
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void setCommonLoc(FileID commonFID, unsigned lCommonOffset, unsigned rCommonOffset)
bool isInSystemMacro(SourceLocation loc)
Returns whether Loc is expanded from a macro in a system header.
SourceLocation getIncludeLoc() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
virtual bool ReadSLocEntry(int ID)=0
Read the source location entry with index ID, which will always be less than -1.
void setPreambleFileID(FileID Preamble)
Set the file ID for the precompiled preamble.
size_t getContentCacheSize() const
Return the total amount of physical memory allocated by the ContentCache allocator.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Used to hold and unique data used to represent #line information.
BeforeThanCompare(SourceManager &SM)
bool hasFileInfo(const FileEntry *File) const
bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const
Determines the order of a source location and a source location offset in the "source location addres...
void disableFileContentsOverride(const FileEntry *File)
Disable overridding the contents of a file, previously enabled with overrideFileContents.
void setMainFileID(FileID FID)
Set the file ID for the main source file.
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
std::pair< SourceLocation, SourceLocation > getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
bool isFileOverridden(const FileEntry *File)
Returns true if the file contents have been overridden.
virtual std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID)=0
Retrieve the module import location and name for the given ID, if in fact it was loaded from a module...
unsigned getExpansionColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
std::pair< FileID, unsigned > getDecomposedSpellingLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body. ...
Concrete class used by the front-end to report problems and issues.
unsigned getNumCreatedFIDsForFileID(FileID FID) const
Get the number of FileIDs (files and macros) that were created during preprocessing of FID...
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
Comparison function object.
bool isLoadedSourceLocation(SourceLocation Loc) const
Returns true if Loc came from a PCH/Module.
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
bool operator()(SourceLocation LHS, SourceLocation RHS) const
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
bool isMacroBodyExpansion() const
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
unsigned getPresumedColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
virtual ~ExternalSLocEntrySource()
ID
Defines the set of possible language-specific address spaces.
SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col) const
Get the source location in FID for the given line:col. Returns null location if FID is not a file SLo...
size_t getDataStructureSizes() const
Return the amount of memory used for various side tables and data structures in the SourceManager...
bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const
Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (of...
SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const
If Loc points inside a function macro argument, the returned location will be the macro location in w...
bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const
Returns true if the spelling locations for both SourceLocations are part of the same file buffer...
ModuleBuildStack getModuleBuildStack() const
Retrieve the module build stack.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
bool hasLineTable() const
Determine if the source manager has a line table.
FileManager & getFileManager() const
SourceLocation createMacroArgExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLoc, unsigned TokLength)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
std::pair< SourceLocation, StringRef > getModuleImportLoc(SourceLocation Loc) const
const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a local SLocEntry. This is exposed for indexing.
const char * getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
FileID getPreambleFileID() const
Get the file ID for the precompiled preamble if there is one.
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isWrittenInMainFile(SourceLocation Loc) const
Returns true if the spelling location for the given location is in the main file buffer.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location...
llvm::MemoryBuffer * getBuffer(FileID FID, bool *Invalid=nullptr) const
Represents an unpacked "presumed" location which can be presented to the user.
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
SourceLocation getExpansionLocEnd() const
bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the "source location address space".
unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Return the column # for the specified file position.
void overrideFileContents(const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree)
Override the contents of the given source file by providing an already-allocated buffer.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
Information about a FileID, basically just the logical file that it represents and include stack info...
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getOffset() const
Cached information about one file (either on disk or in the virtual file system). ...
bool isAtEndOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroEnd=nullptr) const
Returns true if the given MacroID location points at the character end of the immediate macro expansi...
bool isLocalFileID(FileID FID) const
Returns true if FID did not come from a PCH/Module.
unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
DiagnosticsEngine & getDiagnostics() const
llvm::MemoryBuffer * getMemoryBufferForFile(const FileEntry *File, bool *Invalid=nullptr)
Retrieve the memory buffer associated with the given file.
const FileEntry * getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
Returns the FileEntry record for the provided SLocEntry.
bool isCacheValid(FileID LHS, FileID RHS) const
Return true if the currently cached values match up with the specified LHS/RHS query.
const FileInfo & getFile() const
ArrayRef< std::pair< std::string, FullSourceLoc > > ModuleBuildStack
The stack used when building modules on demand, which is used to provide a link between the source ma...
SourceLocation getBegin() const
void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)
Push an entry to the module build stack.
FileID getMainFileID() const
Returns the FileID of the main source file.
External source of source location entries.
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
bool isInSLocAddrSpace(SourceLocation Loc, SourceLocation Start, unsigned Length, unsigned *RelativeOffset=nullptr) const
Returns true if Loc is inside the [Start, +Length) chunk of the source location address space...
bool getCachedResult(unsigned LOffset, unsigned ROffset) const
If the cache is valid, compute the result given the specified offsets in the LHS/RHS FileID's...
static ExpansionInfo create(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End)
Return a ExpansionInfo for an expansion.
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const
Return the file characteristic of the specified source location, indicating whether this is a normal ...
unsigned getLineTableFilenameID(StringRef Str)
Return the uniqued ID for the specified filename.
Reads an AST files chain containing the contents of a translation unit.
bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the beginning of the immediate macro expansion...
std::pair< SourceLocation, SourceLocation > getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
const ContentCache * getContentCache() const
fileinfo_iterator fileinfo_end() const
unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Given a SourceLocation, return the spelling line number for the position indicated.
const size_t malloc_bytes
void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)
SourceLocation getExpansionLocStart() const
llvm::DenseMap< const FileEntry *, SrcMgr::ContentCache * >::const_iterator fileinfo_iterator
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
bool userFilesAreVolatile() const
True if non-system source files should be treated as volatile (likely to change while trying to use t...
bool isMacroArgExpansion() const
Holds the cache used by isBeforeInTranslationUnit.
bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, int *RelativeOffset) const
Return true if both LHS and RHS are in the local source location address space or the loaded one...
void setOverridenFilesKeepOriginalName(bool value)
Set true if the SourceManager should report the original file name for contents of files that were ov...
std::pair< int, unsigned > AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize)
Allocate a number of loaded SLocEntries, which will be actually loaded on demand from the external so...
Defines the clang::SourceLocation class and associated facilities.
void setModuleBuildStack(ModuleBuildStack stack)
Set the module build stack.
bool isFunctionMacroExpansion() const
void overrideFileContents(const FileEntry *SourceFile, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Writes an AST file containing the contents of a translation unit.
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const
Set the number of FileIDs (files and macros) that were created during preprocessing of FID...
void PrintStats() const
Print statistics to stderr.
LineTableInfo & getLineTable()
Retrieve the stored line table.
A SourceLocation and its associated SourceManager.
unsigned loaded_sloc_entry_size() const
Get the number of loaded SLocEntries we have.
static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc, SourceLocation ExpansionLoc)
Return a special ExpansionInfo for the expansion of a macro argument into a function-like macro's bod...
bool isInExternCSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in an "extern C" system header.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
std::pair< SourceLocation, SourceLocation > getExpansionLocRange() const
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
const SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a loaded SLocEntry. This is exposed for indexing.
std::pair< FileID, unsigned > getDecomposedIncludedLoc(FileID FID) const
Returns the "included/expanded in" decomposed location of the given FileID.
A trivial tuple used to represent a source range.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
This class handles loading and caching of source files into memory.
BeforeThanCompare(SourceManager &SM)
SourceLocation getSpellingLoc() const
class LLVM_ALIGNAS(8) ContentCache
One instance of this struct is kept for every file loaded or used.
bool isMacroArgExpansion(SourceLocation Loc) const
Tests whether the given source location represents a macro argument's expansion into the function-lik...
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.