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()->castAs<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   case LinkageSpecDecl::lang_cxx_11:
854     Lang = "C++11";
855     break;
856   case LinkageSpecDecl::lang_cxx_14:
857     Lang = "C++14";
858     break;
859   }
860   JOS.attribute("language", Lang);
861   attributeOnlyIfTrue("hasBraces", LSD->hasBraces());
862 }
863 
864 void JSONNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *ASD) {
865   JOS.attribute("access", createAccessSpecifier(ASD->getAccess()));
866 }
867 
868 void JSONNodeDumper::VisitFriendDecl(const FriendDecl *FD) {
869   if (const TypeSourceInfo *T = FD->getFriendType())
870     JOS.attribute("type", createQualType(T->getType()));
871 }
872 
873 void JSONNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
874   VisitNamedDecl(D);
875   JOS.attribute("type", createQualType(D->getType()));
876   attributeOnlyIfTrue("synthesized", D->getSynthesize());
877   switch (D->getAccessControl()) {
878   case ObjCIvarDecl::None: JOS.attribute("access", "none"); break;
879   case ObjCIvarDecl::Private: JOS.attribute("access", "private"); break;
880   case ObjCIvarDecl::Protected: JOS.attribute("access", "protected"); break;
881   case ObjCIvarDecl::Public: JOS.attribute("access", "public"); break;
882   case ObjCIvarDecl::Package: JOS.attribute("access", "package"); break;
883   }
884 }
885 
886 void JSONNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
887   VisitNamedDecl(D);
888   JOS.attribute("returnType", createQualType(D->getReturnType()));
889   JOS.attribute("instance", D->isInstanceMethod());
890   attributeOnlyIfTrue("variadic", D->isVariadic());
891 }
892 
893 void JSONNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
894   VisitNamedDecl(D);
895   JOS.attribute("type", createQualType(D->getUnderlyingType()));
896   attributeOnlyIfTrue("bounded", D->hasExplicitBound());
897   switch (D->getVariance()) {
898   case ObjCTypeParamVariance::Invariant:
899     break;
900   case ObjCTypeParamVariance::Covariant:
901     JOS.attribute("variance", "covariant");
902     break;
903   case ObjCTypeParamVariance::Contravariant:
904     JOS.attribute("variance", "contravariant");
905     break;
906   }
907 }
908 
909 void JSONNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
910   VisitNamedDecl(D);
911   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
912   JOS.attribute("implementation", createBareDeclRef(D->getImplementation()));
913 
914   llvm::json::Array Protocols;
915   for (const auto* P : D->protocols())
916     Protocols.push_back(createBareDeclRef(P));
917   if (!Protocols.empty())
918     JOS.attribute("protocols", std::move(Protocols));
919 }
920 
921 void JSONNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
922   VisitNamedDecl(D);
923   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
924   JOS.attribute("categoryDecl", createBareDeclRef(D->getCategoryDecl()));
925 }
926 
927 void JSONNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
928   VisitNamedDecl(D);
929 
930   llvm::json::Array Protocols;
931   for (const auto *P : D->protocols())
932     Protocols.push_back(createBareDeclRef(P));
933   if (!Protocols.empty())
934     JOS.attribute("protocols", std::move(Protocols));
935 }
936 
937 void JSONNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
938   VisitNamedDecl(D);
939   JOS.attribute("super", createBareDeclRef(D->getSuperClass()));
940   JOS.attribute("implementation", createBareDeclRef(D->getImplementation()));
941 
942   llvm::json::Array Protocols;
943   for (const auto* P : D->protocols())
944     Protocols.push_back(createBareDeclRef(P));
945   if (!Protocols.empty())
946     JOS.attribute("protocols", std::move(Protocols));
947 }
948 
949 void JSONNodeDumper::VisitObjCImplementationDecl(
950     const ObjCImplementationDecl *D) {
951   VisitNamedDecl(D);
952   JOS.attribute("super", createBareDeclRef(D->getSuperClass()));
953   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
954 }
955 
956 void JSONNodeDumper::VisitObjCCompatibleAliasDecl(
957     const ObjCCompatibleAliasDecl *D) {
958   VisitNamedDecl(D);
959   JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
960 }
961 
962 void JSONNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
963   VisitNamedDecl(D);
964   JOS.attribute("type", createQualType(D->getType()));
965 
966   switch (D->getPropertyImplementation()) {
967   case ObjCPropertyDecl::None: break;
968   case ObjCPropertyDecl::Required: JOS.attribute("control", "required"); break;
969   case ObjCPropertyDecl::Optional: JOS.attribute("control", "optional"); break;
970   }
971 
972   ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
973   if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
974     if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
975       JOS.attribute("getter", createBareDeclRef(D->getGetterMethodDecl()));
976     if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
977       JOS.attribute("setter", createBareDeclRef(D->getSetterMethodDecl()));
978     attributeOnlyIfTrue("readonly", Attrs & ObjCPropertyDecl::OBJC_PR_readonly);
979     attributeOnlyIfTrue("assign", Attrs & ObjCPropertyDecl::OBJC_PR_assign);
980     attributeOnlyIfTrue("readwrite",
981                         Attrs & ObjCPropertyDecl::OBJC_PR_readwrite);
982     attributeOnlyIfTrue("retain", Attrs & ObjCPropertyDecl::OBJC_PR_retain);
983     attributeOnlyIfTrue("copy", Attrs & ObjCPropertyDecl::OBJC_PR_copy);
984     attributeOnlyIfTrue("nonatomic",
985                         Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic);
986     attributeOnlyIfTrue("atomic", Attrs & ObjCPropertyDecl::OBJC_PR_atomic);
987     attributeOnlyIfTrue("weak", Attrs & ObjCPropertyDecl::OBJC_PR_weak);
988     attributeOnlyIfTrue("strong", Attrs & ObjCPropertyDecl::OBJC_PR_strong);
989     attributeOnlyIfTrue("unsafe_unretained",
990                         Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained);
991     attributeOnlyIfTrue("class", Attrs & ObjCPropertyDecl::OBJC_PR_class);
992     attributeOnlyIfTrue("nullability",
993                         Attrs & ObjCPropertyDecl::OBJC_PR_nullability);
994     attributeOnlyIfTrue("null_resettable",
995                         Attrs & ObjCPropertyDecl::OBJC_PR_null_resettable);
996   }
997 }
998 
999 void JSONNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1000   VisitNamedDecl(D->getPropertyDecl());
1001   JOS.attribute("implKind", D->getPropertyImplementation() ==
1002                                     ObjCPropertyImplDecl::Synthesize
1003                                 ? "synthesize"
1004                                 : "dynamic");
1005   JOS.attribute("propertyDecl", createBareDeclRef(D->getPropertyDecl()));
1006   JOS.attribute("ivarDecl", createBareDeclRef(D->getPropertyIvarDecl()));
1007 }
1008 
1009 void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) {
1010   attributeOnlyIfTrue("variadic", D->isVariadic());
1011   attributeOnlyIfTrue("capturesThis", D->capturesCXXThis());
1012 }
1013 
1014 void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) {
1015   JOS.attribute("encodedType", createQualType(OEE->getEncodedType()));
1016 }
1017 
1018 void JSONNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *OME) {
1019   std::string Str;
1020   llvm::raw_string_ostream OS(Str);
1021 
1022   OME->getSelector().print(OS);
1023   JOS.attribute("selector", OS.str());
1024 
1025   switch (OME->getReceiverKind()) {
1026   case ObjCMessageExpr::Instance:
1027     JOS.attribute("receiverKind", "instance");
1028     break;
1029   case ObjCMessageExpr::Class:
1030     JOS.attribute("receiverKind", "class");
1031     JOS.attribute("classType", createQualType(OME->getClassReceiver()));
1032     break;
1033   case ObjCMessageExpr::SuperInstance:
1034     JOS.attribute("receiverKind", "super (instance)");
1035     JOS.attribute("superType", createQualType(OME->getSuperType()));
1036     break;
1037   case ObjCMessageExpr::SuperClass:
1038     JOS.attribute("receiverKind", "super (class)");
1039     JOS.attribute("superType", createQualType(OME->getSuperType()));
1040     break;
1041   }
1042 
1043   QualType CallReturnTy = OME->getCallReturnType(Ctx);
1044   if (OME->getType() != CallReturnTy)
1045     JOS.attribute("callReturnType", createQualType(CallReturnTy));
1046 }
1047 
1048 void JSONNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE) {
1049   if (const ObjCMethodDecl *MD = OBE->getBoxingMethod()) {
1050     std::string Str;
1051     llvm::raw_string_ostream OS(Str);
1052 
1053     MD->getSelector().print(OS);
1054     JOS.attribute("selector", OS.str());
1055   }
1056 }
1057 
1058 void JSONNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE) {
1059   std::string Str;
1060   llvm::raw_string_ostream OS(Str);
1061 
1062   OSE->getSelector().print(OS);
1063   JOS.attribute("selector", OS.str());
1064 }
1065 
1066 void JSONNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) {
1067   JOS.attribute("protocol", createBareDeclRef(OPE->getProtocol()));
1068 }
1069 
1070 void JSONNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) {
1071   if (OPRE->isImplicitProperty()) {
1072     JOS.attribute("propertyKind", "implicit");
1073     if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertyGetter())
1074       JOS.attribute("getter", createBareDeclRef(MD));
1075     if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertySetter())
1076       JOS.attribute("setter", createBareDeclRef(MD));
1077   } else {
1078     JOS.attribute("propertyKind", "explicit");
1079     JOS.attribute("property", createBareDeclRef(OPRE->getExplicitProperty()));
1080   }
1081 
1082   attributeOnlyIfTrue("isSuperReceiver", OPRE->isSuperReceiver());
1083   attributeOnlyIfTrue("isMessagingGetter", OPRE->isMessagingGetter());
1084   attributeOnlyIfTrue("isMessagingSetter", OPRE->isMessagingSetter());
1085 }
1086 
1087 void JSONNodeDumper::VisitObjCSubscriptRefExpr(
1088     const ObjCSubscriptRefExpr *OSRE) {
1089   JOS.attribute("subscriptKind",
1090                 OSRE->isArraySubscriptRefExpr() ? "array" : "dictionary");
1091 
1092   if (const ObjCMethodDecl *MD = OSRE->getAtIndexMethodDecl())
1093     JOS.attribute("getter", createBareDeclRef(MD));
1094   if (const ObjCMethodDecl *MD = OSRE->setAtIndexMethodDecl())
1095     JOS.attribute("setter", createBareDeclRef(MD));
1096 }
1097 
1098 void JSONNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE) {
1099   JOS.attribute("decl", createBareDeclRef(OIRE->getDecl()));
1100   attributeOnlyIfTrue("isFreeIvar", OIRE->isFreeIvar());
1101   JOS.attribute("isArrow", OIRE->isArrow());
1102 }
1103 
1104 void JSONNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE) {
1105   JOS.attribute("value", OBLE->getValue() ? "__objc_yes" : "__objc_no");
1106 }
1107 
1108 void JSONNodeDumper::VisitDeclRefExpr(const DeclRefExpr *DRE) {
1109   JOS.attribute("referencedDecl", createBareDeclRef(DRE->getDecl()));
1110   if (DRE->getDecl() != DRE->getFoundDecl())
1111     JOS.attribute("foundReferencedDecl",
1112                   createBareDeclRef(DRE->getFoundDecl()));
1113   switch (DRE->isNonOdrUse()) {
1114   case NOUR_None: break;
1115   case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break;
1116   case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
1117   case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
1118   }
1119 }
1120 
1121 void JSONNodeDumper::VisitPredefinedExpr(const PredefinedExpr *PE) {
1122   JOS.attribute("name", PredefinedExpr::getIdentKindName(PE->getIdentKind()));
1123 }
1124 
1125 void JSONNodeDumper::VisitUnaryOperator(const UnaryOperator *UO) {
1126   JOS.attribute("isPostfix", UO->isPostfix());
1127   JOS.attribute("opcode", UnaryOperator::getOpcodeStr(UO->getOpcode()));
1128   if (!UO->canOverflow())
1129     JOS.attribute("canOverflow", false);
1130 }
1131 
1132 void JSONNodeDumper::VisitBinaryOperator(const BinaryOperator *BO) {
1133   JOS.attribute("opcode", BinaryOperator::getOpcodeStr(BO->getOpcode()));
1134 }
1135 
1136 void JSONNodeDumper::VisitCompoundAssignOperator(
1137     const CompoundAssignOperator *CAO) {
1138   VisitBinaryOperator(CAO);
1139   JOS.attribute("computeLHSType", createQualType(CAO->getComputationLHSType()));
1140   JOS.attribute("computeResultType",
1141                 createQualType(CAO->getComputationResultType()));
1142 }
1143 
1144 void JSONNodeDumper::VisitMemberExpr(const MemberExpr *ME) {
1145   // Note, we always write this Boolean field because the information it conveys
1146   // is critical to understanding the AST node.
1147   ValueDecl *VD = ME->getMemberDecl();
1148   JOS.attribute("name", VD && VD->getDeclName() ? VD->getNameAsString() : "");
1149   JOS.attribute("isArrow", ME->isArrow());
1150   JOS.attribute("referencedMemberDecl", createPointerRepresentation(VD));
1151   switch (ME->isNonOdrUse()) {
1152   case NOUR_None: break;
1153   case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break;
1154   case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
1155   case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
1156   }
1157 }
1158 
1159 void JSONNodeDumper::VisitCXXNewExpr(const CXXNewExpr *NE) {
1160   attributeOnlyIfTrue("isGlobal", NE->isGlobalNew());
1161   attributeOnlyIfTrue("isArray", NE->isArray());
1162   attributeOnlyIfTrue("isPlacement", NE->getNumPlacementArgs() != 0);
1163   switch (NE->getInitializationStyle()) {
1164   case CXXNewExpr::NoInit: break;
1165   case CXXNewExpr::CallInit: JOS.attribute("initStyle", "call"); break;
1166   case CXXNewExpr::ListInit: JOS.attribute("initStyle", "list"); break;
1167   }
1168   if (const FunctionDecl *FD = NE->getOperatorNew())
1169     JOS.attribute("operatorNewDecl", createBareDeclRef(FD));
1170   if (const FunctionDecl *FD = NE->getOperatorDelete())
1171     JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD));
1172 }
1173 void JSONNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *DE) {
1174   attributeOnlyIfTrue("isGlobal", DE->isGlobalDelete());
1175   attributeOnlyIfTrue("isArray", DE->isArrayForm());
1176   attributeOnlyIfTrue("isArrayAsWritten", DE->isArrayFormAsWritten());
1177   if (const FunctionDecl *FD = DE->getOperatorDelete())
1178     JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD));
1179 }
1180 
1181 void JSONNodeDumper::VisitCXXThisExpr(const CXXThisExpr *TE) {
1182   attributeOnlyIfTrue("implicit", TE->isImplicit());
1183 }
1184 
1185 void JSONNodeDumper::VisitCastExpr(const CastExpr *CE) {
1186   JOS.attribute("castKind", CE->getCastKindName());
1187   llvm::json::Array Path = createCastPath(CE);
1188   if (!Path.empty())
1189     JOS.attribute("path", std::move(Path));
1190   // FIXME: This may not be useful information as it can be obtusely gleaned
1191   // from the inner[] array.
1192   if (const NamedDecl *ND = CE->getConversionFunction())
1193     JOS.attribute("conversionFunc", createBareDeclRef(ND));
1194 }
1195 
1196 void JSONNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
1197   VisitCastExpr(ICE);
1198   attributeOnlyIfTrue("isPartOfExplicitCast", ICE->isPartOfExplicitCast());
1199 }
1200 
1201 void JSONNodeDumper::VisitCallExpr(const CallExpr *CE) {
1202   attributeOnlyIfTrue("adl", CE->usesADL());
1203 }
1204 
1205 void JSONNodeDumper::VisitUnaryExprOrTypeTraitExpr(
1206     const UnaryExprOrTypeTraitExpr *TTE) {
1207   switch (TTE->getKind()) {
1208   case UETT_SizeOf: JOS.attribute("name", "sizeof"); break;
1209   case UETT_AlignOf: JOS.attribute("name", "alignof"); break;
1210   case UETT_VecStep:  JOS.attribute("name", "vec_step"); break;
1211   case UETT_PreferredAlignOf:  JOS.attribute("name", "__alignof"); break;
1212   case UETT_OpenMPRequiredSimdAlign:
1213     JOS.attribute("name", "__builtin_omp_required_simd_align"); break;
1214   }
1215   if (TTE->isArgumentType())
1216     JOS.attribute("argType", createQualType(TTE->getArgumentType()));
1217 }
1218 
1219 void JSONNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE) {
1220   VisitNamedDecl(SOPE->getPack());
1221 }
1222 
1223 void JSONNodeDumper::VisitUnresolvedLookupExpr(
1224     const UnresolvedLookupExpr *ULE) {
1225   JOS.attribute("usesADL", ULE->requiresADL());
1226   JOS.attribute("name", ULE->getName().getAsString());
1227 
1228   JOS.attributeArray("lookups", [this, ULE] {
1229     for (const NamedDecl *D : ULE->decls())
1230       JOS.value(createBareDeclRef(D));
1231   });
1232 }
1233 
1234 void JSONNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *ALE) {
1235   JOS.attribute("name", ALE->getLabel()->getName());
1236   JOS.attribute("labelDeclId", createPointerRepresentation(ALE->getLabel()));
1237 }
1238 
1239 void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) {
1240   if (CTE->isTypeOperand()) {
1241     QualType Adjusted = CTE->getTypeOperand(Ctx);
1242     QualType Unadjusted = CTE->getTypeOperandSourceInfo()->getType();
1243     JOS.attribute("typeArg", createQualType(Unadjusted));
1244     if (Adjusted != Unadjusted)
1245       JOS.attribute("adjustedTypeArg", createQualType(Adjusted));
1246   }
1247 }
1248 
1249 void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) {
1250   if (CE->getResultAPValueKind() != APValue::None) {
1251     std::string Str;
1252     llvm::raw_string_ostream OS(Str);
1253     CE->getAPValueResult().printPretty(OS, Ctx, CE->getType());
1254     JOS.attribute("value", OS.str());
1255   }
1256 }
1257 
1258 void JSONNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
1259   if (const FieldDecl *FD = ILE->getInitializedFieldInUnion())
1260     JOS.attribute("field", createBareDeclRef(FD));
1261 }
1262 
1263 void JSONNodeDumper::VisitGenericSelectionExpr(
1264     const GenericSelectionExpr *GSE) {
1265   attributeOnlyIfTrue("resultDependent", GSE->isResultDependent());
1266 }
1267 
1268 void JSONNodeDumper::VisitCXXUnresolvedConstructExpr(
1269     const CXXUnresolvedConstructExpr *UCE) {
1270   if (UCE->getType() != UCE->getTypeAsWritten())
1271     JOS.attribute("typeAsWritten", createQualType(UCE->getTypeAsWritten()));
1272   attributeOnlyIfTrue("list", UCE->isListInitialization());
1273 }
1274 
1275 void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) {
1276   CXXConstructorDecl *Ctor = CE->getConstructor();
1277   JOS.attribute("ctorType", createQualType(Ctor->getType()));
1278   attributeOnlyIfTrue("elidable", CE->isElidable());
1279   attributeOnlyIfTrue("list", CE->isListInitialization());
1280   attributeOnlyIfTrue("initializer_list", CE->isStdInitListInitialization());
1281   attributeOnlyIfTrue("zeroing", CE->requiresZeroInitialization());
1282   attributeOnlyIfTrue("hadMultipleCandidates", CE->hadMultipleCandidates());
1283 
1284   switch (CE->getConstructionKind()) {
1285   case CXXConstructExpr::CK_Complete:
1286     JOS.attribute("constructionKind", "complete");
1287     break;
1288   case CXXConstructExpr::CK_Delegating:
1289     JOS.attribute("constructionKind", "delegating");
1290     break;
1291   case CXXConstructExpr::CK_NonVirtualBase:
1292     JOS.attribute("constructionKind", "non-virtual base");
1293     break;
1294   case CXXConstructExpr::CK_VirtualBase:
1295     JOS.attribute("constructionKind", "virtual base");
1296     break;
1297   }
1298 }
1299 
1300 void JSONNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *EWC) {
1301   attributeOnlyIfTrue("cleanupsHaveSideEffects",
1302                       EWC->cleanupsHaveSideEffects());
1303   if (EWC->getNumObjects()) {
1304     JOS.attributeArray("cleanups", [this, EWC] {
1305       for (const ExprWithCleanups::CleanupObject &CO : EWC->getObjects())
1306         JOS.value(createBareDeclRef(CO));
1307     });
1308   }
1309 }
1310 
1311 void JSONNodeDumper::VisitCXXBindTemporaryExpr(
1312     const CXXBindTemporaryExpr *BTE) {
1313   const CXXTemporary *Temp = BTE->getTemporary();
1314   JOS.attribute("temp", createPointerRepresentation(Temp));
1315   if (const CXXDestructorDecl *Dtor = Temp->getDestructor())
1316     JOS.attribute("dtor", createBareDeclRef(Dtor));
1317 }
1318 
1319 void JSONNodeDumper::VisitMaterializeTemporaryExpr(
1320     const MaterializeTemporaryExpr *MTE) {
1321   if (const ValueDecl *VD = MTE->getExtendingDecl())
1322     JOS.attribute("extendingDecl", createBareDeclRef(VD));
1323 
1324   switch (MTE->getStorageDuration()) {
1325   case SD_Automatic:
1326     JOS.attribute("storageDuration", "automatic");
1327     break;
1328   case SD_Dynamic:
1329     JOS.attribute("storageDuration", "dynamic");
1330     break;
1331   case SD_FullExpression:
1332     JOS.attribute("storageDuration", "full expression");
1333     break;
1334   case SD_Static:
1335     JOS.attribute("storageDuration", "static");
1336     break;
1337   case SD_Thread:
1338     JOS.attribute("storageDuration", "thread");
1339     break;
1340   }
1341 
1342   attributeOnlyIfTrue("boundToLValueRef", MTE->isBoundToLvalueReference());
1343 }
1344 
1345 void JSONNodeDumper::VisitCXXDependentScopeMemberExpr(
1346     const CXXDependentScopeMemberExpr *DSME) {
1347   JOS.attribute("isArrow", DSME->isArrow());
1348   JOS.attribute("member", DSME->getMember().getAsString());
1349   attributeOnlyIfTrue("hasTemplateKeyword", DSME->hasTemplateKeyword());
1350   attributeOnlyIfTrue("hasExplicitTemplateArgs",
1351                       DSME->hasExplicitTemplateArgs());
1352 
1353   if (DSME->getNumTemplateArgs()) {
1354     JOS.attributeArray("explicitTemplateArgs", [DSME, this] {
1355       for (const TemplateArgumentLoc &TAL : DSME->template_arguments())
1356         JOS.object(
1357             [&TAL, this] { Visit(TAL.getArgument(), TAL.getSourceRange()); });
1358     });
1359   }
1360 }
1361 
1362 void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
1363   JOS.attribute("value",
1364                 IL->getValue().toString(
1365                     /*Radix=*/10, IL->getType()->isSignedIntegerType()));
1366 }
1367 void JSONNodeDumper::VisitCharacterLiteral(const CharacterLiteral *CL) {
1368   // FIXME: This should probably print the character literal as a string,
1369   // rather than as a numerical value. It would be nice if the behavior matched
1370   // what we do to print a string literal; right now, it is impossible to tell
1371   // the difference between 'a' and L'a' in C from the JSON output.
1372   JOS.attribute("value", CL->getValue());
1373 }
1374 void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) {
1375   JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10));
1376 }
1377 void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) {
1378   llvm::SmallVector<char, 16> Buffer;
1379   FL->getValue().toString(Buffer);
1380   JOS.attribute("value", Buffer);
1381 }
1382 void JSONNodeDumper::VisitStringLiteral(const StringLiteral *SL) {
1383   std::string Buffer;
1384   llvm::raw_string_ostream SS(Buffer);
1385   SL->outputString(SS);
1386   JOS.attribute("value", SS.str());
1387 }
1388 void JSONNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE) {
1389   JOS.attribute("value", BLE->getValue());
1390 }
1391 
1392 void JSONNodeDumper::VisitIfStmt(const IfStmt *IS) {
1393   attributeOnlyIfTrue("hasInit", IS->hasInitStorage());
1394   attributeOnlyIfTrue("hasVar", IS->hasVarStorage());
1395   attributeOnlyIfTrue("hasElse", IS->hasElseStorage());
1396   attributeOnlyIfTrue("isConstexpr", IS->isConstexpr());
1397 }
1398 
1399 void JSONNodeDumper::VisitSwitchStmt(const SwitchStmt *SS) {
1400   attributeOnlyIfTrue("hasInit", SS->hasInitStorage());
1401   attributeOnlyIfTrue("hasVar", SS->hasVarStorage());
1402 }
1403 void JSONNodeDumper::VisitCaseStmt(const CaseStmt *CS) {
1404   attributeOnlyIfTrue("isGNURange", CS->caseStmtIsGNURange());
1405 }
1406 
1407 void JSONNodeDumper::VisitLabelStmt(const LabelStmt *LS) {
1408   JOS.attribute("name", LS->getName());
1409   JOS.attribute("declId", createPointerRepresentation(LS->getDecl()));
1410 }
1411 void JSONNodeDumper::VisitGotoStmt(const GotoStmt *GS) {
1412   JOS.attribute("targetLabelDeclId",
1413                 createPointerRepresentation(GS->getLabel()));
1414 }
1415 
1416 void JSONNodeDumper::VisitWhileStmt(const WhileStmt *WS) {
1417   attributeOnlyIfTrue("hasVar", WS->hasVarStorage());
1418 }
1419 
1420 void JSONNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt* OACS) {
1421   // FIXME: it would be nice for the ASTNodeTraverser would handle the catch
1422   // parameter the same way for C++ and ObjC rather. In this case, C++ gets a
1423   // null child node and ObjC gets no child node.
1424   attributeOnlyIfTrue("isCatchAll", OACS->getCatchParamDecl() == nullptr);
1425 }
1426 
1427 void JSONNodeDumper::VisitNullTemplateArgument(const TemplateArgument &TA) {
1428   JOS.attribute("isNull", true);
1429 }
1430 void JSONNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
1431   JOS.attribute("type", createQualType(TA.getAsType()));
1432 }
1433 void JSONNodeDumper::VisitDeclarationTemplateArgument(
1434     const TemplateArgument &TA) {
1435   JOS.attribute("decl", createBareDeclRef(TA.getAsDecl()));
1436 }
1437 void JSONNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
1438   JOS.attribute("isNullptr", true);
1439 }
1440 void JSONNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
1441   JOS.attribute("value", TA.getAsIntegral().getSExtValue());
1442 }
1443 void JSONNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
1444   // FIXME: cannot just call dump() on the argument, as that doesn't specify
1445   // the output format.
1446 }
1447 void JSONNodeDumper::VisitTemplateExpansionTemplateArgument(
1448     const TemplateArgument &TA) {
1449   // FIXME: cannot just call dump() on the argument, as that doesn't specify
1450   // the output format.
1451 }
1452 void JSONNodeDumper::VisitExpressionTemplateArgument(
1453     const TemplateArgument &TA) {
1454   JOS.attribute("isExpr", true);
1455 }
1456 void JSONNodeDumper::VisitPackTemplateArgument(const TemplateArgument &TA) {
1457   JOS.attribute("isPack", true);
1458 }
1459 
1460 StringRef JSONNodeDumper::getCommentCommandName(unsigned CommandID) const {
1461   if (Traits)
1462     return Traits->getCommandInfo(CommandID)->Name;
1463   if (const comments::CommandInfo *Info =
1464           comments::CommandTraits::getBuiltinCommandInfo(CommandID))
1465     return Info->Name;
1466   return "<invalid>";
1467 }
1468 
1469 void JSONNodeDumper::visitTextComment(const comments::TextComment *C,
1470                                       const comments::FullComment *) {
1471   JOS.attribute("text", C->getText());
1472 }
1473 
1474 void JSONNodeDumper::visitInlineCommandComment(
1475     const comments::InlineCommandComment *C, const comments::FullComment *) {
1476   JOS.attribute("name", getCommentCommandName(C->getCommandID()));
1477 
1478   switch (C->getRenderKind()) {
1479   case comments::InlineCommandComment::RenderNormal:
1480     JOS.attribute("renderKind", "normal");
1481     break;
1482   case comments::InlineCommandComment::RenderBold:
1483     JOS.attribute("renderKind", "bold");
1484     break;
1485   case comments::InlineCommandComment::RenderEmphasized:
1486     JOS.attribute("renderKind", "emphasized");
1487     break;
1488   case comments::InlineCommandComment::RenderMonospaced:
1489     JOS.attribute("renderKind", "monospaced");
1490     break;
1491   }
1492 
1493   llvm::json::Array Args;
1494   for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I)
1495     Args.push_back(C->getArgText(I));
1496 
1497   if (!Args.empty())
1498     JOS.attribute("args", std::move(Args));
1499 }
1500 
1501 void JSONNodeDumper::visitHTMLStartTagComment(
1502     const comments::HTMLStartTagComment *C, const comments::FullComment *) {
1503   JOS.attribute("name", C->getTagName());
1504   attributeOnlyIfTrue("selfClosing", C->isSelfClosing());
1505   attributeOnlyIfTrue("malformed", C->isMalformed());
1506 
1507   llvm::json::Array Attrs;
1508   for (unsigned I = 0, E = C->getNumAttrs(); I < E; ++I)
1509     Attrs.push_back(
1510         {{"name", C->getAttr(I).Name}, {"value", C->getAttr(I).Value}});
1511 
1512   if (!Attrs.empty())
1513     JOS.attribute("attrs", std::move(Attrs));
1514 }
1515 
1516 void JSONNodeDumper::visitHTMLEndTagComment(
1517     const comments::HTMLEndTagComment *C, const comments::FullComment *) {
1518   JOS.attribute("name", C->getTagName());
1519 }
1520 
1521 void JSONNodeDumper::visitBlockCommandComment(
1522     const comments::BlockCommandComment *C, const comments::FullComment *) {
1523   JOS.attribute("name", getCommentCommandName(C->getCommandID()));
1524 
1525   llvm::json::Array Args;
1526   for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I)
1527     Args.push_back(C->getArgText(I));
1528 
1529   if (!Args.empty())
1530     JOS.attribute("args", std::move(Args));
1531 }
1532 
1533 void JSONNodeDumper::visitParamCommandComment(
1534     const comments::ParamCommandComment *C, const comments::FullComment *FC) {
1535   switch (C->getDirection()) {
1536   case comments::ParamCommandComment::In:
1537     JOS.attribute("direction", "in");
1538     break;
1539   case comments::ParamCommandComment::Out:
1540     JOS.attribute("direction", "out");
1541     break;
1542   case comments::ParamCommandComment::InOut:
1543     JOS.attribute("direction", "in,out");
1544     break;
1545   }
1546   attributeOnlyIfTrue("explicit", C->isDirectionExplicit());
1547 
1548   if (C->hasParamName())
1549     JOS.attribute("param", C->isParamIndexValid() ? C->getParamName(FC)
1550                                                   : C->getParamNameAsWritten());
1551 
1552   if (C->isParamIndexValid() && !C->isVarArgParam())
1553     JOS.attribute("paramIdx", C->getParamIndex());
1554 }
1555 
1556 void JSONNodeDumper::visitTParamCommandComment(
1557     const comments::TParamCommandComment *C, const comments::FullComment *FC) {
1558   if (C->hasParamName())
1559     JOS.attribute("param", C->isPositionValid() ? C->getParamName(FC)
1560                                                 : C->getParamNameAsWritten());
1561   if (C->isPositionValid()) {
1562     llvm::json::Array Positions;
1563     for (unsigned I = 0, E = C->getDepth(); I < E; ++I)
1564       Positions.push_back(C->getIndex(I));
1565 
1566     if (!Positions.empty())
1567       JOS.attribute("positions", std::move(Positions));
1568   }
1569 }
1570 
1571 void JSONNodeDumper::visitVerbatimBlockComment(
1572     const comments::VerbatimBlockComment *C, const comments::FullComment *) {
1573   JOS.attribute("name", getCommentCommandName(C->getCommandID()));
1574   JOS.attribute("closeName", C->getCloseName());
1575 }
1576 
1577 void JSONNodeDumper::visitVerbatimBlockLineComment(
1578     const comments::VerbatimBlockLineComment *C,
1579     const comments::FullComment *) {
1580   JOS.attribute("text", C->getText());
1581 }
1582 
1583 void JSONNodeDumper::visitVerbatimLineComment(
1584     const comments::VerbatimLineComment *C, const comments::FullComment *) {
1585   JOS.attribute("text", C->getText());
1586 }
1587