@@ -49,41 +49,22 @@ RawComment* Parser::WalkRawComment(const clang::RawComment* RC)
4949}
5050
5151static InlineCommandComment::RenderKind
52- ConvertRenderKind (clang::comments::InlineCommandComment::RenderKind Kind)
52+ ConvertRenderKind (std::string Kind)
5353{
5454 using namespace clang ::comments;
55- switch (Kind)
56- {
57- case clang::comments::InlineCommandComment::RenderNormal:
58- return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderNormal;
59- case clang::comments::InlineCommandComment::RenderBold:
60- return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderBold;
61- case clang::comments::InlineCommandComment::RenderMonospaced:
62- return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderMonospaced;
63- case clang::comments::InlineCommandComment::RenderEmphasized:
64- return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderEmphasized;
65- case clang::comments::InlineCommandComment::RenderAnchor:
66- return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderAnchor;
67- }
55+ if (Kind == " b" )
56+ return AST::InlineCommandComment::RenderKind::RenderBold;
57+ else if (Kind == " c" )
58+ return AST::InlineCommandComment::RenderKind::RenderMonospaced;
59+ else if (Kind == " a" )
60+ return AST::InlineCommandComment::RenderKind::RenderAnchor;
61+ else if (Kind == " e" )
62+ return AST::InlineCommandComment::RenderKind::RenderEmphasized;
63+ else
64+ return AST::InlineCommandComment::RenderKind::RenderNormal;
6865 llvm_unreachable (" Unknown render kind" );
6966}
7067
71- static ParamCommandComment::PassDirection
72- ConvertParamPassDirection (clang::comments::ParamCommandComment::PassDirection Dir)
73- {
74- using namespace clang ::comments;
75- switch (Dir)
76- {
77- case clang::comments::ParamCommandComment::In:
78- return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::In;
79- case clang::comments::ParamCommandComment::Out:
80- return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::Out;
81- case clang::comments::ParamCommandComment::InOut:
82- return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::InOut;
83- }
84- llvm_unreachable (" Unknown parameter pass direction" );
85- }
86-
8768static void HandleInlineContent (const clang::comments::InlineContentComment* CK,
8869 InlineContentComment* IC)
8970{
@@ -102,158 +83,120 @@ static void HandleBlockCommand(const clang::comments::BlockCommandComment* CK,
10283 }
10384}
10485
105- static Comment* ConvertCommentBlock (clang::comments::Comment* C)
86+ static Comment* ConvertCommentBlock (clang::comments::Comment* C, clang::CompilerInstance* CI )
10687{
10788 using namespace clang ;
10889 using clang::comments::Comment;
10990
11091 // This needs to have an underscore else we get an ICE under VS2012.
111- CppSharp::CppParser::AST::Comment* _Comment = 0 ;
112-
113- switch (C-> getCommentKind ( ))
92+ CppSharp::CppParser::AST::Comment* _Comment = nullptr ;
93+ auto kind = C-> getCommentKind ();
94+ if ( auto CK = dyn_cast< const comments::FullComment>(C ))
11495 {
115- case Comment::FullCommentKind:
116- {
117- auto CK = cast<clang::comments::FullComment>(C);
118- auto FC = new FullComment ();
119- _Comment = FC;
120- for (auto I = CK->child_begin (), E = CK->child_end (); I != E; ++I)
121- {
122- auto Content = ConvertCommentBlock (*I);
123- FC->Blocks .push_back (static_cast <BlockContentComment*>(Content));
124- }
125- break ;
126- }
127- case Comment::BlockCommandCommentKind:
128- {
129- auto CK = cast<const clang::comments::BlockCommandComment>(C);
130- auto BC = new BlockCommandComment ();
131- _Comment = BC;
132- HandleBlockCommand (CK, BC);
133- BC->paragraphComment = static_cast <ParagraphComment*>(ConvertCommentBlock (CK->getParagraph ()));
134- break ;
135- }
136- case Comment::ParamCommandCommentKind:
137- {
138- auto CK = cast<clang::comments::ParamCommandComment>(C);
139- auto PC = new ParamCommandComment ();
140- _Comment = PC;
141- HandleBlockCommand (CK, PC);
142- PC->direction = ConvertParamPassDirection (CK->getDirection ());
143- if (CK->isParamIndexValid () && !CK->isVarArgParam ())
144- PC->paramIndex = CK->getParamIndex ();
145- PC->paragraphComment = static_cast <ParagraphComment*>(ConvertCommentBlock (CK->getParagraph ()));
146- break ;
147- }
148- case Comment::TParamCommandCommentKind:
149- {
150- auto CK = cast<clang::comments::TParamCommandComment>(C);
151- _Comment = new TParamCommandComment ();
152- auto TC = new TParamCommandComment ();
153- _Comment = TC;
154- HandleBlockCommand (CK, TC);
155- if (CK->isPositionValid ())
156- for (unsigned I = 0 , E = CK->getDepth (); I != E; ++I)
157- TC->Position .push_back (CK->getIndex (I));
158- TC->paragraphComment = static_cast <ParagraphComment*>(ConvertCommentBlock (CK->getParagraph ()));
159- break ;
160- }
161- case Comment::VerbatimBlockCommentKind:
162- {
163- auto CK = cast<clang::comments::VerbatimBlockComment>(C);
164- auto VB = new VerbatimBlockComment ();
165- _Comment = VB;
166- for (auto I = CK->child_begin (), E = CK->child_end (); I != E; ++I)
167- {
168- auto Line = ConvertCommentBlock (*I);
169- VB->Lines .push_back (static_cast <VerbatimBlockLineComment*>(Line));
170- }
171- break ;
172- }
173- case Comment::VerbatimLineCommentKind:
174- {
175- auto CK = cast<clang::comments::VerbatimLineComment>(C);
176- auto VL = new VerbatimLineComment ();
177- _Comment = VL;
178- VL->text = CK->getText ().str ();
179- break ;
180- }
181- case Comment::ParagraphCommentKind:
182- {
183- auto CK = cast<clang::comments::ParagraphComment>(C);
184- auto PC = new ParagraphComment ();
185- _Comment = PC;
186- for (auto I = CK->child_begin (), E = CK->child_end (); I != E; ++I)
187- {
188- auto Content = ConvertCommentBlock (*I);
189- PC->Content .push_back (static_cast <InlineContentComment*>(Content));
190- }
191- PC->isWhitespace = CK->isWhitespace ();
192- break ;
193- }
194- case Comment::HTMLStartTagCommentKind:
195- {
196- auto CK = cast<clang::comments::HTMLStartTagComment>(C);
197- auto TC = new HTMLStartTagComment ();
198- _Comment = TC;
199- HandleInlineContent (CK, TC);
200- TC->tagName = CK->getTagName ().str ();
201- for (unsigned I = 0 , E = CK->getNumAttrs (); I != E; ++I)
202- {
203- auto A = CK->getAttr (I);
204- auto Attr = HTMLStartTagComment::Attribute ();
205- Attr.name = A.Name .str ();
206- Attr.value = A.Value .str ();
207- TC->Attributes .push_back (Attr);
208- }
209- break ;
210- }
211- case Comment::HTMLEndTagCommentKind:
212- {
213- auto CK = cast<clang::comments::HTMLEndTagComment>(C);
214- auto TC = new HTMLEndTagComment ();
215- _Comment = TC;
216- HandleInlineContent (CK, TC);
217- TC->tagName = CK->getTagName ().str ();
218- break ;
219- }
220- case Comment::TextCommentKind:
221- {
222- auto CK = cast<clang::comments::TextComment>(C);
223- auto TC = new TextComment ();
224- _Comment = TC;
225- HandleInlineContent (CK, TC);
226- TC->text = CK->getText ().str ();
227- break ;
228- }
229- case Comment::InlineCommandCommentKind:
96+ auto FC = new FullComment ();
97+ _Comment = FC;
98+ for (auto I = CK->child_begin (), E = CK->child_end (); I != E; ++I)
99+ FC->Blocks .push_back (static_cast <BlockContentComment*>(ConvertCommentBlock (*I, CI)));
100+ }
101+ else if (auto CK = dyn_cast<const comments::BlockCommandComment>(C))
102+ {
103+ auto BC = new BlockCommandComment ();
104+ _Comment = BC;
105+ HandleBlockCommand (CK, BC);
106+ BC->paragraphComment = static_cast <ParagraphComment*>(ConvertCommentBlock (CK->getParagraph (), CI));
107+ }
108+ else if (auto CK = dyn_cast<const comments::ParamCommandComment>(C))
109+ {
110+ auto PC = new ParamCommandComment ();
111+ _Comment = PC;
112+ HandleBlockCommand (CK, PC);
113+ if (CK->isParamIndexValid () && !CK->isVarArgParam ())
114+ PC->paramIndex = CK->getParamIndex ();
115+ PC->paragraphComment = static_cast <ParagraphComment*>(ConvertCommentBlock (CK->getParagraph (), CI));
116+ }
117+ else if (auto CK = dyn_cast<const comments::TParamCommandComment>(C))
118+ {
119+ auto TC = new TParamCommandComment ();
120+ _Comment = TC;
121+ HandleBlockCommand (CK, TC);
122+ if (CK->isPositionValid ())
123+ for (unsigned I = 0 , E = CK->getDepth (); I != E; ++I)
124+ TC->Position .push_back (CK->getIndex (I));
125+ TC->paragraphComment = static_cast <ParagraphComment*>(ConvertCommentBlock (CK->getParagraph (), CI));
126+ }
127+ else if (auto CK = dyn_cast<const comments::VerbatimBlockComment>(C))
128+ {
129+ auto VB = new VerbatimBlockComment ();
130+ _Comment = VB;
131+ for (auto I = CK->child_begin (), E = CK->child_end (); I != E; ++I)
132+ VB->Lines .push_back (static_cast <VerbatimBlockLineComment*>(ConvertCommentBlock (*I, CI)));
133+ }
134+ else if (auto CK = dyn_cast<const comments::VerbatimLineComment>(C))
135+ {
136+ auto VL = new VerbatimLineComment ();
137+ _Comment = VL;
138+ VL->text = CK->getText ().str ();
139+ }
140+ else if (auto CK = dyn_cast<const comments::ParagraphComment>(C))
141+ {
142+ auto PC = new ParagraphComment ();
143+ _Comment = PC;
144+ for (auto I = CK->child_begin (), E = CK->child_end (); I != E; ++I)
145+ PC->Content .push_back (static_cast <InlineContentComment*>(ConvertCommentBlock (*I, CI)));
146+ PC->isWhitespace = CK->isWhitespace ();
147+ }
148+ else if (auto CK = dyn_cast<const comments::HTMLStartTagComment>(C))
149+ {
150+ auto TC = new HTMLStartTagComment ();
151+ _Comment = TC;
152+ HandleInlineContent (CK, TC);
153+ TC->tagName = CK->getTagName ().str ();
154+ for (unsigned I = 0 , E = CK->getNumAttrs (); I != E; ++I)
230155 {
231- auto CK = cast<clang::comments::InlineCommandComment>(C);
232- auto IC = new InlineCommandComment ();
233- _Comment = IC;
234- HandleInlineContent (CK, IC);
235- IC->commandId = CK->getCommandID ();
236- IC->commentRenderKind = ConvertRenderKind (CK->getRenderKind ());
237- for (unsigned I = 0 , E = CK->getNumArgs (); I != E; ++I)
238- {
239- auto Arg = InlineCommandComment::Argument ();
240- Arg.text = CK->getArgText (I).str ();
241- IC->Arguments .push_back (Arg);
242- }
243- break ;
156+ auto A = CK->getAttr (I);
157+ auto Attr = HTMLStartTagComment::Attribute ();
158+ Attr.name = A.Name .str ();
159+ Attr.value = A.Value .str ();
160+ TC->Attributes .push_back (Attr);
244161 }
245- case Comment::VerbatimBlockLineCommentKind:
162+ }
163+ else if (auto CK = dyn_cast<const comments::HTMLEndTagComment>(C))
164+ {
165+ auto TC = new HTMLEndTagComment ();
166+ _Comment = TC;
167+ HandleInlineContent (CK, TC);
168+ TC->tagName = CK->getTagName ().str ();
169+ }
170+ else if (auto CK = dyn_cast<const comments::TextComment>(C))
171+ {
172+ auto TC = new TextComment ();
173+ _Comment = TC;
174+ HandleInlineContent (CK, TC);
175+ TC->text = CK->getText ().str ();
176+ }
177+ else if (auto CK = dyn_cast<const comments::InlineCommandComment>(C))
178+ {
179+ auto IC = new InlineCommandComment ();
180+ _Comment = IC;
181+ HandleInlineContent (CK, IC);
182+ IC->commandId = CK->getCommandID ();
183+
184+ IC->commentRenderKind = ConvertRenderKind (CK->getCommandName (CI->getASTContext ().getCommentCommandTraits ()).str ());
185+ for (unsigned I = 0 , E = CK->getNumArgs (); I != E; ++I)
246186 {
247- auto CK = cast<clang::comments::VerbatimBlockLineComment>(C);
248- auto VL = new VerbatimBlockLineComment ();
249- _Comment = VL;
250- VL->text = CK->getText ().str ();
251- break ;
187+ auto Arg = InlineCommandComment::Argument ();
188+ Arg.text = CK->getArgText (I).str ();
189+ IC->Arguments .push_back (Arg);
252190 }
253- case Comment::NoCommentKind: return nullptr ;
254- default :
255- llvm_unreachable (" Unknown comment kind" );
256191 }
192+ else if (auto CK = dyn_cast<const comments::VerbatimBlockLineComment>(C))
193+ {
194+ auto VL = new VerbatimBlockLineComment ();
195+ _Comment = VL;
196+ VL->text = CK->getText ().str ();
197+ }
198+ else
199+ llvm_unreachable (" Unknown comment kind" );
257200
258201 assert (_Comment && " Invalid comment instance" );
259202 return _Comment;
@@ -272,7 +215,7 @@ void Parser::HandleComments(const clang::Decl* D, Declaration* Decl)
272215
273216 if (clang::comments::FullComment* FC = RC->parse (c->getASTContext (), &c->getPreprocessor (), D))
274217 {
275- auto CB = static_cast <FullComment*>(ConvertCommentBlock (FC));
218+ auto CB = static_cast <FullComment*>(ConvertCommentBlock (FC, c. get () ));
276219 RawComment->fullCommentBlock = CB;
277220 }
278221}
0 commit comments