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