#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManagerInternals.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Capacity.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <tuple>
#include <utility>
#include <vector>
usingnamespaceclang;
usingnamespaceSrcMgr;
MemoryBuffer;
#define DEBUG_TYPE …
STATISTIC(MaxUsedSLocBytes, "Maximum number of bytes used by source locations "
"(both loaded and local).");
unsigned ContentCache::getSizeBytesMapped() const { … }
llvm::MemoryBuffer::BufferKind ContentCache::getMemoryBufferKind() const { … }
unsigned ContentCache::getSize() const { … }
const char *ContentCache::getInvalidBOM(StringRef BufStr) { … }
std::optional<llvm::MemoryBufferRef>
ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
SourceLocation Loc) const { … }
unsigned LineTableInfo::getLineTableFilenameID(StringRef Name) { … }
void LineTableInfo::AddLineNote(FileID FID, unsigned Offset, unsigned LineNo,
int FilenameID, unsigned EntryExit,
SrcMgr::CharacteristicKind FileKind) { … }
const LineEntry *LineTableInfo::FindNearestLineEntry(FileID FID,
unsigned Offset) { … }
void LineTableInfo::AddEntry(FileID FID,
const std::vector<LineEntry> &Entries) { … }
unsigned SourceManager::getLineTableFilenameID(StringRef Name) { … }
void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo,
int FilenameID, bool IsFileEntry,
bool IsFileExit,
SrcMgr::CharacteristicKind FileKind) { … }
LineTableInfo &SourceManager::getLineTable() { … }
SourceManager::SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr,
bool UserFilesAreVolatile)
: … { … }
SourceManager::~SourceManager() { … }
void SourceManager::clearIDTables() { … }
bool SourceManager::isMainFile(const FileEntry &SourceFile) { … }
void SourceManager::initializeForReplay(const SourceManager &Old) { … }
ContentCache &SourceManager::getOrCreateContentCache(FileEntryRef FileEnt,
bool isSystemFile) { … }
ContentCache &SourceManager::createMemBufferContentCache(
std::unique_ptr<llvm::MemoryBuffer> Buffer) { … }
const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index,
bool *Invalid) const { … }
SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index, bool *Invalid) { … }
std::pair<int, SourceLocation::UIntTy>
SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries,
SourceLocation::UIntTy TotalSize) { … }
llvm::MemoryBufferRef SourceManager::getFakeBufferForRecovery() const { … }
SrcMgr::ContentCache &SourceManager::getFakeContentCacheForRecovery() const { … }
FileID SourceManager::getPreviousFileID(FileID FID) const { … }
FileID SourceManager::getNextFileID(FileID FID) const { … }
FileID SourceManager::createFileID(FileEntryRef SourceFile,
SourceLocation IncludePos,
SrcMgr::CharacteristicKind FileCharacter,
int LoadedID,
SourceLocation::UIntTy LoadedOffset) { … }
FileID SourceManager::createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer,
SrcMgr::CharacteristicKind FileCharacter,
int LoadedID,
SourceLocation::UIntTy LoadedOffset,
SourceLocation IncludeLoc) { … }
FileID SourceManager::createFileID(const llvm::MemoryBufferRef &Buffer,
SrcMgr::CharacteristicKind FileCharacter,
int LoadedID,
SourceLocation::UIntTy LoadedOffset,
SourceLocation IncludeLoc) { … }
FileID
SourceManager::getOrCreateFileID(FileEntryRef SourceFile,
SrcMgr::CharacteristicKind FileCharacter) { … }
FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
SourceLocation IncludePos,
SrcMgr::CharacteristicKind FileCharacter,
int LoadedID,
SourceLocation::UIntTy LoadedOffset) { … }
SourceLocation SourceManager::createMacroArgExpansionLoc(
SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length) { … }
SourceLocation SourceManager::createExpansionLoc(
SourceLocation SpellingLoc, SourceLocation ExpansionLocStart,
SourceLocation ExpansionLocEnd, unsigned Length,
bool ExpansionIsTokenRange, int LoadedID,
SourceLocation::UIntTy LoadedOffset) { … }
SourceLocation SourceManager::createTokenSplitLoc(SourceLocation Spelling,
SourceLocation TokenStart,
SourceLocation TokenEnd) { … }
SourceLocation
SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
unsigned Length, int LoadedID,
SourceLocation::UIntTy LoadedOffset) { … }
std::optional<llvm::MemoryBufferRef>
SourceManager::getMemoryBufferForFileOrNone(FileEntryRef File) { … }
void SourceManager::overrideFileContents(
FileEntryRef SourceFile, std::unique_ptr<llvm::MemoryBuffer> Buffer) { … }
void SourceManager::overrideFileContents(const FileEntry *SourceFile,
FileEntryRef NewFile) { … }
OptionalFileEntryRef
SourceManager::bypassFileContentsOverride(FileEntryRef File) { … }
void SourceManager::setFileIsTransient(FileEntryRef File) { … }
std::optional<StringRef>
SourceManager::getNonBuiltinFilenameForID(FileID FID) const { … }
StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { … }
std::optional<StringRef>
SourceManager::getBufferDataIfLoaded(FileID FID) const { … }
std::optional<StringRef> SourceManager::getBufferDataOrNone(FileID FID) const { … }
FileID SourceManager::getFileIDSlow(SourceLocation::UIntTy SLocOffset) const { … }
FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const { … }
FileID SourceManager::getFileIDLoaded(SourceLocation::UIntTy SLocOffset) const { … }
SourceLocation SourceManager::
getExpansionLocSlowCase(SourceLocation Loc) const { … }
SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const { … }
SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const { … }
std::pair<FileID, unsigned>
SourceManager::getDecomposedExpansionLocSlowCase(
const SrcMgr::SLocEntry *E) const { … }
std::pair<FileID, unsigned>
SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
unsigned Offset) const { … }
SourceLocation SourceManager::getImmediateSpellingLoc(SourceLocation Loc) const{ … }
StringRef SourceManager::getFilename(SourceLocation SpellingLoc) const { … }
CharSourceRange
SourceManager::getImmediateExpansionRange(SourceLocation Loc) const { … }
SourceLocation SourceManager::getTopMacroCallerLoc(SourceLocation Loc) const { … }
CharSourceRange SourceManager::getExpansionRange(SourceLocation Loc) const { … }
bool SourceManager::isMacroArgExpansion(SourceLocation Loc,
SourceLocation *StartLoc) const { … }
bool SourceManager::isMacroBodyExpansion(SourceLocation Loc) const { … }
bool SourceManager::isAtStartOfImmediateMacroExpansion(SourceLocation Loc,
SourceLocation *MacroBegin) const { … }
bool SourceManager::isAtEndOfImmediateMacroExpansion(SourceLocation Loc,
SourceLocation *MacroEnd) const { … }
const char *SourceManager::getCharacterData(SourceLocation SL,
bool *Invalid) const { … }
unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
bool *Invalid) const { … }
template<typename LocType>
static bool isInvalid(LocType Loc, bool *Invalid) { … }
unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc,
bool *Invalid) const { … }
unsigned SourceManager::getExpansionColumnNumber(SourceLocation Loc,
bool *Invalid) const { … }
unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc,
bool *Invalid) const { … }
template <class T>
static constexpr inline T likelyhasbetween(T x, unsigned char m,
unsigned char n) { … }
LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
llvm::BumpPtrAllocator &Alloc) { … }
LineOffsetMapping::LineOffsetMapping(ArrayRef<unsigned> LineOffsets,
llvm::BumpPtrAllocator &Alloc)
: … { … }
unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,
bool *Invalid) const { … }
unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,
bool *Invalid) const { … }
unsigned SourceManager::getExpansionLineNumber(SourceLocation Loc,
bool *Invalid) const { … }
unsigned SourceManager::getPresumedLineNumber(SourceLocation Loc,
bool *Invalid) const { … }
SrcMgr::CharacteristicKind
SourceManager::getFileCharacteristic(SourceLocation Loc) const { … }
StringRef SourceManager::getBufferName(SourceLocation Loc,
bool *Invalid) const { … }
PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,
bool UseLineDirectives) const { … }
bool SourceManager::isInMainFile(SourceLocation Loc) const { … }
unsigned SourceManager::getFileIDSize(FileID FID) const { … }
SourceLocation SourceManager::translateFileLineCol(const FileEntry *SourceFile,
unsigned Line,
unsigned Col) const { … }
FileID SourceManager::translateFile(const FileEntry *SourceFile) const { … }
SourceLocation SourceManager::translateLineCol(FileID FID,
unsigned Line,
unsigned Col) const { … }
void SourceManager::computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
FileID FID) const { … }
void SourceManager::associateFileChunkWithMacroArgExp(
MacroArgsMap &MacroArgsCache,
FileID FID,
SourceLocation SpellLoc,
SourceLocation ExpansionLoc,
unsigned ExpansionLength) const { … }
void SourceManager::updateSlocUsageStats() const { … }
SourceLocation
SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const { … }
std::pair<FileID, unsigned>
SourceManager::getDecomposedIncludedLoc(FileID FID) const { … }
FileID SourceManager::getUniqueLoadedASTFileID(SourceLocation Loc) const { … }
bool SourceManager::isInTheSameTranslationUnitImpl(
const std::pair<FileID, unsigned> &LOffs,
const std::pair<FileID, unsigned> &ROffs) const { … }
static bool
MoveUpTranslationUnitIncludeHierarchy(std::pair<FileID, unsigned> &Loc,
const SourceManager &SM) { … }
InBeforeInTUCacheEntry &SourceManager::getInBeforeInTUCache(FileID LFID,
FileID RFID) const { … }
bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
SourceLocation RHS) const { … }
std::pair<bool, bool> SourceManager::isInTheSameTranslationUnit(
std::pair<FileID, unsigned> &LOffs,
std::pair<FileID, unsigned> &ROffs) const { … }
void SourceManager::PrintStats() const { … }
LLVM_DUMP_METHOD void SourceManager::dump() const { … }
void SourceManager::noteSLocAddressSpaceUsage(
DiagnosticsEngine &Diag, std::optional<unsigned> MaxNotes) const { … }
ExternalSLocEntrySource::~ExternalSLocEntrySource() = default;
SourceManager::MemoryBufferSizes SourceManager::getMemoryBufferSizes() const { … }
size_t SourceManager::getDataStructureSizes() const { … }
SourceManagerForFile::SourceManagerForFile(StringRef FileName,
StringRef Content) { … }