1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H |
15 | #define LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H |
16 | |
17 | #include "clang/Basic/SourceLocation.h" |
18 | #include "clang/Basic/SourceManager.h" |
19 | #include "llvm/ADT/StringMap.h" |
20 | #include "llvm/ADT/StringRef.h" |
21 | #include "llvm/Support/Allocator.h" |
22 | #include <cassert> |
23 | #include <map> |
24 | #include <vector> |
25 | |
26 | namespace clang { |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | struct LineEntry { |
33 | |
34 | unsigned FileOffset; |
35 | |
36 | |
37 | unsigned LineNo; |
38 | |
39 | |
40 | |
41 | int FilenameID; |
42 | |
43 | |
44 | SrcMgr::CharacteristicKind FileKind; |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | unsigned IncludeOffset; |
51 | |
52 | static LineEntry get(unsigned Offs, unsigned Line, int Filename, |
53 | SrcMgr::CharacteristicKind FileKind, |
54 | unsigned IncludeOffset) { |
55 | LineEntry E; |
56 | E.FileOffset = Offs; |
57 | E.LineNo = Line; |
58 | E.FilenameID = Filename; |
59 | E.FileKind = FileKind; |
60 | E.IncludeOffset = IncludeOffset; |
61 | return E; |
62 | } |
63 | }; |
64 | |
65 | |
66 | inline bool operator<(const LineEntry &lhs, const LineEntry &rhs) { |
67 | |
68 | return lhs.FileOffset < rhs.FileOffset; |
69 | } |
70 | |
71 | inline bool operator<(const LineEntry &E, unsigned Offset) { |
72 | return E.FileOffset < Offset; |
73 | } |
74 | |
75 | inline bool operator<(unsigned Offset, const LineEntry &E) { |
76 | return Offset < E.FileOffset; |
77 | } |
78 | |
79 | |
80 | class LineTableInfo { |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | llvm::StringMap<unsigned, llvm::BumpPtrAllocator> FilenameIDs; |
88 | std::vector<llvm::StringMapEntry<unsigned>*> FilenamesByID; |
89 | |
90 | |
91 | |
92 | std::map<FileID, std::vector<LineEntry>> LineEntries; |
93 | |
94 | public: |
95 | void clear() { |
96 | FilenameIDs.clear(); |
97 | FilenamesByID.clear(); |
98 | LineEntries.clear(); |
99 | } |
100 | |
101 | unsigned getLineTableFilenameID(StringRef Str); |
102 | |
103 | StringRef getFilename(unsigned ID) const { |
104 | (0) . __assert_fail ("ID < FilenamesByID.size() && \"Invalid FilenameID\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/SourceManagerInternals.h", 104, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ID < FilenamesByID.size() && "Invalid FilenameID"); |
105 | return FilenamesByID[ID]->getKey(); |
106 | } |
107 | |
108 | unsigned getNumFilenames() const { return FilenamesByID.size(); } |
109 | |
110 | void AddLineNote(FileID FID, unsigned Offset, |
111 | unsigned LineNo, int FilenameID, |
112 | unsigned EntryExit, SrcMgr::CharacteristicKind FileKind); |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | const LineEntry *FindNearestLineEntry(FileID FID, unsigned Offset); |
119 | |
120 | |
121 | using iterator = std::map<FileID, std::vector<LineEntry>>::iterator; |
122 | |
123 | iterator begin() { return LineEntries.begin(); } |
124 | iterator end() { return LineEntries.end(); } |
125 | |
126 | |
127 | |
128 | void AddEntry(FileID FID, const std::vector<LineEntry> &Entries); |
129 | }; |
130 | |
131 | } |
132 | |
133 | #endif |
134 | |