|
10 | 10 | //
|
11 | 11 |
|
12 | 12 | #include "Serialize.h"
|
| 13 | +#include "CommentVisitor.h" |
13 | 14 | #include "BitcodeWriter.h"
|
14 | 15 | #ifdef _MSC_VER
|
15 | 16 | #pragma warning(push)
|
@@ -71,129 +72,6 @@ llvm::SmallString<128> getInfoRelativePath(const Decl *D) {
|
71 | 72 | return getInfoRelativePath(Namespaces);
|
72 | 73 | }
|
73 | 74 |
|
74 |
| -class ClangDocCommentVisitor |
75 |
| - : public ConstCommentVisitor<ClangDocCommentVisitor> { |
76 |
| -public: |
77 |
| - ClangDocCommentVisitor(CommentInfo &CI) : CurrentCI(CI) {} |
78 |
| - |
79 |
| - void parseComment(const comments::Comment *C); |
80 |
| - |
81 |
| - void visitTextComment(const TextComment *C); |
82 |
| - void visitInlineCommandComment(const InlineCommandComment *C); |
83 |
| - void visitHTMLStartTagComment(const HTMLStartTagComment *C); |
84 |
| - void visitHTMLEndTagComment(const HTMLEndTagComment *C); |
85 |
| - void visitBlockCommandComment(const BlockCommandComment *C); |
86 |
| - void visitParamCommandComment(const ParamCommandComment *C); |
87 |
| - void visitTParamCommandComment(const TParamCommandComment *C); |
88 |
| - void visitVerbatimBlockComment(const VerbatimBlockComment *C); |
89 |
| - void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C); |
90 |
| - void visitVerbatimLineComment(const VerbatimLineComment *C); |
91 |
| - |
92 |
| -private: |
93 |
| - std::string getCommandName(unsigned CommandID) const; |
94 |
| - bool isWhitespaceOnly(StringRef S) const; |
95 |
| - |
96 |
| - CommentInfo &CurrentCI; |
97 |
| -}; |
98 |
| - |
99 |
| -void ClangDocCommentVisitor::parseComment(const comments::Comment *C) { |
100 |
| - CurrentCI.Kind = C->getCommentKindName(); |
101 |
| - ConstCommentVisitor<ClangDocCommentVisitor>::visit(C); |
102 |
| - for (comments::Comment *Child : |
103 |
| - llvm::make_range(C->child_begin(), C->child_end())) { |
104 |
| - CurrentCI.Children.emplace_back(std::make_unique<CommentInfo>()); |
105 |
| - ClangDocCommentVisitor Visitor(*CurrentCI.Children.back()); |
106 |
| - Visitor.parseComment(Child); |
107 |
| - } |
108 |
| -} |
109 |
| - |
110 |
| -void |
111 |
| -ClangDocCommentVisitor:: |
112 |
| -visitTextComment( |
113 |
| - TextComment const* c) |
114 |
| -{ |
115 |
| - // Trim leading whitespace |
116 |
| - auto s = c->getText().ltrim(); |
117 |
| - if(! isWhitespaceOnly(s)) |
118 |
| - CurrentCI.Text = s; |
119 |
| -} |
120 |
| - |
121 |
| -void ClangDocCommentVisitor::visitInlineCommandComment( |
122 |
| - const InlineCommandComment *C) { |
123 |
| - CurrentCI.Name = getCommandName(C->getCommandID()); |
124 |
| - for (unsigned I = 0, E = C->getNumArgs(); I != E; ++I) |
125 |
| - CurrentCI.Args.push_back(C->getArgText(I)); |
126 |
| -} |
127 |
| - |
128 |
| -void ClangDocCommentVisitor::visitHTMLStartTagComment( |
129 |
| - const HTMLStartTagComment *C) { |
130 |
| - CurrentCI.Name = C->getTagName(); |
131 |
| - CurrentCI.SelfClosing = C->isSelfClosing(); |
132 |
| - for (unsigned I = 0, E = C->getNumAttrs(); I < E; ++I) { |
133 |
| - const HTMLStartTagComment::Attribute &Attr = C->getAttr(I); |
134 |
| - CurrentCI.AttrKeys.push_back(Attr.Name); |
135 |
| - CurrentCI.AttrValues.push_back(Attr.Value); |
136 |
| - } |
137 |
| -} |
138 |
| - |
139 |
| -void ClangDocCommentVisitor::visitHTMLEndTagComment( |
140 |
| - const HTMLEndTagComment *C) { |
141 |
| - CurrentCI.Name = C->getTagName(); |
142 |
| - CurrentCI.SelfClosing = true; |
143 |
| -} |
144 |
| - |
145 |
| -void ClangDocCommentVisitor::visitBlockCommandComment( |
146 |
| - const BlockCommandComment *C) { |
147 |
| - CurrentCI.Name = getCommandName(C->getCommandID()); |
148 |
| - for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I) |
149 |
| - CurrentCI.Args.push_back(C->getArgText(I)); |
150 |
| -} |
151 |
| - |
152 |
| -void ClangDocCommentVisitor::visitParamCommandComment( |
153 |
| - const ParamCommandComment *C) { |
154 |
| - CurrentCI.Direction = |
155 |
| - ParamCommandComment::getDirectionAsString(C->getDirection()); |
156 |
| - CurrentCI.Explicit = C->isDirectionExplicit(); |
157 |
| - if (C->hasParamName()) |
158 |
| - CurrentCI.ParamName = C->getParamNameAsWritten(); |
159 |
| -} |
160 |
| - |
161 |
| -void ClangDocCommentVisitor::visitTParamCommandComment( |
162 |
| - const TParamCommandComment *C) { |
163 |
| - if (C->hasParamName()) |
164 |
| - CurrentCI.ParamName = C->getParamNameAsWritten(); |
165 |
| -} |
166 |
| - |
167 |
| -void ClangDocCommentVisitor::visitVerbatimBlockComment( |
168 |
| - const VerbatimBlockComment *C) { |
169 |
| - CurrentCI.Name = getCommandName(C->getCommandID()); |
170 |
| - CurrentCI.CloseName = C->getCloseName(); |
171 |
| -} |
172 |
| - |
173 |
| -void ClangDocCommentVisitor::visitVerbatimBlockLineComment( |
174 |
| - const VerbatimBlockLineComment *C) { |
175 |
| - if (!isWhitespaceOnly(C->getText())) |
176 |
| - CurrentCI.Text = C->getText(); |
177 |
| -} |
178 |
| - |
179 |
| -void ClangDocCommentVisitor::visitVerbatimLineComment( |
180 |
| - const VerbatimLineComment *C) { |
181 |
| - if (!isWhitespaceOnly(C->getText())) |
182 |
| - CurrentCI.Text = C->getText(); |
183 |
| -} |
184 |
| - |
185 |
| -bool ClangDocCommentVisitor::isWhitespaceOnly(llvm::StringRef S) const { |
186 |
| - return llvm::all_of(S, isspace); |
187 |
| -} |
188 |
| - |
189 |
| -std::string ClangDocCommentVisitor::getCommandName(unsigned CommandID) const { |
190 |
| - const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID); |
191 |
| - if (Info) |
192 |
| - return Info->Name; |
193 |
| - // TODO: Add parsing for \file command. |
194 |
| - return "<not a builtin command>"; |
195 |
| -} |
196 |
| - |
197 | 75 | // Serializing functions.
|
198 | 76 |
|
199 | 77 | std::string getSourceCode(const Decl *D, const SourceRange &R) {
|
@@ -226,9 +104,13 @@ std::string serialize(std::unique_ptr<Info> &I) {
|
226 | 104 | }
|
227 | 105 | }
|
228 | 106 |
|
229 |
| -static void parseFullComment(const FullComment *C, CommentInfo &CI) { |
230 |
| - ClangDocCommentVisitor Visitor(CI); |
231 |
| - Visitor.parseComment(C); |
| 107 | +void |
| 108 | +parseFullComment( |
| 109 | + FullComment const* c, |
| 110 | + CommentInfo& ci) |
| 111 | +{ |
| 112 | + CommentVisitor Visitor(ci); |
| 113 | + Visitor.parseComment(c); |
232 | 114 | }
|
233 | 115 |
|
234 | 116 | static SymbolID getUSRForDecl(const Decl *D) {
|
|
0 commit comments