@@ -111,7 +111,17 @@ void JSONNodeDumper::Visit(const Decl *D) {
111
111
}
112
112
113
113
void JSONNodeDumper::Visit (const comments::Comment *C,
114
- const comments::FullComment *FC) {}
114
+ const comments::FullComment *FC) {
115
+ if (!C)
116
+ return ;
117
+
118
+ JOS.attribute (" id" , createPointerRepresentation (C));
119
+ JOS.attribute (" kind" , C->getCommentKindName ());
120
+ JOS.attribute (" loc" , createSourceLocation (C->getLocation ()));
121
+ JOS.attribute (" range" , createSourceRange (C->getSourceRange ()));
122
+
123
+ InnerCommentVisitor::visit (C, FC);
124
+ }
115
125
116
126
void JSONNodeDumper::Visit (const TemplateArgument &TA, SourceRange R,
117
127
const Decl *From, StringRef Label) {
@@ -803,3 +813,131 @@ void JSONNodeDumper::VisitGotoStmt(const GotoStmt *GS) {
803
813
void JSONNodeDumper::VisitWhileStmt (const WhileStmt *WS) {
804
814
attributeOnlyIfTrue (" hasVar" , WS->hasVarStorage ());
805
815
}
816
+
817
+ StringRef JSONNodeDumper::getCommentCommandName (unsigned CommandID) const {
818
+ if (Traits)
819
+ return Traits->getCommandInfo (CommandID)->Name ;
820
+ if (const comments::CommandInfo *Info =
821
+ comments::CommandTraits::getBuiltinCommandInfo (CommandID))
822
+ return Info->Name ;
823
+ return " <invalid>" ;
824
+ }
825
+
826
+ void JSONNodeDumper::visitTextComment (const comments::TextComment *C,
827
+ const comments::FullComment *) {
828
+ JOS.attribute (" text" , C->getText ());
829
+ }
830
+
831
+ void JSONNodeDumper::visitInlineCommandComment (
832
+ const comments::InlineCommandComment *C, const comments::FullComment *) {
833
+ JOS.attribute (" name" , getCommentCommandName (C->getCommandID ()));
834
+
835
+ switch (C->getRenderKind ()) {
836
+ case comments::InlineCommandComment::RenderNormal:
837
+ JOS.attribute (" renderKind" , " normal" );
838
+ break ;
839
+ case comments::InlineCommandComment::RenderBold:
840
+ JOS.attribute (" renderKind" , " bold" );
841
+ break ;
842
+ case comments::InlineCommandComment::RenderEmphasized:
843
+ JOS.attribute (" renderKind" , " emphasized" );
844
+ break ;
845
+ case comments::InlineCommandComment::RenderMonospaced:
846
+ JOS.attribute (" renderKind" , " monospaced" );
847
+ break ;
848
+ }
849
+
850
+ llvm::json::Array Args;
851
+ for (unsigned I = 0 , E = C->getNumArgs (); I < E; ++I)
852
+ Args.push_back (C->getArgText (I));
853
+
854
+ if (!Args.empty ())
855
+ JOS.attribute (" args" , std::move (Args));
856
+ }
857
+
858
+ void JSONNodeDumper::visitHTMLStartTagComment (
859
+ const comments::HTMLStartTagComment *C, const comments::FullComment *) {
860
+ JOS.attribute (" name" , C->getTagName ());
861
+ attributeOnlyIfTrue (" selfClosing" , C->isSelfClosing ());
862
+ attributeOnlyIfTrue (" malformed" , C->isMalformed ());
863
+
864
+ llvm::json::Array Attrs;
865
+ for (unsigned I = 0 , E = C->getNumAttrs (); I < E; ++I)
866
+ Attrs.push_back (
867
+ {{" name" , C->getAttr (I).Name }, {" value" , C->getAttr (I).Value }});
868
+
869
+ if (!Attrs.empty ())
870
+ JOS.attribute (" attrs" , std::move (Attrs));
871
+ }
872
+
873
+ void JSONNodeDumper::visitHTMLEndTagComment (
874
+ const comments::HTMLEndTagComment *C, const comments::FullComment *) {
875
+ JOS.attribute (" name" , C->getTagName ());
876
+ }
877
+
878
+ void JSONNodeDumper::visitBlockCommandComment (
879
+ const comments::BlockCommandComment *C, const comments::FullComment *) {
880
+ JOS.attribute (" name" , getCommentCommandName (C->getCommandID ()));
881
+
882
+ llvm::json::Array Args;
883
+ for (unsigned I = 0 , E = C->getNumArgs (); I < E; ++I)
884
+ Args.push_back (C->getArgText (I));
885
+
886
+ if (!Args.empty ())
887
+ JOS.attribute (" args" , std::move (Args));
888
+ }
889
+
890
+ void JSONNodeDumper::visitParamCommandComment (
891
+ const comments::ParamCommandComment *C, const comments::FullComment *FC) {
892
+ switch (C->getDirection ()) {
893
+ case comments::ParamCommandComment::In:
894
+ JOS.attribute (" direction" , " in" );
895
+ break ;
896
+ case comments::ParamCommandComment::Out:
897
+ JOS.attribute (" direction" , " out" );
898
+ break ;
899
+ case comments::ParamCommandComment::InOut:
900
+ JOS.attribute (" direction" , " in,out" );
901
+ break ;
902
+ }
903
+ attributeOnlyIfTrue (" explicit" , C->isDirectionExplicit ());
904
+
905
+ if (C->hasParamName ())
906
+ JOS.attribute (" param" , C->isParamIndexValid () ? C->getParamName (FC)
907
+ : C->getParamNameAsWritten ());
908
+
909
+ if (C->isParamIndexValid () && !C->isVarArgParam ())
910
+ JOS.attribute (" paramIdx" , C->getParamIndex ());
911
+ }
912
+
913
+ void JSONNodeDumper::visitTParamCommandComment (
914
+ const comments::TParamCommandComment *C, const comments::FullComment *FC) {
915
+ if (C->hasParamName ())
916
+ JOS.attribute (" param" , C->isPositionValid () ? C->getParamName (FC)
917
+ : C->getParamNameAsWritten ());
918
+ if (C->isPositionValid ()) {
919
+ llvm::json::Array Positions;
920
+ for (unsigned I = 0 , E = C->getDepth (); I < E; ++I)
921
+ Positions.push_back (C->getIndex (I));
922
+
923
+ if (!Positions.empty ())
924
+ JOS.attribute (" positions" , std::move (Positions));
925
+ }
926
+ }
927
+
928
+ void JSONNodeDumper::visitVerbatimBlockComment (
929
+ const comments::VerbatimBlockComment *C, const comments::FullComment *) {
930
+ JOS.attribute (" name" , getCommentCommandName (C->getCommandID ()));
931
+ JOS.attribute (" closeName" , C->getCloseName ());
932
+ }
933
+
934
+ void JSONNodeDumper::visitVerbatimBlockLineComment (
935
+ const comments::VerbatimBlockLineComment *C,
936
+ const comments::FullComment *) {
937
+ JOS.attribute (" text" , C->getText ());
938
+ }
939
+
940
+ void JSONNodeDumper::visitVerbatimLineComment (
941
+ const comments::VerbatimLineComment *C, const comments::FullComment *) {
942
+ JOS.attribute (" text" , C->getText ());
943
+ }
0 commit comments