1 #include "clang/AST/JSONNodeDumper.h"
2 #include "clang/Lex/Lexer.h"
3 #include "llvm/ADT/StringSwitch.h"
4 
5 using namespace clang;
6 
7 void JSONNodeDumper::addPreviousDeclaration(const Decl *D) {
8   switch (D->getKind()) {
9 #define DECL(DERIVED, BASE)                                                    \
10   case Decl::DERIVED:                                                          \
11     return writePreviousDeclImpl(cast<DERIVED##Decl>(D));
12 #define ABSTRACT_DECL(DECL)
13 #include "clang/AST/DeclNodes.inc"
14 #undef ABSTRACT_DECL
15 #undef DECL
16   }
17   llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
18 }
19 
20 void JSONNodeDumper::Visit(const Attr *A) {
21   const char *AttrName = nullptr;
22   switch (A->getKind()) {
23 #define ATTR(X)                                                                \
24   case attr::X:                                                                \
25     AttrName = #X"Attr";                                                       \
26     break;
27 #include "clang/Basic/AttrList.inc"
28 #undef ATTR
29   }
30   JOS.attribute("id", createPointerRepresentation(A));
31   JOS.attribute("kind", AttrName);
32   JOS.attributeObject("range", [A, this] { writeSourceRange(A->getRange()); });
33   attributeOnlyIfTrue("inherited", A->isInherited());
34   attributeOnlyIfTrue("implicit", A->isImplicit());
35 
36   // FIXME: it would be useful for us to output the spelling kind as well as
37   // the actual spelling. This would allow us to distinguish between the
38   // various attribute syntaxes, but we don't currently track that information
39   // within the AST.
40   //JOS.attribute("spelling", A->getSpelling());
41 
42   InnerAttrVisitor::Visit(A);
43 }
44 
45 void JSONNodeDumper::Visit(const Stmt *S) {
46   if (!S)
47     return;
48 
49   JOS.attribute("id", createPointerRepresentation(S));
50   JOS.attribute("kind", S->getStmtClassName());
51   JOS.attributeObject("range",
52                       [S, this] { writeSourceRange(S->getSourceRange()); });
53 
54   if (const auto *E = dyn_cast<Expr>(S)) {
55     JOS.attribute("type", createQualType(E->getType()));
56     const char *Category = nullptr;
57     switch (E->getValueKind()) {
58     case VK_LValue: Category = "lvalue"; break;
59     case VK_XValue: Category = "xvalue"; break;
60     case VK_RValue: Category = "rvalue"; break;
61     }
62     JOS.attribute("valueCategory", Category);
63   }
64   InnerStmtVisitor::Visit(S);
65 }
66 
67 void JSONNodeDumper::Visit(const Type *T) {
68   JOS.attribute("id", createPointerRepresentation(T));
69 
70   if (!T)
71     return;
72 
73   JOS.attribute("kind", (llvm::Twine(T->getTypeClassName()) + "Type").str());
74   JOS.attribute("type", createQualType(QualType(T, 0), /*Desugar*/ false));
75   attributeOnlyIfTrue("isDependent", T->isDependentType());
76   attributeOnlyIfTrue("isInstantiationDependent",
77                       T->isInstantiationDependentType());
78   attributeOnlyIfTrue("isVariablyModified", T->isVariablyModifiedType());
79   attributeOnlyIfTrue("containsUnexpandedPack",
80                       T->containsUnexpandedParameterPack());
81   attributeOnlyIfTrue("isImported", T->isFromAST());
82   InnerTypeVisitor::Visit(T);
83 }
84 
85 void JSONNodeDumper::Visit(QualType T) {
86   JOS.attribute("id", createPointerRepresentation(T.getAsOpaquePtr()));
87   JOS.attribute("kind", "QualType");
88   JOS.attribute("type", createQualType(T));
89   JOS.attribute("qualifiers", T.split().Quals.getAsString());
90 }
91 
92 void JSONNodeDumper::Visit(const Decl *D) {
93   JOS.attribute("id", createPointerRepresentation(D));
94 
95   if (!D)
96     return;
97 
98   JOS.attribute("kind", (llvm::Twine(D->getDeclKindName()) + "Decl").str());
99   JOS.attributeObject("loc",
100                       [D, this] { writeSourceLocation(D->getLocation()); });
101   JOS.attributeObject("range",
102                       [D, this] { writeSourceRange(D->getSourceRange()); });
103   attributeOnlyIfTrue("isImplicit", D->isImplicit());
104   attributeOnlyIfTrue("isInvalid", D->isInvalidDecl());
105 
106   if (D->isUsed())
107     JOS.attribute("isUsed", true);
108   else if (D->isThisDeclarationReferenced())
109     JOS.attribute("isReferenced", true);
110 
111   if (const auto *ND = dyn_cast<NamedDecl>(D))
112     attributeOnlyIfTrue("isHidden", ND->isHidden());
113 
114   if (D->getLexicalDeclContext() != D->getDeclContext()) {
115     // Because of multiple inheritance, a DeclContext pointer does not produce
116     // the same pointer representation as a Decl pointer that references the
117     // same AST Node.
118     const auto *ParentDeclContextDecl = dyn_cast<Decl>(D->getDeclContext());
119     JOS.attribute("parentDeclContextId",
120                   createPointerRepresentation(ParentDeclContextDecl));
121   }
122 
123   addPreviousDeclaration(D);
124   InnerDeclVisitor::Visit(D);
125 }
126 
127 void JSONNodeDumper::Visit(const comments::Comment *C,
128                            const comments::FullComment *FC) {
129   if (!C)
130     return;
131 
132   JOS.attribute("id", createPointerRepresentation(C));
133   JOS.attribute("kind", C->getCommentKindName());
134   JOS.attributeObject("loc",
135                       [C, this] { writeSourceLocation(C->getLocation()); });
136   JOS.attributeObject("range",
137                       [C, this] { writeSourceRange(C->getSourceRange()); });
138 
139   InnerCommentVisitor::visit(C, FC);
140 }
141 
142 void JSONNodeDumper::Visit(const TemplateArgument &TA, SourceRange R,
143                            const Decl *From, StringRef Label) {
144   JOS.attribute("kind", "TemplateArgument");
145   if (R.isValid())
146     JOS.attributeObject("range", [R, this] { writeSourceRange(R); });
147 
148   if (From)
149     JOS.attribute(Label.empty() ? "fromDecl" : Label, createBareDeclRef(From));
150 
151   InnerTemplateArgVisitor::Visit(TA);
152 }
153 
154 void JSONNodeDumper::Visit(const CXXCtorInitializer *Init) {
155   JOS.attribute("kind", "CXXCtorInitializer");
156   if (Init->isAnyMemberInitializer())
157     JOS.attribute("anyInit", createBareDeclRef(Init->getAnyMember()));
158   else if (Init->isBaseInitializer())
159     JOS.attribute("baseInit",
160                   createQualType(QualType(Init->getBaseClass(), 0)));
161   else if (Init->isDelegatingInitializer())
162     JOS.attribute("delegatingInit",
163                   createQualType(Init->getTypeSourceInfo()->getType()));
164   else
165     llvm_unreachable("Unknown initializer type");
166 }
167 
168 void JSONNodeDumper::Visit(const OMPClause *C) {}
169 
170 void JSONNodeDumper::Visit(const BlockDecl::Capture &C) {
171   JOS.attribute("kind", "Capture");
172   attributeOnlyIfTrue("byref", C.isByRef());
173   attributeOnlyIfTrue("nested", C.isNested());
174   if (C.getVariable())
175     JOS.attribute("var", createBareDeclRef(C.getVariable()));
176 }
177 
178 void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
179   JOS.attribute("associationKind", A.getTypeSourceInfo() ? "case" : "default");
180   attributeOnlyIfTrue("selected", A.isSelected());
181 }
182 
183 void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc,
184                                              bool IsSpelling) {
185   PresumedLoc Presumed = SM.getPresumedLoc(Loc);
186   unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc)
187                                    : SM.getExpansionLineNumber(Loc);
188   if (Presumed.isValid()) {
189     if (LastLocFilename != Presumed.getFilename()) {
190       JOS.attribute("file", Presumed.getFilename());
191       JOS.attribute("line", ActualLine);
192     } else if (LastLocLine != ActualLine)
193       JOS.attribute("line", ActualLine);
194 
195     unsigned PresumedLine = Presumed.getLine();
196     if (ActualLine != PresumedLine && LastLocPresumedLine != PresumedLine)
197       JOS.attribute("presumedLine", PresumedLine);
198 
199     JOS.attribute("col", Presumed.getColumn());
200     JOS.attribute("tokLen",
201                   Lexer::MeasureTokenLength(Loc, SM, Ctx.getLangOpts()));
202     LastLocFilename = Presumed.getFilename();
203     LastLocPresumedLine = PresumedLine;
204     LastLocLine = ActualLine;
205   }
206 }
207 
208 void JSONNodeDumper::writeSourceLocation(SourceLocation Loc) {
209   SourceLocation Spelling = SM.getSpellingLoc(Loc);
210   SourceLocation Expansion = SM.getExpansionLoc(Loc);
211 
212   if (Expansion != Spelling) {
213     // If the expansion and the spelling are different, output subobjects
214     // describing both locations.
215     JOS.attributeObject("spellingLoc", [Spelling, this] {
216       writeBareSourceLocation(Spelling, /*IsSpelling*/ true);
217     });
218     JOS.attributeObject("expansionLoc", [Expansion, Loc, this] {
219       writeBareSourceLocation(Expansion, /*IsSpelling*/ false);
220       // If there is a macro expansion, add extra information if the interesting
221       // bit is the macro arg expansion.
222       if (SM.isMacroArgExpansion(Loc))
223         JOS.attribute("isMacroArgExpansion", true);
224     });
225   } else
226     writeBareSourceLocation(Spelling, /*IsSpelling*/ true);
227 }
228 
229 void JSONNodeDumper::writeSourceRange(SourceRange R) {
230   JOS.attributeObject("begin",
231                       [R, this] { writeSourceLocation(R.getBegin()); });
232   JOS.attributeObject("end", [R, this] { writeSourceLocation(R.getEnd()); });
233 }
234 
235 std::string JSONNodeDumper::createPointerRepresentation(const void *Ptr) {
236   // Because JSON stores integer values as signed 64-bit integers, trying to
237   // represent them as such makes for very ugly pointer values in the resulting
238   // output. Instead, we convert the value to hex and treat it as a string.
239   return "0x" + llvm::utohexstr(reinterpret_cast<uint64_t>(Ptr), true);
240 }
241 
242 llvm::json::Object JSONNodeDumper::createQualType(QualType QT, bool Desugar) {
243   SplitQualType SQT = QT.split();
244   llvm::json::Object Ret{{"qualType", QualType::getAsString(SQT, PrintPolicy)}};
245 
246   if (Desugar && !QT.isNull()) {
247     SplitQualType DSQT = QT.getSplitDesugaredType();
248     if (DSQT != SQT)
249       Ret["desugaredQualType"] = QualType::getAsString(DSQT, PrintPolicy);
250     if (const auto *TT = QT->getAs<TypedefType>())
251       Ret["typeAliasDeclId"] = createPointerRepresentation(TT->getDecl());
252   }
253   return Ret;
254 }
255 
256 void JSONNodeDumper::writeBareDeclRef(const Decl *D) {
257   JOS.attribute("id", createPointerRepresentation(D));
258   if (!D)
259     return;
260 
261   JOS.attribute("kind", (llvm::Twine(D->getDeclKindName()) + "Decl").str());
262   if (const auto *ND = dyn_cast<NamedDecl>(D))
263     JOS.attribute("name", ND->getDeclName().getAsString());
264   if (const auto *VD = dyn_cast<ValueDecl>(D))
265     JOS.attribute("type", createQualType(VD->getType()));
266 }
267 
268 llvm::json::Object JSONNodeDumper::createBareDeclRef(const Decl *D) {
269   llvm::json::Object Ret{{"id", createPointerRepresentation(D)}};
270   if (!D)
271     return Ret;
272 
273   Ret["kind"] = (llvm::Twine(D->getDeclKindName()) + "Decl").str();
274   if (const auto *ND = dyn_cast<NamedDecl>(D))
275     Ret["name"] = ND->getDeclName().getAsString();
276   if (const auto *VD = dyn_cast<ValueDecl>(D))
277     Ret["type"] = createQualType(VD->getType());
278   return Ret;
279 }
280 
281 llvm::json::Array JSONNodeDumper::createCastPath(const CastExpr *C) {
282   llvm::json::Array Ret;
283   if (C->path_empty())
284     return Ret;
285 
286   for (auto I = C->path_begin(), E = C->path_end(); I != E; ++I) {
287     const CXXBaseSpecifier *Base = *I;
288     const auto *RD =
289         cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
290 
291     llvm::json::Object Val{{"name", RD->getName()}};
292     if (Base->isVirtual())
293       Val["isVirtual"] = true;
294     Ret.push_back(std::move(Val));
295   }
296   return Ret;
297 }
298 
299 #define FIELD2(Name, Flag)  if (RD->Flag()) Ret[Name] = true
300 #define FIELD1(Flag)        FIELD2(#Flag, Flag)
301 
302 static llvm::json::Object
303 createDefaultConstructorDefinitionData(const CXXRecordDecl *RD) {
304   llvm::json::Object Ret;
305 
306   FIELD2("exists", hasDefaultConstructor);
307   FIELD2("trivial", hasTrivialDefaultConstructor);
308   FIELD2("nonTrivial", hasNonTrivialDefaultConstructor);
309   FIELD2("userProvided", hasUserProvidedDefaultConstructor);
310   FIELD2("isConstexpr", hasConstexprDefaultConstructor);
311   FIELD2("needsImplicit", needsImplicitDefaultConstructor);
312   FIELD2("defaultedIsConstexpr", defaultedDefaultConstructorIsConstexpr);
313 
314   return Ret;
315 }
316 
317 static llvm::json::Object
318 createCopyConstructorDefinitionData(const CXXRecordDecl *RD) {
319   llvm::json::Object Ret;
320 
321   FIELD2("simple", hasSimpleCopyConstructor);
322   FIELD2("trivial", hasTrivialCopyConstructor);
323   FIELD2("nonTrivial", hasNonTrivialCopyConstructor);
324   FIELD2("userDeclared", hasUserDeclaredCopyConstructor);
325   FIELD2("hasConstParam", hasCopyConstructorWithConstParam);
326   FIELD2("implicitHasConstParam", implicitCopyConstructorHasConstParam);
327   FIELD2("needsImplicit", needsImplicitCopyConstructor);
328   FIELD2("needsOverloadResolution", needsOverloadResolutionForCopyConstructor);
329   if (!RD->needsOverloadResolutionForCopyConstructor())
330     FIELD2("defaultedIsDeleted", defaultedCopyConstructorIsDeleted);
331 
332   return Ret;
333 }
334 
335 static llvm::json::Object
336 createMoveConstructorDefinitionData(const CXXRecordDecl *RD) {
337   llvm::json::Object Ret;
338 
339   FIELD2("exists", hasMoveConstructor);
340   FIELD2("simple", hasSimpleMoveConstructor);
341   FIELD2("trivial", hasTrivialMoveConstructor);
342   FIELD2("nonTrivial", hasNonTrivialMoveConstructor);
343   FIELD2("userDeclared", hasUserDeclaredMoveConstructor);
344   FIELD2("needsImplicit", needsImplicitMoveConstructor);
345   FIELD2("needsOverloadResolution", needsOverloadResolutionForMoveConstructor);
346   if (!RD->needsOverloadResolutionForMoveConstructor())
347     FIELD2("defaultedIsDeleted", defaultedMoveConstructorIsDeleted);
348 
349   return Ret;
350 }
351 
352 static llvm::json::Object
353 createCopyAssignmentDefinitionData(const CXXRecordDecl *RD) {
354   llvm::json::Object Ret;
355 
356   FIELD2("trivial", hasTrivialCopyAssignment);
357   FIELD2("nonTrivial", hasNonTrivialCopyAssignment);
358   FIELD2("hasConstParam", hasCopyAssignmentWithConstParam);
359   FIELD2("implicitHasConstParam", implicitCopyAssignmentHasConstParam);
360   FIELD2("userDeclared", hasUserDeclaredCopyAssignment);
361   FIELD2("needsImplicit", needsImplicitCopyAssignment);
362   FIELD2("needsOverloadResolution", needsOverloadResolutionForCopyAssignment);
363 
364   return Ret;
365 }
366 
367 static llvm::json::Object
368 createMoveAssignmentDefinitionData(const CXXRecordDecl *RD) {
369   llvm::json::Object Ret;
370 
371   FIELD2("exists", hasMoveAssignment);
372   FIELD2("simple", hasSimpleMoveAssignment);
373   FIELD2("trivial", hasTrivialMoveAssignment);
374   FIELD2("nonTrivial", hasNonTrivialMoveAssignment);
375   FIELD2("userDeclared", hasUserDeclaredMoveAssignment);
376   FIELD2("needsImplicit", needsImplicitMoveAssignment);
377   FIELD2("needsOverloadResolution", needsOverloadResolutionForMoveAssignment);
378 
379   return Ret;
380 }
381 
382 static llvm::json::Object
383 createDestructorDefinitionData(const CXXRecordDecl *RD) {
384   llvm::json::Object Ret;
385 
386   FIELD2("simple", hasSimpleDestructor);
387   FIELD2("irrelevant", hasIrrelevantDestructor);
388   FIELD2("trivial", hasTrivialDestructor);
389   FIELD2("nonTrivial", hasNonTrivialDestructor);
390   FIELD2("userDeclared", hasUserDeclaredDestructor);
391   FIELD2("needsImplicit", needsImplicitDestructor);
392   FIELD2("needsOverloadResolution", needsOverloadResolutionForDestructor);
393   if (!RD->needsOverloadResolutionForDestructor())
394     FIELD2("defaultedIsDeleted", defaultedDestructorIsDeleted);
395 
396   return Ret;
397 }
398 
399 llvm::json::Object
400 JSONNodeDumper::createCXXRecordDefinitionData(const CXXRecordDecl *RD) {
401   llvm::json::Object Ret;
402 
403   // This data is common to all C++ classes.
404   FIELD1(isGenericLambda);
405   FIELD1(isLambda);
406   FIELD1(isEmpty);
407   FIELD1(isAggregate);
408   FIELD1(isStandardLayout);
409   FIELD1(isTriviallyCopyable);
410   FIELD1(isPOD);
411   FIELD1(isTrivial);
412   FIELD1(isPolymorphic);
413   FIELD1(isAbstract);
414   FIELD1(isLiteral);
415   FIELD1(canPassInRegisters);
416   FIELD1(hasUserDeclaredConstructor);
417   FIELD1(hasConstexprNonCopyMoveConstructor);
418   FIELD1(hasMutableFields);
419   FIELD1(hasVariantMembers);
420   FIELD2("canConstDefaultInit", allowConstDefaultInit);
421 
422   Ret["defaultCtor"] = createDefaultConstructorDefinitionData(RD);
423   Ret["copyCtor"] = createCopyConstructorDefinitionData(RD);
424   Ret["moveCtor"] = createMoveConstructorDefinitionData(RD);
425   Ret["copyAssign"] = createCopyAssignmentDefinitionData(RD);
426   Ret["moveAssign"] = createMoveAssignmentDefinitionData(RD);
427   Ret["dtor"] = createDestructorDefinitionData(RD);
428 
429   return Ret;
430 }
431 
432 #undef FIELD1
433 #undef FIELD2
434 
435 std::string JSONNodeDumper::createAccessSpecifier(AccessSpecifier AS) {
436   switch (AS) {
437   case AS_none: return "none";
438   case AS_private: return "private";
439   case AS_protected: return "protected";
440   case AS_public: return "public";
441   }
442   llvm_unreachable("Unknown access specifier");
443 }
444 
445 llvm::json::Object
446 JSONNodeDumper::createCXXBaseSpecifier(const CXXBaseSpecifier &BS) {
447   llvm::json::Object Ret;
448 
449   Ret["type"] = createQualType(BS.getType());
450   Ret["access"] = createAccessSpecifier(BS.getAccessSpecifier());
451   Ret["writtenAccess"] =
452       createAccessSpecifier(BS.getAccessSpecifierAsWritten());
453   if (BS.isVirtual())
454     Ret["isVirtual"] = true;
455   if (BS.isPackExpansion())
456     Ret["isPackExpansion"] = true;
457 
458   return Ret;
459 }
460 
461 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
462   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
463 }
464 
465 void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
466   FunctionType::ExtInfo E = T->getExtInfo();
467   attributeOnlyIfTrue("noreturn", E.getNoReturn());
468   attributeOnlyIfTrue("producesResult", E.getProducesResult());
469   if (E.getHasRegParm())
470     JOS.attribute("regParm", E.getRegParm());
471   JOS.attribute("cc", FunctionType::getNameForCallConv(E.getCC()));
472 }
473 
474 void JSONNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
475   FunctionProtoType::ExtProtoInfo E = T->getExtProtoInfo();
476   attributeOnlyIfTrue("trailingReturn", E.HasTrailingReturn);
477   attributeOnlyIfTrue("const", T->isConst());
478   attributeOnlyIfTrue("volatile", T->isVolatile());
479   attributeOnlyIfTrue("restrict", T->isRestrict());
480   attributeOnlyIfTrue("variadic", E.Variadic);
481   switch (E.RefQualifier) {
482   case RQ_LValue: JOS.attribute("refQualifier", "&"); break;
483   case RQ_RValue: JOS.attribute("refQualifier", "&&"); break;
484   case RQ_None: break;
485   }
486   switch (E.ExceptionSpec.Type) {
487   case EST_DynamicNone:
488   case EST_Dynamic: {
489     JOS.attribute("exceptionSpec", "throw");
490     llvm::json::Array Types;
491     for (QualType QT : E.ExceptionSpec.Exceptions)
492       Types.push_back(createQualType(QT));
493     JOS.attribute("exceptionTypes", std::move(Types));
494   } break;
495   case EST_MSAny:
496     JOS.attribute("exceptionSpec", "throw");
497     JOS.attribute("throwsAny", true);
498     break;
499   case EST_BasicNoexcept:
500     JOS.attribute("exceptionSpec", "noexcept");
501     break;
502   case EST_NoexceptTrue:
503   case EST_NoexceptFalse:
504     JOS.attribute("exceptionSpec", "noexcept");
505     JOS.attribute("conditionEvaluatesTo",
506                 E.ExceptionSpec.Type == EST_NoexceptTrue);
507     //JOS.attributeWithCall("exceptionSpecExpr",
508     //                    [this, E]() { Visit(E.ExceptionSpec.NoexceptExpr); });
509     break;
510   case EST_NoThrow:
511     JOS.attribute("exceptionSpec", "nothrow");
512     break;
513   // FIXME: I cannot find a way to trigger these cases while dumping the AST. I
514   // suspect you can only run into them when executing an AST dump from within
515   // the debugger, which is not a use case we worry about for the JSON dumping
516   // feature.
517   case EST_DependentNoexcept:
518   case EST_Unevaluated:
519   case EST_Uninstantiated:
520   case EST_Unparsed:
521   case EST_None: break;
522   }
523   VisitFunctionType(T);
524 }
525 
526 void JSONNodeDumper::VisitRValueReferenceType(const ReferenceType *RT) {
527   attributeOnlyIfTrue("spelledAsLValue", RT->isSpelledAsLValue());
528 }
529 
530 void JSONNodeDumper::VisitArrayType(const ArrayType *AT) {
531   switch (AT->getSizeModifier()) {
532   case ArrayType::Star:
533     JOS.attribute("sizeModifier", "*");
534     break;
535   case ArrayType::Static:
536     JOS.attribute("sizeModifier", "static");
537     break;
538   case ArrayType::Normal:
539     break;
540   }
541 
542   std::string Str = AT->getIndexTypeQualifiers().getAsString();
543   if (!Str.empty())
544     JOS.attribute("indexTypeQualifiers", Str);
545 }
546 
547 void JSONNodeDumper::VisitConstantArrayType(const ConstantArrayType *CAT) {
548   // FIXME: this should use ZExt instead of SExt, but JSON doesn't allow a
549   // narrowing conversion to int64_t so it cannot be expressed.
550   JOS.attribute("size", CAT->getSize().getSExtValue());
551   VisitArrayType(CAT);
552 }
553 
554 void JSONNodeDumper::VisitDependentSizedExtVectorType(
555     const DependentSizedExtVectorType *VT) {
556   JOS.attributeObject(
557       "attrLoc", [VT, this] { writeSourceLocation(VT->getAttributeLoc()); });
558 }
559 
560 void JSONNodeDumper::VisitVectorType(const VectorType *VT) {
561   JOS.attribute("numElements", VT->getNumElements());
562   switch (VT->getVectorKind()) {
563   case VectorType::GenericVector:
564     break;
565   case VectorType::AltiVecVector:
566     JOS.attribute("vectorKind", "altivec");
567     break;
568   case VectorType::AltiVecPixel:
569     JOS.attribute("vectorKind", "altivec pixel");
570     break;
571   case VectorType::AltiVecBool:
572     JOS.attribute("vectorKind", "altivec bool");
573     break;
574   case VectorType::NeonVector:
575     JOS.attribute("vectorKind", "neon");
576     break;
577   case VectorType::NeonPolyVector:
578     JOS.attribute("vectorKind", "neon poly");
579     break;
580   }
581 }
582 
583 void JSONNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *UUT) {
584   JOS.attribute("decl", createBareDeclRef(UUT->getDecl()));
585 }
586 
587 void JSONNodeDumper::VisitUnaryTransformType(const UnaryTransformType *UTT) {
588   switch (UTT->getUTTKind()) {
589   case UnaryTransformType::EnumUnderlyingType:
590     JOS.attribute("transformKind", "underlying_type");
591     break;
592   }
593 }
594 
595 void JSONNodeDumper::VisitTagType(const TagType *TT) {
596   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
597 }
598 
599 void JSONNodeDumper::VisitTemplateTypeParmType(
600     const TemplateTypeParmType *TTPT) {
601   JOS.attribute("depth", TTPT->getDepth());
602   JOS.attribute("index", TTPT->getIndex());
603   attributeOnlyIfTrue("isPack", TTPT->isParameterPack());
604   JOS.attribute("decl", createBareDeclRef(TTPT->getDecl()));
605 }
606 
607 void JSONNodeDumper::VisitAutoType(const AutoType *AT) {
608   JOS.attribute("undeduced", !AT->isDeduced());
609   switch (AT->getKeyword()) {
610   case AutoTypeKeyword::Auto:
611     JOS.attribute("typeKeyword", "auto");
612     break;
613   case AutoTypeKeyword::DecltypeAuto:
614     JOS.attribute("typeKeyword", "decltype(auto)");
615     break;
616   case AutoTypeKeyword::GNUAutoType:
617     JOS.attribute("typeKeyword", "__auto_type");
618     break;
619   }
620 }
621 
622 void JSONNodeDumper::VisitTemplateSpecializationType(
623     const TemplateSpecializationType *TST) {
624   attributeOnlyIfTrue("isAlias", TST->isTypeAlias());
625 
626   std::string Str;
627   llvm::raw_string_ostream OS(Str);
628   TST->getTemplateName().print(OS, PrintPolicy);
629   JOS.attribute("templateName", OS.str());
630 }
631 
632 void JSONNodeDumper::VisitInjectedClassNameType(
633     const InjectedClassNameType *ICNT) {
634   JOS.attribute("decl", createBareDeclRef(ICNT->getDecl()));
635 }
636 
637 void JSONNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
638   JOS.attribute("decl", createBareDeclRef(OIT->getDecl()));
639 }
640 
641 void JSONNodeDumper::VisitPackExpansionType(const PackExpansionType *PET) {
642   if (llvm::Optional<unsigned> N = PET->getNumExpansions())
643     JOS.attribute("numExpansions", *N);
644 }
645 
646 void JSONNodeDumper::VisitElaboratedType(const ElaboratedType *ET) {
647   if (const NestedNameSpecifier *NNS = ET->getQualifier()) {
648     std::string Str;
649     llvm::raw_string_ostream OS(Str);
650     NNS->print(OS, PrintPolicy, /*ResolveTemplateArgs*/ true);
651     JOS.attribute("qualifier", OS.str());
652   }
653   if (const TagDecl *TD = ET->getOwnedTagDecl())
654     JOS.attribute("ownedTagDecl", createBareDeclRef(TD));
655 }
656 
657 void JSONNodeDumper::VisitMacroQualifiedType(const MacroQualifiedType *MQT) {
658   JOS.attribute("macroName", MQT->getMacroIdentifier()->getName());
659 }
660 
661 void JSONNodeDumper::VisitMemberPointerType(const MemberPointerType *MPT) {
662   attributeOnlyIfTrue("isData", MPT->isMemberDataPointer());
663   attributeOnlyIfTrue("isFunction", MPT->isMemberFunctionPointer());
664 }
665 
666 void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
667   if (ND && ND->getDeclName())
668     JOS.attribute("name", ND->getNameAsString());
669 }
670 
671 void JSONNodeDumper::VisitTypedefDecl(const TypedefDecl *TD) {
672   VisitNamedDecl(TD);
673   JOS.attribute("type", createQualType(TD->getUnderlyingType()));
674 }
675 
676 void JSONNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *TAD) {
677   VisitNamedDecl(TAD);
678   JOS.attribute("type", createQualType(TAD->getUnderlyingType()));
679 }
680 
681 void JSONNodeDumper::VisitNamespaceDecl(const NamespaceDecl *ND) {
682   VisitNamedDecl(ND);
683   attributeOnlyIfTrue("isInline", ND->isInline());
684   if (!ND->isOriginalNamespace())
685     JOS.attribute("originalNamespace",
686                   createBareDeclRef(ND->getOriginalNamespace()));
687 }
688 
689 void JSONNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD) {
690   JOS.attribute("nominatedNamespace",
691                 createBareDeclRef(UDD->getNominatedNamespace()));
692 }
693 
694 void JSONNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD) {
695   VisitNamedDecl(NAD);
696   JOS.attribute("aliasedNamespace",
697                 createBareDeclRef(NAD->getAliasedNamespace()));
698 }
699 
700 void JSONNodeDumper::VisitUsingDecl(const UsingDecl *UD) {
701   std::string Name;
702   if (const NestedNameSpecifier *NNS = UD->getQualifier()) {
703     llvm::raw_string_ostream SOS(Name);
704     NNS->print(SOS, UD->getASTContext().getPrintingPolicy());
705   }
706   Name += UD->getNameAsString();
707   JOS.attribute("name", Name);
708 }
709 
710 void JSONNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *USD) {
711   JOS.attribute("target", createBareDeclRef(USD->getTargetDecl()));
712 }
713 
714 void JSONNodeDumper::VisitVarDecl(const VarDecl *VD) {
715   VisitNamedDecl(VD);
716   JOS.attribute("type", createQualType(VD->getType()));
717 
718   StorageClass SC = VD->getStorageClass();
719   if (SC != SC_None)
720     JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC));
721   switch (VD->getTLSKind()) {
722   case VarDecl::TLS_Dynamic: JOS.attribute("tls", "dynamic"); break;
723   case VarDecl::TLS_Static: JOS.attribute("tls", "static"); break;
724   case VarDecl::TLS_None: break;
725   }
726   attributeOnlyIfTrue("nrvo", VD->isNRVOVariable());
727   attributeOnlyIfTrue("inline", VD->isInline());
728   attributeOnlyIfTrue("constexpr", VD->isConstexpr());
729   attributeOnlyIfTrue("modulePrivate", VD->isModulePrivate());
730   if (VD->hasInit()) {
731     switch (VD->getInitStyle()) {
732     case VarDecl::CInit: JOS.attribute("init", "c");  break;
733     case VarDecl::CallInit: JOS.attribute("init", "call"); break;
734     case VarDecl::ListInit: JOS.attribute("init", "list"); break;
735     }
736   }
737   attributeOnlyIfTrue("isParameterPack", VD->isParameterPack());
738 }
739 
740 void JSONNodeDumper::VisitFieldDecl(const FieldDecl *FD) {
741   VisitNamedDecl(FD);
742   JOS.attribute("type", createQualType(FD->getType()));
743   attributeOnlyIfTrue("mutable", FD->isMutable());
744   attributeOnlyIfTrue("modulePrivate", FD->isModulePrivate());
745   attributeOnlyIfTrue("isBitfield", FD->isBitField());
746   attributeOnlyIfTrue("hasInClassInitializer", FD->hasInClassInitializer());
747 }
748 
749 void JSONNodeDumper::VisitFunctionDecl(const FunctionDecl *FD) {
750   VisitNamedDecl(FD);
751   JOS.attribute("type", createQualType(FD->getType()));
752   StorageClass SC = FD->getStorageClass();
753   if (SC != SC_None)
754     JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC));
755   attributeOnlyIfTrue("inline", FD->isInlineSpecified());
756   attributeOnlyIfTrue("virtual", FD->isVirtualAsWritten());
757   attributeOnlyIfTrue("pure", FD->isPure());
758   attributeOnlyIfTrue("explicitlyDeleted", FD->isDeletedAsWritten());
759   attributeOnlyIfTrue("constexpr", FD->isConstexpr());
760   attributeOnlyIfTrue("variadic", FD->isVariadic());
761 
762   if (FD->isDefaulted())
763     JOS.attribute("explicitlyDefaulted",
764                   FD->isDeleted() ? "deleted" : "default");
765 }
766 
767 void JSONNodeDumper::VisitEnumDecl(const EnumDecl *ED) {
768   VisitNamedDecl(ED);
769   if (ED->isFixed())
770     JOS.attribute("fixedUnderlyingType", createQualType(ED->getIntegerType()));
771   if (ED->isScoped())
772     JOS.attribute("scopedEnumTag",
773                   ED->isScopedUsingClassTag() ? "class" : "struct");
774 }
775 void JSONNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *ECD) {
776   VisitNamedDecl(ECD);
777   JOS.attribute("type", createQualType(ECD->getType()));
778 }
779 
780 void JSONNodeDumper::VisitRecordDecl(const RecordDecl *RD) {
781   VisitNamedDecl(RD);
782   JOS.attribute("tagUsed", RD->getKindName());
783   attributeOnlyIfTrue("completeDefinition", RD->isCompleteDefinition());
784 }
785 void JSONNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *RD) {
786   VisitRecordDecl(RD);
787 
788   // All other information requires a complete definition.
789   if (!RD->isCompleteDefinition())
790     return;
791 
792   JOS.attribute("definitionData", createCXXRecordDefinitionData(RD));
793   if (RD->getNumBases()) {
794     JOS.attributeArray("bases", [this, RD] {
795       for (const auto &Spec : RD->bases())
796         JOS.value(createCXXBaseSpecifier(Spec));
797     });
798   }
799 }
800 
801 void JSONNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
802   VisitNamedDecl(D);
803   JOS.attribute("tagUsed", D->wasDeclaredWithTypename() ? "typename" : "class");
804   JOS.attribute("depth", D->getDepth());
805   JOS.attribute("index", D->getIndex());
806   attributeOnlyIfTrue("isParameterPack", D->isParameterPack());
807 
808   if (D->hasDefaultArgument())
809     JOS.attributeObject("defaultArg", [=] {
810       Visit(D->getDefaultArgument(), SourceRange(),
811             D->getDefaultArgStorage().getInheritedFrom(),
812             D->defaultArgumentWasInherited() ? "inherited from" : "previous");
813     });
814 }
815 
816 void JSONNodeDumper::VisitNonTypeTemplateParmDecl(
817     const NonTypeTemplateParmDecl *D) {
818   VisitNamedDecl(D);
819   JOS.attribute("type", createQualType(D->getType()));
820   JOS.attribute("depth", D->getDepth());
821   JOS.attribute("index", D->getIndex());
822   attributeOnlyIfTrue("isParameterPack", D->isParameterPack());
823 
824   if (D->hasDefaultArgument())
825     JOS.attributeObject("defaultArg", [=] {
826       Visit(D->getDefaultArgument(), SourceRange(),
827             D->getDefaultArgStorage().getInheritedFrom(),
828             D->defaultArgumentWasInherited() ? "inherited from" : "previous");
829     });
830 }
831 
832 void JSONNodeDumper::VisitTemplateTemplateParmDecl(
833     const TemplateTemplateParmDecl *D) {
834   VisitNamedDecl(D);
835   JOS.attribute("depth", D->getDepth());
836   JOS.attribute("index", D->getIndex());
837   attributeOnlyIfTrue("isParameterPack", D->isParameterPack());
838 
839   if (D->hasDefaultArgument())
840     JOS.attributeObject("defaultArg", [=] {
841       Visit(D->getDefaultArgument().getArgument(),
842             D->getDefaultArgStorage().getInheritedFrom()->getSourceRange(),
843             D->getDefaultArgStorage().getInheritedFrom(),
844             D->defaultArgumentWasInherited() ? "inherited from" : "previous");
845     });
846 }
847 
848 void JSONNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *LSD) {
849   StringRef Lang;
850   switch (LSD->getLanguage()) {
851   case LinkageSpecDecl::lang_c: Lang = "C"; break;
852   case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
853   }
854   JOS.attribute("language", Lang);
855   attributeOnlyIfTrue("hasBraces", LSD->hasBraces());
856 }
857 
858 void JSONNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *ASD) {
859   JOS.attribute("access", createAccessSpecifier(ASD->getAccess()));
860 }
861 
862 void JSONNodeDumper::VisitFriendDecl(const FriendDecl *FD) {
863   if (const TypeSourceInfo *T = FD->getFriendType())
864     JOS.attribute("type", createQualType(T->getType()));
865 }
866 
867 void JSONNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
868   VisitNamedDecl(D);
869   JOS.attribute("type", createQualType(D->getType()));
870   attributeOnlyIfTrue("synthesized", D->getSynthesize());
871   switch (D->getAccessControl()) {
872   case ObjCIvarDecl::None: JOS.attribute("access", "none"); break;
873   case ObjCIvarDecl::Private: JOS.attribute("access", "private"); break;
874   case ObjCIvarDecl::Protected: JOS.attribute("access", "protected"); break;
875   case ObjCIvarDecl::Public: JOS.attribute("access", "public"); break;
876   case ObjCIvarDecl::Package: JOS.attribute("access", "package"); break;
877   }
878 }
879 
880 void JSONNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
881   VisitNamedDecl(D);
882   JOS.attribute("returnType", createQualType(D->getReturnType()));
883   JOS.attribute("instance", D->isInstanceMethod());
884   attributeOnlyIfTrue("variadic", D->isVariadic());
885 }
886 
887 void JSONNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
888   VisitNamedDecl(D);
889   JOS.attribute("type", createQualType(D->getUnderlyingType()));
890   attributeOnlyIfTrue("bounded", D->hasExplicitBound());
891   switch (D->getVariance()) {
892   case ObjCTypeParamVariance::Invariant:
893     break;
894   case ObjCTypeParamVariance::Covariant:
895     JOS.attribute("variance", "covariant");
896     break;
897   case ObjCTypeParamVariance::Contravariant:
898     JOS.attribute("variance", "contravariant");
899     break;
900   }
901 }
902 
903 void JSONNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
904   VisitNamedDecl(D);
905   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
906   JOS.attribute("implementation", createBareDeclRef(D->getImplementation()));
907 
908   llvm::json::Array Protocols;
909   for (const auto* P : D->protocols())
910     Protocols.push_back(createBareDeclRef(P));
911   if (!Protocols.empty())
912     JOS.attribute("protocols", std::move(Protocols));
913 }
914 
915 void JSONNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
916   VisitNamedDecl(D);
917   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
918   JOS.attribute("categoryDecl", createBareDeclRef(D->getCategoryDecl()));
919 }
920 
921 void JSONNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
922   VisitNamedDecl(D);
923 
924   llvm::json::Array Protocols;
925   for (const auto *P : D->protocols())
926     Protocols.push_back(createBareDeclRef(P));
927   if (!Protocols.empty())
928     JOS.attribute("protocols", std::move(Protocols));
929 }
930 
931 void JSONNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
932   VisitNamedDecl(D);
933   JOS.attribute("super", createBareDeclRef(D->getSuperClass()));
934   JOS.attribute("implementation", createBareDeclRef(D->getImplementation()));
935 
936   llvm::json::Array Protocols;
937   for (const auto* P : D->protocols())
938     Protocols.push_back(createBareDeclRef(P));
939   if (!Protocols.empty())
940     JOS.attribute("protocols", std::move(Protocols));
941 }
942 
943 void JSONNodeDumper::VisitObjCImplementationDecl(
944     const ObjCImplementationDecl *D) {
945   VisitNamedDecl(D);
946   JOS.attribute("super", createBareDeclRef(D->getSuperClass()));
947   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
948 }
949 
950 void JSONNodeDumper::VisitObjCCompatibleAliasDecl(
951     const ObjCCompatibleAliasDecl *D) {
952   VisitNamedDecl(D);
953   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
954 }
955 
956 void JSONNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
957   VisitNamedDecl(D);
958   JOS.attribute("type", createQualType(D->getType()));
959 
960   switch (D->getPropertyImplementation()) {
961   case ObjCPropertyDecl::None: break;
962   case ObjCPropertyDecl::Required: JOS.attribute("control", "required"); break;
963   case ObjCPropertyDecl::Optional: JOS.attribute("control", "optional"); break;
964   }
965 
966   ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
967   if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
968     if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
969       JOS.attribute("getter", createBareDeclRef(D->getGetterMethodDecl()));
970     if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
971       JOS.attribute("setter", createBareDeclRef(D->getSetterMethodDecl()));
972     attributeOnlyIfTrue("readonly", Attrs & ObjCPropertyDecl::OBJC_PR_readonly);
973     attributeOnlyIfTrue("assign", Attrs & ObjCPropertyDecl::OBJC_PR_assign);
974     attributeOnlyIfTrue("readwrite",
975                         Attrs & ObjCPropertyDecl::OBJC_PR_readwrite);
976     attributeOnlyIfTrue("retain", Attrs & ObjCPropertyDecl::OBJC_PR_retain);
977     attributeOnlyIfTrue("copy", Attrs & ObjCPropertyDecl::OBJC_PR_copy);
978     attributeOnlyIfTrue("nonatomic",
979                         Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic);
980     attributeOnlyIfTrue("atomic", Attrs & ObjCPropertyDecl::OBJC_PR_atomic);
981     attributeOnlyIfTrue("weak", Attrs & ObjCPropertyDecl::OBJC_PR_weak);
982     attributeOnlyIfTrue("strong", Attrs & ObjCPropertyDecl::OBJC_PR_strong);
983     attributeOnlyIfTrue("unsafe_unretained",
984                         Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
985     attributeOnlyIfTrue("class", Attrs & ObjCPropertyDecl::OBJC_PR_class);
986     attributeOnlyIfTrue("nullability",
987                         Attrs & ObjCPropertyDecl::OBJC_PR_nullability);
988     attributeOnlyIfTrue("null_resettable",
989                         Attrs & ObjCPropertyDecl::OBJC_PR_null_resettable);
990   }
991 }
992 
993 void JSONNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
994   VisitNamedDecl(D->getPropertyDecl());
995   JOS.attribute("implKind", D->getPropertyImplementation() ==
996                                     ObjCPropertyImplDecl::Synthesize
997                                 ? "synthesize"
998                                 : "dynamic");
999   JOS.attribute("propertyDecl", createBareDeclRef(D->getPropertyDecl()));
1000   JOS.attribute("ivarDecl", createBareDeclRef(D->getPropertyIvarDecl()));
1001 }
1002 
1003 void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) {
1004   attributeOnlyIfTrue("variadic", D->isVariadic());
1005   attributeOnlyIfTrue("capturesThis", D->capturesCXXThis());
1006 }
1007 
1008 void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) {
1009   JOS.attribute("encodedType", createQualType(OEE->getEncodedType()));
1010 }
1011 
1012 void JSONNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *OME) {
1013   std::string Str;
1014   llvm::raw_string_ostream OS(Str);
1015 
1016   OME->getSelector().print(OS);
1017   JOS.attribute("selector", OS.str());
1018 
1019   switch (OME->getReceiverKind()) {
1020   case ObjCMessageExpr::Instance:
1021     JOS.attribute("receiverKind", "instance");
1022     break;
1023   case ObjCMessageExpr::Class:
1024     JOS.attribute("receiverKind", "class");
1025     JOS.attribute("classType", createQualType(OME->getClassReceiver()));
1026     break;
1027   case ObjCMessageExpr::SuperInstance:
1028     JOS.attribute("receiverKind", "super (instance)");
1029     JOS.attribute("superType", createQualType(OME->getSuperType()));
1030     break;
1031   case ObjCMessageExpr::SuperClass:
1032     JOS.attribute("receiverKind", "super (class)");
1033     JOS.attribute("superType", createQualType(OME->getSuperType()));
1034     break;
1035   }
1036 
1037   QualType CallReturnTy = OME->getCallReturnType(Ctx);
1038   if (OME->getType() != CallReturnTy)
1039     JOS.attribute("callReturnType", createQualType(CallReturnTy));
1040 }
1041 
1042 void JSONNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE) {
1043   if (const ObjCMethodDecl *MD = OBE->getBoxingMethod()) {
1044     std::string Str;
1045     llvm::raw_string_ostream OS(Str);
1046 
1047     MD->getSelector().print(OS);
1048     JOS.attribute("selector", OS.str());
1049   }
1050 }
1051 
1052 void JSONNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE) {
1053   std::string Str;
1054   llvm::raw_string_ostream OS(Str);
1055 
1056   OSE->getSelector().print(OS);
1057   JOS.attribute("selector", OS.str());
1058 }
1059 
1060 void JSONNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) {
1061   JOS.attribute("protocol", createBareDeclRef(OPE->getProtocol()));
1062 }
1063 
1064 void JSONNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) {
1065   if (OPRE->isImplicitProperty()) {
1066     JOS.attribute("propertyKind", "implicit");
1067     if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertyGetter())
1068       JOS.attribute("getter", createBareDeclRef(MD));
1069     if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertySetter())
1070       JOS.attribute("setter", createBareDeclRef(MD));
1071   } else {
1072     JOS.attribute("propertyKind", "explicit");
1073     JOS.attribute("property", createBareDeclRef(OPRE->getExplicitProperty()));
1074   }
1075 
1076   attributeOnlyIfTrue("isSuperReceiver", OPRE->isSuperReceiver());
1077   attributeOnlyIfTrue("isMessagingGetter", OPRE->isMessagingGetter());
1078   attributeOnlyIfTrue("isMessagingSetter", OPRE->isMessagingSetter());
1079 }
1080 
1081 void JSONNodeDumper::VisitObjCSubscriptRefExpr(
1082     const ObjCSubscriptRefExpr *OSRE) {
1083   JOS.attribute("subscriptKind",
1084                 OSRE->isArraySubscriptRefExpr() ? "array" : "dictionary");
1085 
1086   if (const ObjCMethodDecl *MD = OSRE->getAtIndexMethodDecl())
1087     JOS.attribute("getter", createBareDeclRef(MD));
1088   if (const ObjCMethodDecl *MD = OSRE->setAtIndexMethodDecl())
1089     JOS.attribute("setter", createBareDeclRef(MD));
1090 }
1091 
1092 void JSONNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE) {
1093   JOS.attribute("decl", createBareDeclRef(OIRE->getDecl()));
1094   attributeOnlyIfTrue("isFreeIvar", OIRE->isFreeIvar());
1095   JOS.attribute("isArrow", OIRE->isArrow());
1096 }
1097 
1098 void JSONNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE) {
1099   JOS.attribute("value", OBLE->getValue() ? "__objc_yes" : "__objc_no");
1100 }
1101 
1102 void JSONNodeDumper::VisitDeclRefExpr(const DeclRefExpr *DRE) {
1103   JOS.attribute("referencedDecl", createBareDeclRef(DRE->getDecl()));
1104   if (DRE->getDecl() != DRE->getFoundDecl())
1105     JOS.attribute("foundReferencedDecl",
1106                   createBareDeclRef(DRE->getFoundDecl()));
1107   switch (DRE->isNonOdrUse()) {
1108   case NOUR_None: break;
1109   case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break;
1110   case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
1111   case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
1112   }
1113 }
1114 
1115 void JSONNodeDumper::VisitPredefinedExpr(const PredefinedExpr *PE) {
1116   JOS.attribute("name", PredefinedExpr::getIdentKindName(PE->getIdentKind()));
1117 }
1118 
1119 void JSONNodeDumper::VisitUnaryOperator(const UnaryOperator *UO) {
1120   JOS.attribute("isPostfix", UO->isPostfix());
1121   JOS.attribute("opcode", UnaryOperator::getOpcodeStr(UO->getOpcode()));
1122   if (!UO->canOverflow())
1123     JOS.attribute("canOverflow", false);
1124 }
1125 
1126 void JSONNodeDumper::VisitBinaryOperator(const BinaryOperator *BO) {
1127   JOS.attribute("opcode", BinaryOperator::getOpcodeStr(BO->getOpcode()));
1128 }
1129 
1130 void JSONNodeDumper::VisitCompoundAssignOperator(
1131     const CompoundAssignOperator *CAO) {
1132   VisitBinaryOperator(CAO);
1133   JOS.attribute("computeLHSType", createQualType(CAO->getComputationLHSType()));
1134   JOS.attribute("computeResultType",
1135                 createQualType(CAO->getComputationResultType()));
1136 }
1137 
1138 void JSONNodeDumper::VisitMemberExpr(const MemberExpr *ME) {
1139   // Note, we always write this Boolean field because the information it conveys
1140   // is critical to understanding the AST node.
1141   ValueDecl *VD = ME->getMemberDecl();
1142   JOS.attribute("name", VD && VD->getDeclName() ? VD->getNameAsString() : "");
1143   JOS.attribute("isArrow", ME->isArrow());
1144   JOS.attribute("referencedMemberDecl", createPointerRepresentation(VD));
1145   switch (ME->isNonOdrUse()) {
1146   case NOUR_None: break;
1147   case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break;
1148   case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
1149   case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
1150   }
1151 }
1152 
1153 void JSONNodeDumper::VisitCXXNewExpr(const CXXNewExpr *NE) {
1154   attributeOnlyIfTrue("isGlobal", NE->isGlobalNew());
1155   attributeOnlyIfTrue("isArray", NE->isArray());
1156   attributeOnlyIfTrue("isPlacement", NE->getNumPlacementArgs() != 0);
1157   switch (NE->getInitializationStyle()) {
1158   case CXXNewExpr::NoInit: break;
1159   case CXXNewExpr::CallInit: JOS.attribute("initStyle", "call"); break;
1160   case CXXNewExpr::ListInit: JOS.attribute("initStyle", "list"); break;
1161   }
1162   if (const FunctionDecl *FD = NE->getOperatorNew())
1163     JOS.attribute("operatorNewDecl", createBareDeclRef(FD));
1164   if (const FunctionDecl *FD = NE->getOperatorDelete())
1165     JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD));
1166 }
1167 void JSONNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *DE) {
1168   attributeOnlyIfTrue("isGlobal", DE->isGlobalDelete());
1169   attributeOnlyIfTrue("isArray", DE->isArrayForm());
1170   attributeOnlyIfTrue("isArrayAsWritten", DE->isArrayFormAsWritten());
1171   if (const FunctionDecl *FD = DE->getOperatorDelete())
1172     JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD));
1173 }
1174 
1175 void JSONNodeDumper::VisitCXXThisExpr(const CXXThisExpr *TE) {
1176   attributeOnlyIfTrue("implicit", TE->isImplicit());
1177 }
1178 
1179 void JSONNodeDumper::VisitCastExpr(const CastExpr *CE) {
1180   JOS.attribute("castKind", CE->getCastKindName());
1181   llvm::json::Array Path = createCastPath(CE);
1182   if (!Path.empty())
1183     JOS.attribute("path", std::move(Path));
1184   // FIXME: This may not be useful information as it can be obtusely gleaned
1185   // from the inner[] array.
1186   if (const NamedDecl *ND = CE->getConversionFunction())
1187     JOS.attribute("conversionFunc", createBareDeclRef(ND));
1188 }
1189 
1190 void JSONNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
1191   VisitCastExpr(ICE);
1192   attributeOnlyIfTrue("isPartOfExplicitCast", ICE->isPartOfExplicitCast());
1193 }
1194 
1195 void JSONNodeDumper::VisitCallExpr(const CallExpr *CE) {
1196   attributeOnlyIfTrue("adl", CE->usesADL());
1197 }
1198 
1199 void JSONNodeDumper::VisitUnaryExprOrTypeTraitExpr(
1200     const UnaryExprOrTypeTraitExpr *TTE) {
1201   switch (TTE->getKind()) {
1202   case UETT_SizeOf: JOS.attribute("name", "sizeof"); break;
1203   case UETT_AlignOf: JOS.attribute("name", "alignof"); break;
1204   case UETT_VecStep:  JOS.attribute("name", "vec_step"); break;
1205   case UETT_PreferredAlignOf:  JOS.attribute("name", "__alignof"); break;
1206   case UETT_OpenMPRequiredSimdAlign:
1207     JOS.attribute("name", "__builtin_omp_required_simd_align"); break;
1208   }
1209   if (TTE->isArgumentType())
1210     JOS.attribute("argType", createQualType(TTE->getArgumentType()));
1211 }
1212 
1213 void JSONNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE) {
1214   VisitNamedDecl(SOPE->getPack());
1215 }
1216 
1217 void JSONNodeDumper::VisitUnresolvedLookupExpr(
1218     const UnresolvedLookupExpr *ULE) {
1219   JOS.attribute("usesADL", ULE->requiresADL());
1220   JOS.attribute("name", ULE->getName().getAsString());
1221 
1222   JOS.attributeArray("lookups", [this, ULE] {
1223     for (const NamedDecl *D : ULE->decls())
1224       JOS.value(createBareDeclRef(D));
1225   });
1226 }
1227 
1228 void JSONNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *ALE) {
1229   JOS.attribute("name", ALE->getLabel()->getName());
1230   JOS.attribute("labelDeclId", createPointerRepresentation(ALE->getLabel()));
1231 }
1232 
1233 void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) {
1234   if (CTE->isTypeOperand()) {
1235     QualType Adjusted = CTE->getTypeOperand(Ctx);
1236     QualType Unadjusted = CTE->getTypeOperandSourceInfo()->getType();
1237     JOS.attribute("typeArg", createQualType(Unadjusted));
1238     if (Adjusted != Unadjusted)
1239       JOS.attribute("adjustedTypeArg", createQualType(Adjusted));
1240   }
1241 }
1242 
1243 void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) {
1244   if (CE->getResultAPValueKind() != APValue::None) {
1245     std::string Str;
1246     llvm::raw_string_ostream OS(Str);
1247     CE->getAPValueResult().printPretty(OS, Ctx, CE->getType());
1248     JOS.attribute("value", OS.str());
1249   }
1250 }
1251 
1252 void JSONNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
1253   if (const FieldDecl *FD = ILE->getInitializedFieldInUnion())
1254     JOS.attribute("field", createBareDeclRef(FD));
1255 }
1256 
1257 void JSONNodeDumper::VisitGenericSelectionExpr(
1258     const GenericSelectionExpr *GSE) {
1259   attributeOnlyIfTrue("resultDependent", GSE->isResultDependent());
1260 }
1261 
1262 void JSONNodeDumper::VisitCXXUnresolvedConstructExpr(
1263     const CXXUnresolvedConstructExpr *UCE) {
1264   if (UCE->getType() != UCE->getTypeAsWritten())
1265     JOS.attribute("typeAsWritten", createQualType(UCE->getTypeAsWritten()));
1266   attributeOnlyIfTrue("list", UCE->isListInitialization());
1267 }
1268 
1269 void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) {
1270   CXXConstructorDecl *Ctor = CE->getConstructor();
1271   JOS.attribute("ctorType", createQualType(Ctor->getType()));
1272   attributeOnlyIfTrue("elidable", CE->isElidable());
1273   attributeOnlyIfTrue("list", CE->isListInitialization());
1274   attributeOnlyIfTrue("initializer_list", CE->isStdInitListInitialization());
1275   attributeOnlyIfTrue("zeroing", CE->requiresZeroInitialization());
1276   attributeOnlyIfTrue("hadMultipleCandidates", CE->hadMultipleCandidates());
1277 
1278   switch (CE->getConstructionKind()) {
1279   case CXXConstructExpr::CK_Complete:
1280     JOS.attribute("constructionKind", "complete");
1281     break;
1282   case CXXConstructExpr::CK_Delegating:
1283     JOS.attribute("constructionKind", "delegating");
1284     break;
1285   case CXXConstructExpr::CK_NonVirtualBase:
1286     JOS.attribute("constructionKind", "non-virtual base");
1287     break;
1288   case CXXConstructExpr::CK_VirtualBase:
1289     JOS.attribute("constructionKind", "virtual base");
1290     break;
1291   }
1292 }
1293 
1294 void JSONNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *EWC) {
1295   attributeOnlyIfTrue("cleanupsHaveSideEffects",
1296                       EWC->cleanupsHaveSideEffects());
1297   if (EWC->getNumObjects()) {
1298     JOS.attributeArray("cleanups", [this, EWC] {
1299       for (const ExprWithCleanups::CleanupObject &CO : EWC->getObjects())
1300         JOS.value(createBareDeclRef(CO));
1301     });
1302   }
1303 }
1304 
1305 void JSONNodeDumper::VisitCXXBindTemporaryExpr(
1306     const CXXBindTemporaryExpr *BTE) {
1307   const CXXTemporary *Temp = BTE->getTemporary();
1308   JOS.attribute("temp", createPointerRepresentation(Temp));
1309   if (const CXXDestructorDecl *Dtor = Temp->getDestructor())
1310     JOS.attribute("dtor", createBareDeclRef(Dtor));
1311 }
1312 
1313 void JSONNodeDumper::VisitMaterializeTemporaryExpr(
1314     const MaterializeTemporaryExpr *MTE) {
1315   if (const ValueDecl *VD = MTE->getExtendingDecl())
1316     JOS.attribute("extendingDecl", createBareDeclRef(VD));
1317 
1318   switch (MTE->getStorageDuration()) {
1319   case SD_Automatic:
1320     JOS.attribute("storageDuration", "automatic");
1321     break;
1322   case SD_Dynamic:
1323     JOS.attribute("storageDuration", "dynamic");
1324     break;
1325   case SD_FullExpression:
1326     JOS.attribute("storageDuration", "full expression");
1327     break;
1328   case SD_Static:
1329     JOS.attribute("storageDuration", "static");
1330     break;
1331   case SD_Thread:
1332     JOS.attribute("storageDuration", "thread");
1333     break;
1334   }
1335 
1336   attributeOnlyIfTrue("boundToLValueRef", MTE->isBoundToLvalueReference());
1337 }
1338 
1339 void JSONNodeDumper::VisitCXXDependentScopeMemberExpr(
1340     const CXXDependentScopeMemberExpr *DSME) {
1341   JOS.attribute("isArrow", DSME->isArrow());
1342   JOS.attribute("member", DSME->getMember().getAsString());
1343   attributeOnlyIfTrue("hasTemplateKeyword", DSME->hasTemplateKeyword());
1344   attributeOnlyIfTrue("hasExplicitTemplateArgs",
1345                       DSME->hasExplicitTemplateArgs());
1346 
1347   if (DSME->getNumTemplateArgs()) {
1348     JOS.attributeArray("explicitTemplateArgs", [DSME, this] {
1349       for (const TemplateArgumentLoc &TAL : DSME->template_arguments())
1350         JOS.object(
1351             [&TAL, this] { Visit(TAL.getArgument(), TAL.getSourceRange()); });
1352     });
1353   }
1354 }
1355 
1356 void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
1357   JOS.attribute("value",
1358                 IL->getValue().toString(
1359                     /*Radix=*/10, IL->getType()->isSignedIntegerType()));
1360 }
1361 void JSONNodeDumper::VisitCharacterLiteral(const CharacterLiteral *CL) {
1362   // FIXME: This should probably print the character literal as a string,
1363   // rather than as a numerical value. It would be nice if the behavior matched
1364   // what we do to print a string literal; right now, it is impossible to tell
1365   // the difference between 'a' and L'a' in C from the JSON output.
1366   JOS.attribute("value", CL->getValue());
1367 }
1368 void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) {
1369   JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10));
1370 }
1371 void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) {
1372   llvm::SmallVector<char, 16> Buffer;
1373   FL->getValue().toString(Buffer);
1374   JOS.attribute("value", Buffer);
1375 }
1376 void JSONNodeDumper::VisitStringLiteral(const StringLiteral *SL) {
1377   std::string Buffer;
1378   llvm::raw_string_ostream SS(Buffer);
1379   SL->outputString(SS);
1380   JOS.attribute("value", SS.str());
1381 }
1382 void JSONNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE) {
1383   JOS.attribute("value", BLE->getValue());
1384 }
1385 
1386 void JSONNodeDumper::VisitIfStmt(const IfStmt *IS) {
1387   attributeOnlyIfTrue("hasInit", IS->hasInitStorage());
1388   attributeOnlyIfTrue("hasVar", IS->hasVarStorage());
1389   attributeOnlyIfTrue("hasElse", IS->hasElseStorage());
1390   attributeOnlyIfTrue("isConstexpr", IS->isConstexpr());
1391 }
1392 
1393 void JSONNodeDumper::VisitSwitchStmt(const SwitchStmt *SS) {
1394   attributeOnlyIfTrue("hasInit", SS->hasInitStorage());
1395   attributeOnlyIfTrue("hasVar", SS->hasVarStorage());
1396 }
1397 void JSONNodeDumper::VisitCaseStmt(const CaseStmt *CS) {
1398   attributeOnlyIfTrue("isGNURange", CS->caseStmtIsGNURange());
1399 }
1400 
1401 void JSONNodeDumper::VisitLabelStmt(const LabelStmt *LS) {
1402   JOS.attribute("name", LS->getName());
1403   JOS.attribute("declId", createPointerRepresentation(LS->getDecl()));
1404 }
1405 void JSONNodeDumper::VisitGotoStmt(const GotoStmt *GS) {
1406   JOS.attribute("targetLabelDeclId",
1407                 createPointerRepresentation(GS->getLabel()));
1408 }
1409 
1410 void JSONNodeDumper::VisitWhileStmt(const WhileStmt *WS) {
1411   attributeOnlyIfTrue("hasVar", WS->hasVarStorage());
1412 }
1413 
1414 void JSONNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt* OACS) {
1415   // FIXME: it would be nice for the ASTNodeTraverser would handle the catch
1416   // parameter the same way for C++ and ObjC rather. In this case, C++ gets a
1417   // null child node and ObjC gets no child node.
1418   attributeOnlyIfTrue("isCatchAll", OACS->getCatchParamDecl() == nullptr);
1419 }
1420 
1421 void JSONNodeDumper::VisitNullTemplateArgument(const TemplateArgument &TA) {
1422   JOS.attribute("isNull", true);
1423 }
1424 void JSONNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
1425   JOS.attribute("type", createQualType(TA.getAsType()));
1426 }
1427 void JSONNodeDumper::VisitDeclarationTemplateArgument(
1428     const TemplateArgument &TA) {
1429   JOS.attribute("decl", createBareDeclRef(TA.getAsDecl()));
1430 }
1431 void JSONNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
1432   JOS.attribute("isNullptr", true);
1433 }
1434 void JSONNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
1435   JOS.attribute("value", TA.getAsIntegral().getSExtValue());
1436 }
1437 void JSONNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
1438   // FIXME: cannot just call dump() on the argument, as that doesn't specify
1439   // the output format.
1440 }
1441 void JSONNodeDumper::VisitTemplateExpansionTemplateArgument(
1442     const TemplateArgument &TA) {
1443   // FIXME: cannot just call dump() on the argument, as that doesn't specify
1444   // the output format.
1445 }
1446 void JSONNodeDumper::VisitExpressionTemplateArgument(
1447     const TemplateArgument &TA) {
1448   JOS.attribute("isExpr", true);
1449 }
1450 void JSONNodeDumper::VisitPackTemplateArgument(const TemplateArgument &TA) {
1451   JOS.attribute("isPack", true);
1452 }
1453 
1454 StringRef JSONNodeDumper::getCommentCommandName(unsigned CommandID) const {
1455   if (Traits)
1456     return Traits->getCommandInfo(CommandID)->Name;
1457   if (const comments::CommandInfo *Info =
1458           comments::CommandTraits::getBuiltinCommandInfo(CommandID))
1459     return Info->Name;
1460   return "<invalid>";
1461 }
1462 
1463 void JSONNodeDumper::visitTextComment(const comments::TextComment *C,
1464                                       const comments::FullComment *) {
1465   JOS.attribute("text", C->getText());
1466 }
1467 
1468 void JSONNodeDumper::visitInlineCommandComment(
1469     const comments::InlineCommandComment *C, const comments::FullComment *) {
1470   JOS.attribute("name", getCommentCommandName(C->getCommandID()));
1471 
1472   switch (C->getRenderKind()) {
1473   case comments::InlineCommandComment::RenderNormal:
1474     JOS.attribute("renderKind", "normal");
1475     break;
1476   case comments::InlineCommandComment::RenderBold:
1477     JOS.attribute("renderKind", "bold");
1478     break;
1479   case comments::InlineCommandComment::RenderEmphasized:
1480     JOS.attribute("renderKind", "emphasized");
1481     break;
1482   case comments::InlineCommandComment::RenderMonospaced:
1483     JOS.attribute("renderKind", "monospaced");
1484     break;
1485   }
1486 
1487   llvm::json::Array Args;
1488   for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I)
1489     Args.push_back(C->getArgText(I));
1490 
1491   if (!Args.empty())
1492     JOS.attribute("args", std::move(Args));
1493 }
1494 
1495 void JSONNodeDumper::visitHTMLStartTagComment(
1496     const comments::HTMLStartTagComment *C, const comments::FullComment *) {
1497   JOS.attribute("name", C->getTagName());
1498   attributeOnlyIfTrue("selfClosing", C->isSelfClosing());
1499   attributeOnlyIfTrue("malformed", C->isMalformed());
1500 
1501   llvm::json::Array Attrs;
1502   for (unsigned I = 0, E = C->getNumAttrs(); I < E; ++I)
1503     Attrs.push_back(
1504         {{"name", C->getAttr(I).Name}, {"value", C->getAttr(I).Value}});
1505 
1506   if (!Attrs.empty())
1507     JOS.attribute("attrs", std::move(Attrs));
1508 }
1509 
1510 void JSONNodeDumper::visitHTMLEndTagComment(
1511     const comments::HTMLEndTagComment *C, const comments::FullComment *) {
1512   JOS.attribute("name", C->getTagName());
1513 }
1514 
1515 void JSONNodeDumper::visitBlockCommandComment(
1516     const comments::BlockCommandComment *C, const comments::FullComment *) {
1517   JOS.attribute("name", getCommentCommandName(C->getCommandID()));
1518 
1519   llvm::json::Array Args;
1520   for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I)
1521     Args.push_back(C->getArgText(I));
1522 
1523   if (!Args.empty())
1524     JOS.attribute("args", std::move(Args));
1525 }
1526 
1527 void JSONNodeDumper::visitParamCommandComment(
1528     const comments::ParamCommandComment *C, const comments::FullComment *FC) {
1529   switch (C->getDirection()) {
1530   case comments::ParamCommandComment::In:
1531     JOS.attribute("direction", "in");
1532     break;
1533   case comments::ParamCommandComment::Out:
1534     JOS.attribute("direction", "out");
1535     break;
1536   case comments::ParamCommandComment::InOut:
1537     JOS.attribute("direction", "in,out");
1538     break;
1539   }
1540   attributeOnlyIfTrue("explicit", C->isDirectionExplicit());
1541 
1542   if (C->hasParamName())
1543     JOS.attribute("param", C->isParamIndexValid() ? C->getParamName(FC)
1544                                                   : C->getParamNameAsWritten());
1545 
1546   if (C->isParamIndexValid() && !C->isVarArgParam())
1547     JOS.attribute("paramIdx", C->getParamIndex());
1548 }
1549 
1550 void JSONNodeDumper::visitTParamCommandComment(
1551     const comments::TParamCommandComment *C, const comments::FullComment *FC) {
1552   if (C->hasParamName())
1553     JOS.attribute("param", C->isPositionValid() ? C->getParamName(FC)
1554                                                 : C->getParamNameAsWritten());
1555   if (C->isPositionValid()) {
1556     llvm::json::Array Positions;
1557     for (unsigned I = 0, E = C->getDepth(); I < E; ++I)
1558       Positions.push_back(C->getIndex(I));
1559 
1560     if (!Positions.empty())
1561       JOS.attribute("positions", std::move(Positions));
1562   }
1563 }
1564 
1565 void JSONNodeDumper::visitVerbatimBlockComment(
1566     const comments::VerbatimBlockComment *C, const comments::FullComment *) {
1567   JOS.attribute("name", getCommentCommandName(C->getCommandID()));
1568   JOS.attribute("closeName", C->getCloseName());
1569 }
1570 
1571 void JSONNodeDumper::visitVerbatimBlockLineComment(
1572     const comments::VerbatimBlockLineComment *C,
1573     const comments::FullComment *) {
1574   JOS.attribute("text", C->getText());
1575 }
1576 
1577 void JSONNodeDumper::visitVerbatimLineComment(
1578     const comments::VerbatimLineComment *C, const comments::FullComment *) {
1579   JOS.attribute("text", C->getText());
1580 }
1581