Skip to content

Commit b567c6c

Browse files
committed
add new comment changes
1 parent adc5742 commit b567c6c

File tree

3 files changed

+105
-35
lines changed

3 files changed

+105
-35
lines changed

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,112 @@ static json::Object serializeLocation(const Location &Loc,
4242
return LocationObj;
4343
}
4444

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
5147
Object Obj = Object();
52-
json::Value Child = Object();
5348

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();
5951

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
6952
json::Value ChildArr = Array();
7053
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)
7356
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.");
77151
}
78152

79153
static void serializeCommonAttributes(const Info &I, json::Object &Obj,
@@ -110,10 +184,7 @@ static void serializeCommonAttributes(const Info &I, json::Object &Obj,
110184

111185
static void serializeReference(const Reference &Ref, Object &ReferenceObj,
112186
SmallString<64> CurrentDirectory) {
113-
SmallString<64> Path = Ref.getRelativeFilePath(CurrentDirectory);
114-
sys::path::append(Path, Ref.getFileBaseName() + ".json");
115-
sys::path::native(Path, sys::path::Style::posix);
116-
ReferenceObj["Link"] = Path;
187+
ReferenceObj["Path"] = Ref.Path;
117188
ReferenceObj["Name"] = Ref.Name;
118189
ReferenceObj["QualName"] = Ref.QualName;
119190
ReferenceObj["USR"] = toHex(toStringRef(Ref.USR));

clang-tools-extra/test/clang-doc/json/class.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ struct MyClass {
146146
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
147147
// CHECK-NEXT: },
148148
// CHECK: "IsStatic": true,
149-
// CHECK: "IsStatic": false,
150149
// CHECK: "Name": "getConst",
151150
// CHECK: "ReturnType": {
152151
// CHECK-NEXT: "IsBuiltIn": false,
@@ -163,8 +162,8 @@ struct MyClass {
163162
// CHECK-NEXT: ],
164163
// CHECK-NEXT: "Records": [
165164
// CHECK-NEXT: {
166-
// CHECK-NEXT: "Link": "NestedClass.json",
167165
// CHECK-NEXT: "Name": "NestedClass",
166+
// CHECK-NEXT: "Path": "GlobalNamespace/MyClass",
168167
// CHECK-NEXT: "QualName": "NestedClass",
169168
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
170169
// CHECK-NEXT: }

clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ TEST(JSONGeneratorTest, emitRecordJSON) {
118118
],
119119
"Parents": [
120120
{
121-
"Link": "F.json",
122121
"Name": "F",
122+
"Path": "",
123123
"QualName": "",
124124
"USR": "0000000000000000000000000000000000000000"
125125
}
@@ -147,8 +147,8 @@ TEST(JSONGeneratorTest, emitRecordJSON) {
147147
],
148148
"Records": [
149149
{
150-
"Link": "ChildStruct.json",
151150
"Name": "ChildStruct",
151+
"Path": "path/to/A/r",
152152
"QualName": "path::to::A::r::ChildStruct",
153153
"USR": "0000000000000000000000000000000000000000"
154154
}
@@ -162,8 +162,8 @@ TEST(JSONGeneratorTest, emitRecordJSON) {
162162
"USR": "0000000000000000000000000000000000000000",
163163
"VirtualParents": [
164164
{
165-
"Link": "G.json",
166165
"Name": "G",
166+
"Path": "path/to/G",
167167
"QualName": "path::to::G::G",
168168
"USR": "0000000000000000000000000000000000000000"
169169
}

0 commit comments

Comments
 (0)