1 | //===--- CommentParser.h - Doxygen comment parser ---------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file defines the Doxygen comment parser. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_CLANG_AST_COMMENTPARSER_H |
14 | #define |
15 | |
16 | #include "clang/AST/Comment.h" |
17 | #include "clang/AST/CommentLexer.h" |
18 | #include "clang/AST/CommentSema.h" |
19 | #include "clang/Basic/Diagnostic.h" |
20 | #include "llvm/Support/Allocator.h" |
21 | |
22 | namespace clang { |
23 | class SourceManager; |
24 | |
25 | namespace comments { |
26 | class CommandTraits; |
27 | |
28 | /// Doxygen comment parser. |
29 | class { |
30 | (const Parser &) = delete; |
31 | void (const Parser &) = delete; |
32 | |
33 | friend class TextTokenRetokenizer; |
34 | |
35 | Lexer &; |
36 | |
37 | Sema &; |
38 | |
39 | /// Allocator for anything that goes into AST nodes. |
40 | llvm::BumpPtrAllocator &; |
41 | |
42 | /// Source manager for the comment being parsed. |
43 | const SourceManager &; |
44 | |
45 | DiagnosticsEngine &; |
46 | |
47 | DiagnosticBuilder (SourceLocation Loc, unsigned DiagID) { |
48 | return Diags.Report(Loc, DiagID); |
49 | } |
50 | |
51 | const CommandTraits &; |
52 | |
53 | /// Current lookahead token. We can safely assume that all tokens are from |
54 | /// a single source file. |
55 | Token ; |
56 | |
57 | /// A stack of additional lookahead tokens. |
58 | SmallVector<Token, 8> ; |
59 | |
60 | void () { |
61 | if (MoreLATokens.empty()) |
62 | L.lex(T&: Tok); |
63 | else |
64 | Tok = MoreLATokens.pop_back_val(); |
65 | } |
66 | |
67 | void (const Token &OldTok) { |
68 | MoreLATokens.push_back(Elt: Tok); |
69 | Tok = OldTok; |
70 | } |
71 | |
72 | void (ArrayRef<Token> Toks) { |
73 | if (Toks.empty()) |
74 | return; |
75 | |
76 | MoreLATokens.push_back(Elt: Tok); |
77 | MoreLATokens.append(in_start: Toks.rbegin(), in_end: std::prev(x: Toks.rend())); |
78 | |
79 | Tok = Toks[0]; |
80 | } |
81 | |
82 | bool isTokBlockCommand() { |
83 | return (Tok.is(K: tok::backslash_command) || Tok.is(K: tok::at_command)) && |
84 | Traits.getCommandInfo(CommandID: Tok.getCommandID())->IsBlockCommand; |
85 | } |
86 | |
87 | public: |
88 | (Lexer &L, Sema &S, llvm::BumpPtrAllocator &Allocator, |
89 | const SourceManager &SourceMgr, DiagnosticsEngine &Diags, |
90 | const CommandTraits &Traits); |
91 | |
92 | /// Parse arguments for \\param command. |
93 | void parseParamCommandArgs(ParamCommandComment *PC, |
94 | TextTokenRetokenizer &Retokenizer); |
95 | |
96 | /// Parse arguments for \\tparam command. |
97 | void parseTParamCommandArgs(TParamCommandComment *TPC, |
98 | TextTokenRetokenizer &Retokenizer); |
99 | |
100 | ArrayRef<Comment::Argument> |
101 | parseCommandArgs(TextTokenRetokenizer &Retokenizer, unsigned NumArgs); |
102 | |
103 | BlockCommandComment *parseBlockCommand(); |
104 | InlineCommandComment *parseInlineCommand(); |
105 | |
106 | HTMLStartTagComment *(); |
107 | HTMLEndTagComment *(); |
108 | |
109 | BlockContentComment *parseParagraphOrBlockCommand(); |
110 | |
111 | VerbatimBlockComment *(); |
112 | VerbatimLineComment *(); |
113 | BlockContentComment *(); |
114 | FullComment *(); |
115 | }; |
116 | |
117 | } // end namespace comments |
118 | } // end namespace clang |
119 | |
120 | #endif |
121 | |
122 | |