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