1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_AST_COMMENTLEXER_H |
14 | #define |
15 | |
16 | #include "clang/Basic/Diagnostic.h" |
17 | #include "clang/Basic/SourceManager.h" |
18 | #include "llvm/ADT/SmallString.h" |
19 | #include "llvm/ADT/StringRef.h" |
20 | #include "llvm/Support/Allocator.h" |
21 | #include "llvm/Support/raw_ostream.h" |
22 | |
23 | namespace clang { |
24 | namespace comments { |
25 | |
26 | class Lexer; |
27 | class ; |
28 | struct CommandInfo; |
29 | class CommandTraits; |
30 | |
31 | namespace tok { |
32 | enum { |
33 | , |
34 | , |
35 | , |
36 | unknown_command, |
37 | backslash_command, |
38 | at_command, |
39 | , |
40 | , |
41 | , |
42 | , |
43 | , |
44 | , |
45 | , |
46 | , |
47 | , |
48 | , |
49 | , |
50 | |
51 | }; |
52 | } |
53 | |
54 | |
55 | class { |
56 | friend class Lexer; |
57 | friend class TextTokenRetokenizer; |
58 | |
59 | |
60 | SourceLocation ; |
61 | |
62 | |
63 | tok::TokenKind ; |
64 | |
65 | |
66 | |
67 | unsigned ; |
68 | |
69 | |
70 | const char *; |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | unsigned ; |
78 | |
79 | public: |
80 | SourceLocation () const LLVM_READONLY { return Loc; } |
81 | void setLocation(SourceLocation SL) { Loc = SL; } |
82 | |
83 | SourceLocation getEndLocation() const LLVM_READONLY { |
84 | if (Length == 0 || Length == 1) |
85 | return Loc; |
86 | return Loc.getLocWithOffset(Length - 1); |
87 | } |
88 | |
89 | tok::TokenKind getKind() const LLVM_READONLY { return Kind; } |
90 | void setKind(tok::TokenKind K) { Kind = K; } |
91 | |
92 | bool is(tok::TokenKind K) const LLVM_READONLY { return Kind == K; } |
93 | bool isNot(tok::TokenKind K) const LLVM_READONLY { return Kind != K; } |
94 | |
95 | unsigned getLength() const LLVM_READONLY { return Length; } |
96 | void setLength(unsigned L) { Length = L; } |
97 | |
98 | StringRef getText() const LLVM_READONLY { |
99 | assert(is(tok::text)); |
100 | return StringRef(TextPtr, IntVal); |
101 | } |
102 | |
103 | void setText(StringRef Text) { |
104 | assert(is(tok::text)); |
105 | TextPtr = Text.data(); |
106 | IntVal = Text.size(); |
107 | } |
108 | |
109 | StringRef getUnknownCommandName() const LLVM_READONLY { |
110 | assert(is(tok::unknown_command)); |
111 | return StringRef(TextPtr, IntVal); |
112 | } |
113 | |
114 | void setUnknownCommandName(StringRef Name) { |
115 | assert(is(tok::unknown_command)); |
116 | TextPtr = Name.data(); |
117 | IntVal = Name.size(); |
118 | } |
119 | |
120 | unsigned getCommandID() const LLVM_READONLY { |
121 | assert(is(tok::backslash_command) || is(tok::at_command)); |
122 | return IntVal; |
123 | } |
124 | |
125 | void setCommandID(unsigned ID) { |
126 | assert(is(tok::backslash_command) || is(tok::at_command)); |
127 | IntVal = ID; |
128 | } |
129 | |
130 | unsigned getVerbatimBlockID() const LLVM_READONLY { |
131 | assert(is(tok::verbatim_block_begin) || is(tok::verbatim_block_end)); |
132 | return IntVal; |
133 | } |
134 | |
135 | void setVerbatimBlockID(unsigned ID) { |
136 | assert(is(tok::verbatim_block_begin) || is(tok::verbatim_block_end)); |
137 | IntVal = ID; |
138 | } |
139 | |
140 | StringRef getVerbatimBlockText() const LLVM_READONLY { |
141 | assert(is(tok::verbatim_block_line)); |
142 | return StringRef(TextPtr, IntVal); |
143 | } |
144 | |
145 | void setVerbatimBlockText(StringRef Text) { |
146 | assert(is(tok::verbatim_block_line)); |
147 | TextPtr = Text.data(); |
148 | IntVal = Text.size(); |
149 | } |
150 | |
151 | unsigned getVerbatimLineID() const LLVM_READONLY { |
152 | assert(is(tok::verbatim_line_name)); |
153 | return IntVal; |
154 | } |
155 | |
156 | void setVerbatimLineID(unsigned ID) { |
157 | assert(is(tok::verbatim_line_name)); |
158 | IntVal = ID; |
159 | } |
160 | |
161 | StringRef getVerbatimLineText() const LLVM_READONLY { |
162 | assert(is(tok::verbatim_line_text)); |
163 | return StringRef(TextPtr, IntVal); |
164 | } |
165 | |
166 | void setVerbatimLineText(StringRef Text) { |
167 | assert(is(tok::verbatim_line_text)); |
168 | TextPtr = Text.data(); |
169 | IntVal = Text.size(); |
170 | } |
171 | |
172 | StringRef getHTMLTagStartName() const LLVM_READONLY { |
173 | assert(is(tok::html_start_tag)); |
174 | return StringRef(TextPtr, IntVal); |
175 | } |
176 | |
177 | void setHTMLTagStartName(StringRef Name) { |
178 | assert(is(tok::html_start_tag)); |
179 | TextPtr = Name.data(); |
180 | IntVal = Name.size(); |
181 | } |
182 | |
183 | StringRef getHTMLIdent() const LLVM_READONLY { |
184 | assert(is(tok::html_ident)); |
185 | return StringRef(TextPtr, IntVal); |
186 | } |
187 | |
188 | void setHTMLIdent(StringRef Name) { |
189 | assert(is(tok::html_ident)); |
190 | TextPtr = Name.data(); |
191 | IntVal = Name.size(); |
192 | } |
193 | |
194 | StringRef getHTMLQuotedString() const LLVM_READONLY { |
195 | assert(is(tok::html_quoted_string)); |
196 | return StringRef(TextPtr, IntVal); |
197 | } |
198 | |
199 | void setHTMLQuotedString(StringRef Str) { |
200 | assert(is(tok::html_quoted_string)); |
201 | TextPtr = Str.data(); |
202 | IntVal = Str.size(); |
203 | } |
204 | |
205 | StringRef getHTMLTagEndName() const LLVM_READONLY { |
206 | assert(is(tok::html_end_tag)); |
207 | return StringRef(TextPtr, IntVal); |
208 | } |
209 | |
210 | void setHTMLTagEndName(StringRef Name) { |
211 | assert(is(tok::html_end_tag)); |
212 | TextPtr = Name.data(); |
213 | IntVal = Name.size(); |
214 | } |
215 | |
216 | void dump(const Lexer &L, const SourceManager &SM) const; |
217 | }; |
218 | |
219 | |
220 | class { |
221 | private: |
222 | Lexer(const Lexer &) = delete; |
223 | void operator=(const Lexer &) = delete; |
224 | |
225 | |
226 | |
227 | llvm::BumpPtrAllocator &; |
228 | |
229 | DiagnosticsEngine &; |
230 | |
231 | const CommandTraits &; |
232 | |
233 | const char *const ; |
234 | const char *const ; |
235 | SourceLocation ; |
236 | |
237 | const char *; |
238 | |
239 | |
240 | |
241 | const char *; |
242 | |
243 | enum { |
244 | , |
245 | , |
246 | , |
247 | |
248 | }; |
249 | |
250 | |
251 | LexerCommentState ; |
252 | |
253 | enum { |
254 | |
255 | , |
256 | |
257 | |
258 | |
259 | , |
260 | |
261 | |
262 | |
263 | LS_VerbatimBlockBody, |
264 | |
265 | |
266 | |
267 | , |
268 | |
269 | |
270 | , |
271 | |
272 | |
273 | |
274 | }; |
275 | |
276 | |
277 | LexerState ; |
278 | |
279 | |
280 | |
281 | SmallString<16> VerbatimBlockEndCommandName; |
282 | |
283 | |
284 | |
285 | |
286 | bool ParseCommands; |
287 | |
288 | |
289 | |
290 | StringRef (StringRef Name) const; |
291 | |
292 | |
293 | StringRef (StringRef Name) const; |
294 | |
295 | |
296 | StringRef (StringRef Name) const; |
297 | |
298 | void (Token &Result, const char *TokEnd, |
299 | tok::TokenKind Kind); |
300 | |
301 | void (Token &Result, const char *TokEnd) { |
302 | StringRef Text(BufferPtr, TokEnd - BufferPtr); |
303 | formTokenWithChars(Result, TokEnd, tok::text); |
304 | Result.setText(Text); |
305 | } |
306 | |
307 | SourceLocation (const char *Loc) const { |
308 | (0) . __assert_fail ("Loc >= BufferStart && Loc <= BufferEnd && \"Location out of range for this buffer!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/CommentLexer.h", 309, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Loc >= BufferStart && Loc <= BufferEnd && |
309 | (0) . __assert_fail ("Loc >= BufferStart && Loc <= BufferEnd && \"Location out of range for this buffer!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/CommentLexer.h", 309, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Location out of range for this buffer!"); |
310 | |
311 | const unsigned CharNo = Loc - BufferStart; |
312 | return FileLoc.getLocWithOffset(CharNo); |
313 | } |
314 | |
315 | DiagnosticBuilder (SourceLocation Loc, unsigned DiagID) { |
316 | return Diags.Report(Loc, DiagID); |
317 | } |
318 | |
319 | |
320 | void (); |
321 | |
322 | |
323 | void (Token &T); |
324 | |
325 | void setupAndLexVerbatimBlock(Token &T, const char *TextBegin, char Marker, |
326 | const CommandInfo *Info); |
327 | |
328 | void (Token &T); |
329 | |
330 | void lexVerbatimBlockBody(Token &T); |
331 | |
332 | void setupAndLexVerbatimLine(Token &T, const char *TextBegin, |
333 | const CommandInfo *Info); |
334 | |
335 | void (Token &T); |
336 | |
337 | void (Token &T); |
338 | |
339 | void setupAndLexHTMLStartTag(Token &T); |
340 | |
341 | void (Token &T); |
342 | |
343 | void setupAndLexHTMLEndTag(Token &T); |
344 | |
345 | void (Token &T); |
346 | |
347 | public: |
348 | Lexer(llvm::BumpPtrAllocator &Allocator, DiagnosticsEngine &Diags, |
349 | const CommandTraits &Traits, SourceLocation FileLoc, |
350 | const char *BufferStart, const char *BufferEnd, |
351 | bool ParseCommands = true); |
352 | |
353 | void (Token &T); |
354 | |
355 | StringRef (const Token &Tok, const SourceManager &SourceMgr, |
356 | bool *Invalid = nullptr) const; |
357 | }; |
358 | |
359 | } |
360 | } |
361 | |
362 | #endif |
363 | |
364 | |