@@ -42,38 +42,112 @@ static json::Object serializeLocation(const Location &Loc,
42
42
return LocationObj;
43
43
}
44
44
45
- static json::Value serializeComment (const CommentInfo &Comment) {
46
- assert ((Comment.Kind == " BlockCommandComment" ||
47
- Comment.Kind == " FullComment" || Comment.Kind == " ParagraphComment" ||
48
- Comment.Kind == " TextComment" ) &&
49
- " Unknown Comment type in CommentInfo." );
50
-
45
+ static json::Value serializeComment (const CommentInfo &I) {
46
+ // taken from PR #142273
51
47
Object Obj = Object ();
52
- json::Value Child = Object ();
53
48
54
- // TextComment has no children, so return it.
55
- if (Comment.Kind == " TextComment" ) {
56
- Obj[" TextComment" ] = Comment.Text ;
57
- return Obj;
58
- }
49
+ json::Value ChildVal = Object ();
50
+ Object &Child = *ChildVal.getAsObject ();
59
51
60
- // BlockCommandComment needs to generate a Command key.
61
- if (Comment.Kind == " BlockCommandComment" )
62
- Child.getAsObject ()->insert ({" Command" , Comment.Name });
63
-
64
- // Use the same handling for everything else.
65
- // Only valid for:
66
- // - BlockCommandComment
67
- // - FullComment
68
- // - ParagraphComment
69
52
json::Value ChildArr = Array ();
70
53
auto &CARef = *ChildArr.getAsArray ();
71
- CARef.reserve (Comment .Children .size ());
72
- for (const auto &C : Comment .Children )
54
+ CARef.reserve (I .Children .size ());
55
+ for (const auto &C : I .Children )
73
56
CARef.emplace_back (serializeComment (*C));
74
- Child.getAsObject ()->insert ({" Children" , ChildArr});
75
- Obj.insert ({Comment.Kind , Child});
76
- return Obj;
57
+
58
+ switch (I.Kind ) {
59
+ case CommentKind::CK_TextComment: {
60
+ Obj.insert ({commentKindToString (I.Kind ), I.Text });
61
+ return Obj;
62
+ }
63
+
64
+ case CommentKind::CK_BlockCommandComment: {
65
+ Child.insert ({" Command" , I.Name });
66
+ Child.insert ({" Children" , ChildArr});
67
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
68
+ return Obj;
69
+ }
70
+
71
+ case CommentKind::CK_InlineCommandComment: {
72
+ json::Value ArgsArr = Array ();
73
+ auto &ARef = *ArgsArr.getAsArray ();
74
+ ARef.reserve (I.Args .size ());
75
+ for (const auto &Arg : I.Args )
76
+ ARef.emplace_back (Arg);
77
+ Child.insert ({" Command" , I.Name });
78
+ Child.insert ({" Args" , ArgsArr});
79
+ Child.insert ({" Children" , ChildArr});
80
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
81
+ return Obj;
82
+ }
83
+
84
+ case CommentKind::CK_ParamCommandComment:
85
+ case CommentKind::CK_TParamCommandComment: {
86
+ Child.insert ({" ParamName" , I.ParamName });
87
+ Child.insert ({" Direction" , I.Direction });
88
+ Child.insert ({" Explicit" , I.Explicit });
89
+ Child.insert ({" Children" , ChildArr});
90
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
91
+ return Obj;
92
+ }
93
+
94
+ case CommentKind::CK_VerbatimBlockComment: {
95
+ Child.insert ({" Text" , I.Text });
96
+ if (!I.CloseName .empty ())
97
+ Child.insert ({" CloseName" , I.CloseName });
98
+ Child.insert ({" Children" , ChildArr});
99
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
100
+ return Obj;
101
+ }
102
+
103
+ case CommentKind::CK_VerbatimBlockLineComment:
104
+ case CommentKind::CK_VerbatimLineComment: {
105
+ Child.insert ({" Text" , I.Text });
106
+ Child.insert ({" Children" , ChildArr});
107
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
108
+ return Obj;
109
+ }
110
+
111
+ case CommentKind::CK_HTMLStartTagComment: {
112
+ json::Value AttrKeysArray = json::Array ();
113
+ json::Value AttrValuesArray = json::Array ();
114
+ auto &KeyArr = *AttrKeysArray.getAsArray ();
115
+ auto &ValArr = *AttrValuesArray.getAsArray ();
116
+ KeyArr.reserve (I.AttrKeys .size ());
117
+ ValArr.reserve (I.AttrValues .size ());
118
+ for (const auto &K : I.AttrKeys )
119
+ KeyArr.emplace_back (K);
120
+ for (const auto &V : I.AttrValues )
121
+ ValArr.emplace_back (V);
122
+ Child.insert ({" Name" , I.Name });
123
+ Child.insert ({" SelfClosing" , I.SelfClosing });
124
+ Child.insert ({" AttrKeys" , AttrKeysArray});
125
+ Child.insert ({" AttrValues" , AttrValuesArray});
126
+ Child.insert ({" Children" , ChildArr});
127
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
128
+ return Obj;
129
+ }
130
+
131
+ case CommentKind::CK_HTMLEndTagComment: {
132
+ Child.insert ({" Name" , I.Name });
133
+ Child.insert ({" Children" , ChildArr});
134
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
135
+ return Obj;
136
+ }
137
+
138
+ case CommentKind::CK_FullComment:
139
+ case CommentKind::CK_ParagraphComment: {
140
+ Child.insert ({" Children" , ChildArr});
141
+ Obj.insert ({commentKindToString (I.Kind ), ChildVal});
142
+ return Obj;
143
+ }
144
+
145
+ case CommentKind::CK_Unknown: {
146
+ Obj.insert ({commentKindToString (I.Kind ), I.Text });
147
+ return Obj;
148
+ }
149
+ }
150
+ llvm_unreachable (" Unknown comment kind encountered." );
77
151
}
78
152
79
153
static void serializeCommonAttributes (const Info &I, json::Object &Obj,
0 commit comments