File indexing completed on 2026-05-10 08:36:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H
0015 #define LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H
0016
0017 #include "clang/Basic/SourceLocation.h"
0018 #include "clang/Basic/SourceManager.h"
0019 #include "llvm/ADT/StringMap.h"
0020 #include "llvm/ADT/StringRef.h"
0021 #include "llvm/Support/Allocator.h"
0022 #include <cassert>
0023 #include <map>
0024 #include <vector>
0025
0026 namespace clang {
0027
0028
0029
0030
0031
0032 struct LineEntry {
0033
0034 unsigned FileOffset;
0035
0036
0037 unsigned LineNo;
0038
0039
0040
0041 int FilenameID;
0042
0043
0044 SrcMgr::CharacteristicKind FileKind;
0045
0046
0047
0048
0049
0050 unsigned IncludeOffset;
0051
0052 static LineEntry get(unsigned Offs, unsigned Line, int Filename,
0053 SrcMgr::CharacteristicKind FileKind,
0054 unsigned IncludeOffset) {
0055 LineEntry E;
0056 E.FileOffset = Offs;
0057 E.LineNo = Line;
0058 E.FilenameID = Filename;
0059 E.FileKind = FileKind;
0060 E.IncludeOffset = IncludeOffset;
0061 return E;
0062 }
0063 };
0064
0065
0066 inline bool operator<(const LineEntry &lhs, const LineEntry &rhs) {
0067
0068 return lhs.FileOffset < rhs.FileOffset;
0069 }
0070
0071 inline bool operator<(const LineEntry &E, unsigned Offset) {
0072 return E.FileOffset < Offset;
0073 }
0074
0075 inline bool operator<(unsigned Offset, const LineEntry &E) {
0076 return Offset < E.FileOffset;
0077 }
0078
0079
0080 class LineTableInfo {
0081
0082
0083
0084
0085
0086
0087 llvm::StringMap<unsigned, llvm::BumpPtrAllocator> FilenameIDs;
0088 std::vector<llvm::StringMapEntry<unsigned>*> FilenamesByID;
0089
0090
0091
0092 std::map<FileID, std::vector<LineEntry>> LineEntries;
0093
0094 public:
0095 void clear() {
0096 FilenameIDs.clear();
0097 FilenamesByID.clear();
0098 LineEntries.clear();
0099 }
0100
0101 unsigned getLineTableFilenameID(StringRef Str);
0102
0103 StringRef getFilename(unsigned ID) const {
0104 assert(ID < FilenamesByID.size() && "Invalid FilenameID");
0105 return FilenamesByID[ID]->getKey();
0106 }
0107
0108 unsigned getNumFilenames() const { return FilenamesByID.size(); }
0109
0110 void AddLineNote(FileID FID, unsigned Offset,
0111 unsigned LineNo, int FilenameID,
0112 unsigned EntryExit, SrcMgr::CharacteristicKind FileKind);
0113
0114
0115
0116
0117
0118 const LineEntry *FindNearestLineEntry(FileID FID, unsigned Offset);
0119
0120
0121 using iterator = std::map<FileID, std::vector<LineEntry>>::iterator;
0122
0123 iterator begin() { return LineEntries.begin(); }
0124 iterator end() { return LineEntries.end(); }
0125
0126
0127
0128 void AddEntry(FileID FID, const std::vector<LineEntry> &Entries);
0129 };
0130
0131 }
0132
0133 #endif