35 #ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H 36 #define LLVM_CLANG_BASIC_SOURCEMANAGER_H 40 #include "llvm/ADT/ArrayRef.h" 41 #include "llvm/ADT/BitVector.h" 42 #include "llvm/ADT/DenseMap.h" 43 #include "llvm/ADT/DenseSet.h" 44 #include "llvm/ADT/IntrusiveRefCntPtr.h" 45 #include "llvm/ADT/PointerIntPair.h" 46 #include "llvm/ADT/SmallVector.h" 47 #include "llvm/ADT/StringRef.h" 48 #include "llvm/Support/Allocator.h" 49 #include "llvm/Support/Compiler.h" 50 #include "llvm/Support/MemoryBuffer.h" 63 class DiagnosticsEngine;
109 mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2> Buffer;
130 unsigned *SourceLineCache =
nullptr;
135 unsigned NumLines = 0;
156 : Buffer(nullptr,
false), OrigEntry(Ent), ContentsEntry(contentEnt),
163 : Buffer(nullptr,
false), BufferOverridden(
false), IsSystemFile(
false),
168 assert(RHS.Buffer.getPointer() ==
nullptr &&
170 "Passed ContentCache object cannot own a buffer.");
191 bool *Invalid =
nullptr)
const;
199 unsigned getSize()
const;
205 unsigned getSizeBytesMapped()
const;
209 llvm::MemoryBuffer::BufferKind getMemoryBufferKind()
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;
332 return EndLoc.
isInvalid() ? getExpansionLocStart() : EndLoc;
336 return std::make_pair(getExpansionLocStart(), getExpansionLocEnd());
341 return getExpansionLocStart().isValid() &&
346 return getExpansionLocStart().isValid() &&
351 return getExpansionLocStart().isValid() &&
352 getExpansionLocStart() != getExpansionLocEnd();
404 unsigned IsExpansion : 1;
416 bool isFile()
const {
return !isExpansion(); }
419 assert(isFile() &&
"Not a file SLocEntry!");
424 assert(isExpansion() &&
"Not a macro expansion SLocEntry!");
429 assert(!(Offset & (1 << 31)) &&
"Offset is too large");
432 E.IsExpansion =
false;
438 assert(!(Offset & (1 << 31)) &&
"Offset is too large");
441 E.IsExpansion =
true;
459 virtual bool ReadSLocEntry(
int ID) = 0;
464 virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(
int ID) = 0;
475 FileID LQueryFID, RQueryFID;
480 bool IsLQFIDBeforeRQFID;
491 unsigned LCommonOffset, RCommonOffset;
499 return LQueryFID == LHS && RQueryFID == RHS;
507 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
508 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
515 if (LOffset == ROffset)
516 return IsLQFIDBeforeRQFID;
518 return LOffset < ROffset;
526 IsLQFIDBeforeRQFID = isLFIDBeforeRFID;
530 LQueryFID = RQueryFID =
FileID();
531 IsLQFIDBeforeRQFID =
false;
535 unsigned rCommonOffset) {
536 CommonFID = commonFID;
537 LCommonOffset = lCommonOffset;
538 RCommonOffset = rCommonOffset;
565 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
573 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
577 bool OverridenFilesKeepOriginalName =
true;
581 bool UserFilesAreVolatile;
586 bool FilesAreTransient =
false;
588 struct OverriddenFilesInfoTy {
591 llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
599 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
601 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
602 if (!OverriddenFilesInfo)
603 OverriddenFilesInfo.reset(
new OverriddenFilesInfoTy);
604 return *OverriddenFilesInfo;
611 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
628 unsigned NextLocalOffset;
634 unsigned CurrentLoadedOffset;
638 static const unsigned MaxLoadedOffset = 1U << 31U;
644 llvm::BitVector SLocEntryLoaded;
653 mutable FileID LastFileIDLookup;
662 mutable FileID LastLineNoFileIDQuery;
664 mutable unsigned LastLineNoFilePos;
665 mutable unsigned LastLineNoResult;
674 mutable unsigned NumLinearScans = 0;
675 mutable unsigned NumBinaryProbes = 0;
682 mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap;
685 using IsBeforeInTUCacheKey = std::pair<FileID, FileID>;
689 using InBeforeInTUCache =
690 llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>;
693 mutable InBeforeInTUCache IBTUCache;
701 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
703 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
707 using MacroArgsMap = std::map<unsigned, SourceLocation>;
709 mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
723 bool UserFilesAreVolatile =
false);
728 void clearIDTables();
742 OverridenFilesKeepOriginalName = value;
751 return StoredModuleBuildStack;
756 StoredModuleBuildStack.clear();
757 StoredModuleBuildStack.append(stack.begin(), stack.end());
762 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
779 assert(PreambleFileID.
isInvalid() &&
"PreambleFileID already set!");
780 PreambleFileID = Preamble;
796 int LoadedID = 0,
unsigned LoadedOffset = 0) {
798 getOrCreateContentCache(SourceFile,
isSystem(FileCharacter));
799 assert(IR &&
"getOrCreateContentCache() cannot return NULL");
800 return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset);
809 int LoadedID = 0,
unsigned LoadedOffset = 0,
812 createMemBufferContentCache(Buffer.release(),
false),
813 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
824 int LoadedID = 0,
unsigned LoadedOffset = 0,
826 return createFileID(createMemBufferContentCache(Buffer,
true),
827 IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
834 FileID ID = translateFile(SourceFile);
855 unsigned LoadedOffset = 0);
861 llvm::MemoryBuffer *getMemoryBufferForFile(
const FileEntry *File,
862 bool *Invalid =
nullptr);
874 void overrideFileContents(
const FileEntry *SourceFile,
875 llvm::MemoryBuffer *Buffer,
bool DoNotFree);
877 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
878 overrideFileContents(SourceFile, Buffer.release(),
false);
887 void overrideFileContents(
const FileEntry *SourceFile,
892 if (OverriddenFilesInfo) {
893 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
895 if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
896 OverriddenFilesInfo->OverriddenFiles.end())
906 void disableFileContentsOverride(
const FileEntry *File);
909 void setFileIsTransient(
const FileEntry *SourceFile);
914 FilesAreTransient = Transient;
926 bool *Invalid =
nullptr)
const {
927 bool MyInvalid =
false;
929 if (MyInvalid || !Entry.
isFile()) {
933 return getFakeBufferForRecovery();
941 bool MyInvalid =
false;
943 if (MyInvalid || !Entry.
isFile()) {
947 return getFakeBufferForRecovery();
957 bool MyInvalid =
false;
959 if (MyInvalid || !Entry.
isFile())
982 StringRef getBufferData(
FileID FID,
bool *Invalid =
nullptr)
const;
987 bool Invalid =
false;
989 if (Invalid || !Entry.
isFile())
992 return Entry.
getFile().NumCreatedFIDs;
998 bool Invalid =
false;
1000 if (Invalid || !Entry.
isFile())
1003 assert(Entry.
getFile().NumCreatedFIDs == 0 &&
"Already set!");
1018 unsigned SLocOffset = SpellingLoc.getOffset();
1021 if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
1022 return LastFileIDLookup;
1024 return getFileIDSlow(SLocOffset);
1029 if (
const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc)))
1030 return F->getName();
1037 bool Invalid =
false;
1039 if (Invalid || !Entry.
isFile())
1042 unsigned FileOffset = Entry.
getOffset();
1043 return SourceLocation::getFileLoc(FileOffset);
1049 bool Invalid =
false;
1051 if (Invalid || !Entry.
isFile())
1054 unsigned FileOffset = Entry.
getOffset();
1055 return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID));
1061 bool Invalid =
false;
1063 if (Invalid || !Entry.
isFile())
1072 std::pair<SourceLocation, StringRef>
1074 FileID FID = getFileID(Loc);
1090 return getExpansionLocSlowCase(Loc);
1098 return getFileLocSlowCase(Loc);
1105 std::pair<SourceLocation,SourceLocation>
1110 std::pair<SourceLocation,SourceLocation>
1117 getExpansionRange(Range.
getEnd()).second);
1129 return getSpellingLocSlowCase(Loc);
1145 FileID FID = getFileID(Loc);
1146 bool Invalid =
false;
1149 return std::make_pair(
FileID(), 0);
1150 return std::make_pair(FID, Loc.getOffset()-E.
getOffset());
1157 std::pair<FileID, unsigned>
1159 FileID FID = getFileID(Loc);
1160 bool Invalid =
false;
1163 return std::make_pair(
FileID(), 0);
1167 return std::make_pair(FID, Offset);
1169 return getDecomposedExpansionLocSlowCase(E);
1176 std::pair<FileID, unsigned>
1178 FileID FID = getFileID(Loc);
1179 bool Invalid =
false;
1182 return std::make_pair(
FileID(), 0);
1186 return std::make_pair(FID, Offset);
1187 return getDecomposedSpellingLocSlowCase(E, Offset);
1192 std::pair<FileID, unsigned> getDecomposedIncludedLoc(
FileID FID)
const;
1199 return getDecomposedLoc(SpellingLoc).second;
1245 unsigned *RelativeOffset =
nullptr)
const {
1246 assert(((Start.getOffset() < NextLocalOffset &&
1247 Start.getOffset()+Length <= NextLocalOffset) ||
1248 (Start.getOffset() >= CurrentLoadedOffset &&
1249 Start.getOffset()+Length < MaxLoadedOffset)) &&
1250 "Chunk is not valid SLoc address space");
1251 unsigned LocOffs = Loc.getOffset();
1252 unsigned BeginOffs = Start.getOffset();
1253 unsigned EndOffs = BeginOffs + Length;
1254 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1256 *RelativeOffset = LocOffs - BeginOffs;
1269 int *RelativeOffset)
const {
1270 unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1271 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1272 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1274 if (LHSLoaded == RHSLoaded) {
1276 *RelativeOffset = RHSOffs - LHSOffs;
1292 bool *Invalid =
nullptr)
const;
1300 unsigned getColumnNumber(
FileID FID,
unsigned FilePos,
1301 bool *Invalid =
nullptr)
const;
1303 bool *Invalid =
nullptr)
const;
1305 bool *Invalid =
nullptr)
const;
1307 bool *Invalid =
nullptr)
const;
1315 unsigned getLineNumber(
FileID FID,
unsigned FilePos,
bool *Invalid =
nullptr)
const;
1316 unsigned getSpellingLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1317 unsigned getExpansionLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1318 unsigned getPresumedLineNumber(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1325 StringRef getBufferName(
SourceLocation Loc,
bool *Invalid =
nullptr)
const;
1353 bool UseLineDirectives =
true)
const;
1369 return getFileID(Loc1) == getFileID(Loc2);
1377 return getFileID(Loc) == getMainFileID();
1382 return isSystem(getFileCharacteristic(Loc));
1392 return loc.
isMacroID() && isInSystemHeader(getSpellingLoc(loc));
1396 unsigned getFileIDSize(
FileID FID)
const;
1402 unsigned *RelativeOffset =
nullptr)
const {
1403 unsigned Offs = Loc.getOffset();
1404 if (isOffsetInFileID(FID, Offs)) {
1406 *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
1418 unsigned getLineTableFilenameID(StringRef Str);
1424 void AddLineNote(
SourceLocation Loc,
unsigned LineNo,
int FilenameID,
1425 bool IsFileEntry,
bool IsFileExit,
1441 return ContentCacheAlloc.getTotalMemory();
1449 : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
1458 size_t getDataStructureSizes()
const;
1469 unsigned Line,
unsigned Col)
const;
1480 unsigned Line,
unsigned Col)
const;
1505 std::pair<bool, bool>
1506 isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs,
1507 std::pair<FileID, unsigned> &ROffs)
const;
1512 return isBeforeInSLocAddrSpace(LHS, RHS.getOffset());
1520 unsigned LHSOffset = LHS.getOffset();
1521 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1522 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1523 if (LHSLoaded == RHSLoaded)
1524 return LHSOffset < RHS;
1532 return Location == Start || Location == End ||
1533 (isBeforeInTranslationUnit(Start, Location) &&
1534 isBeforeInTranslationUnit(Location, End));
1539 llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator;
1544 return FileInfos.find(File) != FileInfos.end();
1548 void PrintStats()
const;
1557 bool *Invalid =
nullptr)
const {
1558 assert(Index < LocalSLocEntryTable.size() &&
"Invalid index");
1559 return LocalSLocEntryTable[Index];
1567 bool *Invalid =
nullptr)
const {
1568 assert(Index < LoadedSLocEntryTable.size() &&
"Invalid index");
1569 if (SLocEntryLoaded[Index])
1570 return LoadedSLocEntryTable[Index];
1571 return loadSLocEntry(Index, Invalid);
1575 bool *Invalid =
nullptr)
const {
1576 if (FID.ID == 0 || FID.ID == -1) {
1577 if (Invalid) *Invalid =
true;
1578 return LocalSLocEntryTable[0];
1580 return getSLocEntryByID(FID.ID, Invalid);
1586 assert(LoadedSLocEntryTable.empty() &&
1587 "Invalidating existing loaded entries");
1588 ExternalSLocEntries = Source;
1597 std::pair<int, unsigned>
1598 AllocateLoadedSLocEntries(
unsigned NumSLocEntries,
unsigned TotalSize);
1602 return Loc.getOffset() >= CurrentLoadedOffset;
1607 return Loc.getOffset() < NextLocalOffset;
1612 assert(FID.ID != -1 &&
"Using FileID sentinel value");
1618 return !isLoadedFileID(FID);
1629 if (isMacroArgExpansion(Loc))
1630 return getImmediateSpellingLoc(Loc);
1634 return getImmediateExpansionRange(Loc).first;
1641 llvm::MemoryBuffer *getFakeBufferForRecovery()
const;
1648 bool *Invalid =
nullptr)
const {
1649 assert(ID != -1 &&
"Using FileID sentinel value");
1651 return getLoadedSLocEntryByID(ID, Invalid);
1652 return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid);
1656 getLoadedSLocEntryByID(
int ID,
bool *Invalid =
nullptr)
const {
1657 return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
1665 unsigned LoadedOffset = 0);
1669 inline bool isOffsetInFileID(
FileID FID,
unsigned SLocOffset)
const {
1672 if (SLocOffset < Entry.
getOffset())
return false;
1679 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1680 return SLocOffset < NextLocalOffset;
1684 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();
1703 int LoadedID,
unsigned LoadedOffset);
1706 getOrCreateContentCache(
const FileEntry *SourceFile,
1707 bool isSystemFile =
false);
1711 createMemBufferContentCache(llvm::MemoryBuffer *Buf,
bool DoNotFree);
1713 FileID getFileIDSlow(
unsigned SLocOffset)
const;
1714 FileID getFileIDLocal(
unsigned SLocOffset)
const;
1715 FileID getFileIDLoaded(
unsigned SLocOffset)
const;
1721 std::pair<FileID, unsigned>
1723 std::pair<FileID, unsigned>
1726 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
FileID FID)
const;
1727 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1731 unsigned ExpansionLength)
const;
1735 template<
typename T>
1747 return SM.isBeforeInTranslationUnit(LHS, RHS);
1766 #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.
SourceRange getExpansionRange(SourceRange Range) const
Given a SourceRange object, return the range of tokens covered by the expansion in the ultimate file...
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
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...
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.
Comparison function object.
DiagnosticsEngine & getDiagnostics() const
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
SourceLocation getIncludeLoc() const
bool isMacroArgExpansion() const
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.
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
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). ...
std::pair< SourceLocation, SourceLocation > getExpansionLocRange() const
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.
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 isInExternCSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in an "extern C" system header.
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
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
static ExpansionInfo create(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End)
Return a ExpansionInfo for an expansion.
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...
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...
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.
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