17330f729Sjoerg #include "clang/AST/JSONNodeDumper.h"
2*e038c9c4Sjoerg #include "clang/Basic/SourceManager.h"
3*e038c9c4Sjoerg #include "clang/Basic/Specifiers.h"
47330f729Sjoerg #include "clang/Lex/Lexer.h"
57330f729Sjoerg #include "llvm/ADT/StringSwitch.h"
67330f729Sjoerg
77330f729Sjoerg using namespace clang;
87330f729Sjoerg
addPreviousDeclaration(const Decl * D)97330f729Sjoerg void JSONNodeDumper::addPreviousDeclaration(const Decl *D) {
107330f729Sjoerg switch (D->getKind()) {
117330f729Sjoerg #define DECL(DERIVED, BASE) \
127330f729Sjoerg case Decl::DERIVED: \
137330f729Sjoerg return writePreviousDeclImpl(cast<DERIVED##Decl>(D));
147330f729Sjoerg #define ABSTRACT_DECL(DECL)
157330f729Sjoerg #include "clang/AST/DeclNodes.inc"
167330f729Sjoerg #undef ABSTRACT_DECL
177330f729Sjoerg #undef DECL
187330f729Sjoerg }
197330f729Sjoerg llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
207330f729Sjoerg }
217330f729Sjoerg
Visit(const Attr * A)227330f729Sjoerg void JSONNodeDumper::Visit(const Attr *A) {
237330f729Sjoerg const char *AttrName = nullptr;
247330f729Sjoerg switch (A->getKind()) {
257330f729Sjoerg #define ATTR(X) \
267330f729Sjoerg case attr::X: \
277330f729Sjoerg AttrName = #X"Attr"; \
287330f729Sjoerg break;
297330f729Sjoerg #include "clang/Basic/AttrList.inc"
307330f729Sjoerg #undef ATTR
317330f729Sjoerg }
327330f729Sjoerg JOS.attribute("id", createPointerRepresentation(A));
337330f729Sjoerg JOS.attribute("kind", AttrName);
347330f729Sjoerg JOS.attributeObject("range", [A, this] { writeSourceRange(A->getRange()); });
357330f729Sjoerg attributeOnlyIfTrue("inherited", A->isInherited());
367330f729Sjoerg attributeOnlyIfTrue("implicit", A->isImplicit());
377330f729Sjoerg
387330f729Sjoerg // FIXME: it would be useful for us to output the spelling kind as well as
397330f729Sjoerg // the actual spelling. This would allow us to distinguish between the
407330f729Sjoerg // various attribute syntaxes, but we don't currently track that information
417330f729Sjoerg // within the AST.
427330f729Sjoerg //JOS.attribute("spelling", A->getSpelling());
437330f729Sjoerg
447330f729Sjoerg InnerAttrVisitor::Visit(A);
457330f729Sjoerg }
467330f729Sjoerg
Visit(const Stmt * S)477330f729Sjoerg void JSONNodeDumper::Visit(const Stmt *S) {
487330f729Sjoerg if (!S)
497330f729Sjoerg return;
507330f729Sjoerg
517330f729Sjoerg JOS.attribute("id", createPointerRepresentation(S));
527330f729Sjoerg JOS.attribute("kind", S->getStmtClassName());
537330f729Sjoerg JOS.attributeObject("range",
547330f729Sjoerg [S, this] { writeSourceRange(S->getSourceRange()); });
557330f729Sjoerg
567330f729Sjoerg if (const auto *E = dyn_cast<Expr>(S)) {
577330f729Sjoerg JOS.attribute("type", createQualType(E->getType()));
587330f729Sjoerg const char *Category = nullptr;
597330f729Sjoerg switch (E->getValueKind()) {
607330f729Sjoerg case VK_LValue: Category = "lvalue"; break;
617330f729Sjoerg case VK_XValue: Category = "xvalue"; break;
627330f729Sjoerg case VK_RValue: Category = "rvalue"; break;
637330f729Sjoerg }
647330f729Sjoerg JOS.attribute("valueCategory", Category);
657330f729Sjoerg }
667330f729Sjoerg InnerStmtVisitor::Visit(S);
677330f729Sjoerg }
687330f729Sjoerg
Visit(const Type * T)697330f729Sjoerg void JSONNodeDumper::Visit(const Type *T) {
707330f729Sjoerg JOS.attribute("id", createPointerRepresentation(T));
717330f729Sjoerg
727330f729Sjoerg if (!T)
737330f729Sjoerg return;
747330f729Sjoerg
757330f729Sjoerg JOS.attribute("kind", (llvm::Twine(T->getTypeClassName()) + "Type").str());
767330f729Sjoerg JOS.attribute("type", createQualType(QualType(T, 0), /*Desugar*/ false));
77*e038c9c4Sjoerg attributeOnlyIfTrue("containsErrors", T->containsErrors());
787330f729Sjoerg attributeOnlyIfTrue("isDependent", T->isDependentType());
797330f729Sjoerg attributeOnlyIfTrue("isInstantiationDependent",
807330f729Sjoerg T->isInstantiationDependentType());
817330f729Sjoerg attributeOnlyIfTrue("isVariablyModified", T->isVariablyModifiedType());
827330f729Sjoerg attributeOnlyIfTrue("containsUnexpandedPack",
837330f729Sjoerg T->containsUnexpandedParameterPack());
847330f729Sjoerg attributeOnlyIfTrue("isImported", T->isFromAST());
857330f729Sjoerg InnerTypeVisitor::Visit(T);
867330f729Sjoerg }
877330f729Sjoerg
Visit(QualType T)887330f729Sjoerg void JSONNodeDumper::Visit(QualType T) {
897330f729Sjoerg JOS.attribute("id", createPointerRepresentation(T.getAsOpaquePtr()));
907330f729Sjoerg JOS.attribute("kind", "QualType");
917330f729Sjoerg JOS.attribute("type", createQualType(T));
927330f729Sjoerg JOS.attribute("qualifiers", T.split().Quals.getAsString());
937330f729Sjoerg }
947330f729Sjoerg
Visit(const Decl * D)957330f729Sjoerg void JSONNodeDumper::Visit(const Decl *D) {
967330f729Sjoerg JOS.attribute("id", createPointerRepresentation(D));
977330f729Sjoerg
987330f729Sjoerg if (!D)
997330f729Sjoerg return;
1007330f729Sjoerg
1017330f729Sjoerg JOS.attribute("kind", (llvm::Twine(D->getDeclKindName()) + "Decl").str());
1027330f729Sjoerg JOS.attributeObject("loc",
1037330f729Sjoerg [D, this] { writeSourceLocation(D->getLocation()); });
1047330f729Sjoerg JOS.attributeObject("range",
1057330f729Sjoerg [D, this] { writeSourceRange(D->getSourceRange()); });
1067330f729Sjoerg attributeOnlyIfTrue("isImplicit", D->isImplicit());
1077330f729Sjoerg attributeOnlyIfTrue("isInvalid", D->isInvalidDecl());
1087330f729Sjoerg
1097330f729Sjoerg if (D->isUsed())
1107330f729Sjoerg JOS.attribute("isUsed", true);
1117330f729Sjoerg else if (D->isThisDeclarationReferenced())
1127330f729Sjoerg JOS.attribute("isReferenced", true);
1137330f729Sjoerg
1147330f729Sjoerg if (const auto *ND = dyn_cast<NamedDecl>(D))
115*e038c9c4Sjoerg attributeOnlyIfTrue("isHidden", !ND->isUnconditionallyVisible());
1167330f729Sjoerg
1177330f729Sjoerg if (D->getLexicalDeclContext() != D->getDeclContext()) {
1187330f729Sjoerg // Because of multiple inheritance, a DeclContext pointer does not produce
1197330f729Sjoerg // the same pointer representation as a Decl pointer that references the
1207330f729Sjoerg // same AST Node.
1217330f729Sjoerg const auto *ParentDeclContextDecl = dyn_cast<Decl>(D->getDeclContext());
1227330f729Sjoerg JOS.attribute("parentDeclContextId",
1237330f729Sjoerg createPointerRepresentation(ParentDeclContextDecl));
1247330f729Sjoerg }
1257330f729Sjoerg
1267330f729Sjoerg addPreviousDeclaration(D);
1277330f729Sjoerg InnerDeclVisitor::Visit(D);
1287330f729Sjoerg }
1297330f729Sjoerg
Visit(const comments::Comment * C,const comments::FullComment * FC)1307330f729Sjoerg void JSONNodeDumper::Visit(const comments::Comment *C,
1317330f729Sjoerg const comments::FullComment *FC) {
1327330f729Sjoerg if (!C)
1337330f729Sjoerg return;
1347330f729Sjoerg
1357330f729Sjoerg JOS.attribute("id", createPointerRepresentation(C));
1367330f729Sjoerg JOS.attribute("kind", C->getCommentKindName());
1377330f729Sjoerg JOS.attributeObject("loc",
1387330f729Sjoerg [C, this] { writeSourceLocation(C->getLocation()); });
1397330f729Sjoerg JOS.attributeObject("range",
1407330f729Sjoerg [C, this] { writeSourceRange(C->getSourceRange()); });
1417330f729Sjoerg
1427330f729Sjoerg InnerCommentVisitor::visit(C, FC);
1437330f729Sjoerg }
1447330f729Sjoerg
Visit(const TemplateArgument & TA,SourceRange R,const Decl * From,StringRef Label)1457330f729Sjoerg void JSONNodeDumper::Visit(const TemplateArgument &TA, SourceRange R,
1467330f729Sjoerg const Decl *From, StringRef Label) {
1477330f729Sjoerg JOS.attribute("kind", "TemplateArgument");
1487330f729Sjoerg if (R.isValid())
1497330f729Sjoerg JOS.attributeObject("range", [R, this] { writeSourceRange(R); });
1507330f729Sjoerg
1517330f729Sjoerg if (From)
1527330f729Sjoerg JOS.attribute(Label.empty() ? "fromDecl" : Label, createBareDeclRef(From));
1537330f729Sjoerg
1547330f729Sjoerg InnerTemplateArgVisitor::Visit(TA);
1557330f729Sjoerg }
1567330f729Sjoerg
Visit(const CXXCtorInitializer * Init)1577330f729Sjoerg void JSONNodeDumper::Visit(const CXXCtorInitializer *Init) {
1587330f729Sjoerg JOS.attribute("kind", "CXXCtorInitializer");
1597330f729Sjoerg if (Init->isAnyMemberInitializer())
1607330f729Sjoerg JOS.attribute("anyInit", createBareDeclRef(Init->getAnyMember()));
1617330f729Sjoerg else if (Init->isBaseInitializer())
1627330f729Sjoerg JOS.attribute("baseInit",
1637330f729Sjoerg createQualType(QualType(Init->getBaseClass(), 0)));
1647330f729Sjoerg else if (Init->isDelegatingInitializer())
1657330f729Sjoerg JOS.attribute("delegatingInit",
1667330f729Sjoerg createQualType(Init->getTypeSourceInfo()->getType()));
1677330f729Sjoerg else
1687330f729Sjoerg llvm_unreachable("Unknown initializer type");
1697330f729Sjoerg }
1707330f729Sjoerg
Visit(const OMPClause * C)1717330f729Sjoerg void JSONNodeDumper::Visit(const OMPClause *C) {}
1727330f729Sjoerg
Visit(const BlockDecl::Capture & C)1737330f729Sjoerg void JSONNodeDumper::Visit(const BlockDecl::Capture &C) {
1747330f729Sjoerg JOS.attribute("kind", "Capture");
1757330f729Sjoerg attributeOnlyIfTrue("byref", C.isByRef());
1767330f729Sjoerg attributeOnlyIfTrue("nested", C.isNested());
1777330f729Sjoerg if (C.getVariable())
1787330f729Sjoerg JOS.attribute("var", createBareDeclRef(C.getVariable()));
1797330f729Sjoerg }
1807330f729Sjoerg
Visit(const GenericSelectionExpr::ConstAssociation & A)1817330f729Sjoerg void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
1827330f729Sjoerg JOS.attribute("associationKind", A.getTypeSourceInfo() ? "case" : "default");
1837330f729Sjoerg attributeOnlyIfTrue("selected", A.isSelected());
1847330f729Sjoerg }
1857330f729Sjoerg
Visit(const APValue & Value,QualType Ty)186*e038c9c4Sjoerg void JSONNodeDumper::Visit(const APValue &Value, QualType Ty) {
187*e038c9c4Sjoerg std::string Str;
188*e038c9c4Sjoerg llvm::raw_string_ostream OS(Str);
189*e038c9c4Sjoerg Value.printPretty(OS, Ctx, Ty);
190*e038c9c4Sjoerg JOS.attribute("value", OS.str());
191*e038c9c4Sjoerg }
192*e038c9c4Sjoerg
writeIncludeStack(PresumedLoc Loc,bool JustFirst)1937330f729Sjoerg void JSONNodeDumper::writeIncludeStack(PresumedLoc Loc, bool JustFirst) {
1947330f729Sjoerg if (Loc.isInvalid())
1957330f729Sjoerg return;
1967330f729Sjoerg
1977330f729Sjoerg JOS.attributeBegin("includedFrom");
1987330f729Sjoerg JOS.objectBegin();
1997330f729Sjoerg
2007330f729Sjoerg if (!JustFirst) {
2017330f729Sjoerg // Walk the stack recursively, then print out the presumed location.
2027330f729Sjoerg writeIncludeStack(SM.getPresumedLoc(Loc.getIncludeLoc()));
2037330f729Sjoerg }
2047330f729Sjoerg
2057330f729Sjoerg JOS.attribute("file", Loc.getFilename());
2067330f729Sjoerg JOS.objectEnd();
2077330f729Sjoerg JOS.attributeEnd();
2087330f729Sjoerg }
2097330f729Sjoerg
writeBareSourceLocation(SourceLocation Loc,bool IsSpelling)2107330f729Sjoerg void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc,
2117330f729Sjoerg bool IsSpelling) {
2127330f729Sjoerg PresumedLoc Presumed = SM.getPresumedLoc(Loc);
2137330f729Sjoerg unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc)
2147330f729Sjoerg : SM.getExpansionLineNumber(Loc);
215*e038c9c4Sjoerg StringRef ActualFile = SM.getBufferName(Loc);
216*e038c9c4Sjoerg
2177330f729Sjoerg if (Presumed.isValid()) {
2187330f729Sjoerg JOS.attribute("offset", SM.getDecomposedLoc(Loc).second);
219*e038c9c4Sjoerg if (LastLocFilename != ActualFile) {
220*e038c9c4Sjoerg JOS.attribute("file", ActualFile);
2217330f729Sjoerg JOS.attribute("line", ActualLine);
2227330f729Sjoerg } else if (LastLocLine != ActualLine)
2237330f729Sjoerg JOS.attribute("line", ActualLine);
2247330f729Sjoerg
225*e038c9c4Sjoerg StringRef PresumedFile = Presumed.getFilename();
226*e038c9c4Sjoerg if (PresumedFile != ActualFile && LastLocPresumedFilename != PresumedFile)
227*e038c9c4Sjoerg JOS.attribute("presumedFile", PresumedFile);
228*e038c9c4Sjoerg
2297330f729Sjoerg unsigned PresumedLine = Presumed.getLine();
2307330f729Sjoerg if (ActualLine != PresumedLine && LastLocPresumedLine != PresumedLine)
2317330f729Sjoerg JOS.attribute("presumedLine", PresumedLine);
2327330f729Sjoerg
2337330f729Sjoerg JOS.attribute("col", Presumed.getColumn());
2347330f729Sjoerg JOS.attribute("tokLen",
2357330f729Sjoerg Lexer::MeasureTokenLength(Loc, SM, Ctx.getLangOpts()));
236*e038c9c4Sjoerg LastLocFilename = ActualFile;
237*e038c9c4Sjoerg LastLocPresumedFilename = PresumedFile;
2387330f729Sjoerg LastLocPresumedLine = PresumedLine;
2397330f729Sjoerg LastLocLine = ActualLine;
2407330f729Sjoerg
2417330f729Sjoerg // Orthogonal to the file, line, and column de-duplication is whether the
2427330f729Sjoerg // given location was a result of an include. If so, print where the
2437330f729Sjoerg // include location came from.
2447330f729Sjoerg writeIncludeStack(SM.getPresumedLoc(Presumed.getIncludeLoc()),
2457330f729Sjoerg /*JustFirst*/ true);
2467330f729Sjoerg }
2477330f729Sjoerg }
2487330f729Sjoerg
writeSourceLocation(SourceLocation Loc)2497330f729Sjoerg void JSONNodeDumper::writeSourceLocation(SourceLocation Loc) {
2507330f729Sjoerg SourceLocation Spelling = SM.getSpellingLoc(Loc);
2517330f729Sjoerg SourceLocation Expansion = SM.getExpansionLoc(Loc);
2527330f729Sjoerg
2537330f729Sjoerg if (Expansion != Spelling) {
2547330f729Sjoerg // If the expansion and the spelling are different, output subobjects
2557330f729Sjoerg // describing both locations.
2567330f729Sjoerg JOS.attributeObject("spellingLoc", [Spelling, this] {
2577330f729Sjoerg writeBareSourceLocation(Spelling, /*IsSpelling*/ true);
2587330f729Sjoerg });
2597330f729Sjoerg JOS.attributeObject("expansionLoc", [Expansion, Loc, this] {
2607330f729Sjoerg writeBareSourceLocation(Expansion, /*IsSpelling*/ false);
2617330f729Sjoerg // If there is a macro expansion, add extra information if the interesting
2627330f729Sjoerg // bit is the macro arg expansion.
2637330f729Sjoerg if (SM.isMacroArgExpansion(Loc))
2647330f729Sjoerg JOS.attribute("isMacroArgExpansion", true);
2657330f729Sjoerg });
2667330f729Sjoerg } else
2677330f729Sjoerg writeBareSourceLocation(Spelling, /*IsSpelling*/ true);
2687330f729Sjoerg }
2697330f729Sjoerg
writeSourceRange(SourceRange R)2707330f729Sjoerg void JSONNodeDumper::writeSourceRange(SourceRange R) {
2717330f729Sjoerg JOS.attributeObject("begin",
2727330f729Sjoerg [R, this] { writeSourceLocation(R.getBegin()); });
2737330f729Sjoerg JOS.attributeObject("end", [R, this] { writeSourceLocation(R.getEnd()); });
2747330f729Sjoerg }
2757330f729Sjoerg
createPointerRepresentation(const void * Ptr)2767330f729Sjoerg std::string JSONNodeDumper::createPointerRepresentation(const void *Ptr) {
2777330f729Sjoerg // Because JSON stores integer values as signed 64-bit integers, trying to
2787330f729Sjoerg // represent them as such makes for very ugly pointer values in the resulting
2797330f729Sjoerg // output. Instead, we convert the value to hex and treat it as a string.
2807330f729Sjoerg return "0x" + llvm::utohexstr(reinterpret_cast<uint64_t>(Ptr), true);
2817330f729Sjoerg }
2827330f729Sjoerg
createQualType(QualType QT,bool Desugar)2837330f729Sjoerg llvm::json::Object JSONNodeDumper::createQualType(QualType QT, bool Desugar) {
2847330f729Sjoerg SplitQualType SQT = QT.split();
2857330f729Sjoerg llvm::json::Object Ret{{"qualType", QualType::getAsString(SQT, PrintPolicy)}};
2867330f729Sjoerg
2877330f729Sjoerg if (Desugar && !QT.isNull()) {
2887330f729Sjoerg SplitQualType DSQT = QT.getSplitDesugaredType();
2897330f729Sjoerg if (DSQT != SQT)
2907330f729Sjoerg Ret["desugaredQualType"] = QualType::getAsString(DSQT, PrintPolicy);
2917330f729Sjoerg if (const auto *TT = QT->getAs<TypedefType>())
2927330f729Sjoerg Ret["typeAliasDeclId"] = createPointerRepresentation(TT->getDecl());
2937330f729Sjoerg }
2947330f729Sjoerg return Ret;
2957330f729Sjoerg }
2967330f729Sjoerg
writeBareDeclRef(const Decl * D)2977330f729Sjoerg void JSONNodeDumper::writeBareDeclRef(const Decl *D) {
2987330f729Sjoerg JOS.attribute("id", createPointerRepresentation(D));
2997330f729Sjoerg if (!D)
3007330f729Sjoerg return;
3017330f729Sjoerg
3027330f729Sjoerg JOS.attribute("kind", (llvm::Twine(D->getDeclKindName()) + "Decl").str());
3037330f729Sjoerg if (const auto *ND = dyn_cast<NamedDecl>(D))
3047330f729Sjoerg JOS.attribute("name", ND->getDeclName().getAsString());
3057330f729Sjoerg if (const auto *VD = dyn_cast<ValueDecl>(D))
3067330f729Sjoerg JOS.attribute("type", createQualType(VD->getType()));
3077330f729Sjoerg }
3087330f729Sjoerg
createBareDeclRef(const Decl * D)3097330f729Sjoerg llvm::json::Object JSONNodeDumper::createBareDeclRef(const Decl *D) {
3107330f729Sjoerg llvm::json::Object Ret{{"id", createPointerRepresentation(D)}};
3117330f729Sjoerg if (!D)
3127330f729Sjoerg return Ret;
3137330f729Sjoerg
3147330f729Sjoerg Ret["kind"] = (llvm::Twine(D->getDeclKindName()) + "Decl").str();
3157330f729Sjoerg if (const auto *ND = dyn_cast<NamedDecl>(D))
3167330f729Sjoerg Ret["name"] = ND->getDeclName().getAsString();
3177330f729Sjoerg if (const auto *VD = dyn_cast<ValueDecl>(D))
3187330f729Sjoerg Ret["type"] = createQualType(VD->getType());
3197330f729Sjoerg return Ret;
3207330f729Sjoerg }
3217330f729Sjoerg
createCastPath(const CastExpr * C)3227330f729Sjoerg llvm::json::Array JSONNodeDumper::createCastPath(const CastExpr *C) {
3237330f729Sjoerg llvm::json::Array Ret;
3247330f729Sjoerg if (C->path_empty())
3257330f729Sjoerg return Ret;
3267330f729Sjoerg
3277330f729Sjoerg for (auto I = C->path_begin(), E = C->path_end(); I != E; ++I) {
3287330f729Sjoerg const CXXBaseSpecifier *Base = *I;
3297330f729Sjoerg const auto *RD =
3307330f729Sjoerg cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
3317330f729Sjoerg
3327330f729Sjoerg llvm::json::Object Val{{"name", RD->getName()}};
3337330f729Sjoerg if (Base->isVirtual())
3347330f729Sjoerg Val["isVirtual"] = true;
3357330f729Sjoerg Ret.push_back(std::move(Val));
3367330f729Sjoerg }
3377330f729Sjoerg return Ret;
3387330f729Sjoerg }
3397330f729Sjoerg
3407330f729Sjoerg #define FIELD2(Name, Flag) if (RD->Flag()) Ret[Name] = true
3417330f729Sjoerg #define FIELD1(Flag) FIELD2(#Flag, Flag)
3427330f729Sjoerg
3437330f729Sjoerg static llvm::json::Object
createDefaultConstructorDefinitionData(const CXXRecordDecl * RD)3447330f729Sjoerg createDefaultConstructorDefinitionData(const CXXRecordDecl *RD) {
3457330f729Sjoerg llvm::json::Object Ret;
3467330f729Sjoerg
3477330f729Sjoerg FIELD2("exists", hasDefaultConstructor);
3487330f729Sjoerg FIELD2("trivial", hasTrivialDefaultConstructor);
3497330f729Sjoerg FIELD2("nonTrivial", hasNonTrivialDefaultConstructor);
3507330f729Sjoerg FIELD2("userProvided", hasUserProvidedDefaultConstructor);
3517330f729Sjoerg FIELD2("isConstexpr", hasConstexprDefaultConstructor);
3527330f729Sjoerg FIELD2("needsImplicit", needsImplicitDefaultConstructor);
3537330f729Sjoerg FIELD2("defaultedIsConstexpr", defaultedDefaultConstructorIsConstexpr);
3547330f729Sjoerg
3557330f729Sjoerg return Ret;
3567330f729Sjoerg }
3577330f729Sjoerg
3587330f729Sjoerg static llvm::json::Object
createCopyConstructorDefinitionData(const CXXRecordDecl * RD)3597330f729Sjoerg createCopyConstructorDefinitionData(const CXXRecordDecl *RD) {
3607330f729Sjoerg llvm::json::Object Ret;
3617330f729Sjoerg
3627330f729Sjoerg FIELD2("simple", hasSimpleCopyConstructor);
3637330f729Sjoerg FIELD2("trivial", hasTrivialCopyConstructor);
3647330f729Sjoerg FIELD2("nonTrivial", hasNonTrivialCopyConstructor);
3657330f729Sjoerg FIELD2("userDeclared", hasUserDeclaredCopyConstructor);
3667330f729Sjoerg FIELD2("hasConstParam", hasCopyConstructorWithConstParam);
3677330f729Sjoerg FIELD2("implicitHasConstParam", implicitCopyConstructorHasConstParam);
3687330f729Sjoerg FIELD2("needsImplicit", needsImplicitCopyConstructor);
3697330f729Sjoerg FIELD2("needsOverloadResolution", needsOverloadResolutionForCopyConstructor);
3707330f729Sjoerg if (!RD->needsOverloadResolutionForCopyConstructor())
3717330f729Sjoerg FIELD2("defaultedIsDeleted", defaultedCopyConstructorIsDeleted);
3727330f729Sjoerg
3737330f729Sjoerg return Ret;
3747330f729Sjoerg }
3757330f729Sjoerg
3767330f729Sjoerg static llvm::json::Object
createMoveConstructorDefinitionData(const CXXRecordDecl * RD)3777330f729Sjoerg createMoveConstructorDefinitionData(const CXXRecordDecl *RD) {
3787330f729Sjoerg llvm::json::Object Ret;
3797330f729Sjoerg
3807330f729Sjoerg FIELD2("exists", hasMoveConstructor);
3817330f729Sjoerg FIELD2("simple", hasSimpleMoveConstructor);
3827330f729Sjoerg FIELD2("trivial", hasTrivialMoveConstructor);
3837330f729Sjoerg FIELD2("nonTrivial", hasNonTrivialMoveConstructor);
3847330f729Sjoerg FIELD2("userDeclared", hasUserDeclaredMoveConstructor);
3857330f729Sjoerg FIELD2("needsImplicit", needsImplicitMoveConstructor);
3867330f729Sjoerg FIELD2("needsOverloadResolution", needsOverloadResolutionForMoveConstructor);
3877330f729Sjoerg if (!RD->needsOverloadResolutionForMoveConstructor())
3887330f729Sjoerg FIELD2("defaultedIsDeleted", defaultedMoveConstructorIsDeleted);
3897330f729Sjoerg
3907330f729Sjoerg return Ret;
3917330f729Sjoerg }
3927330f729Sjoerg
3937330f729Sjoerg static llvm::json::Object
createCopyAssignmentDefinitionData(const CXXRecordDecl * RD)3947330f729Sjoerg createCopyAssignmentDefinitionData(const CXXRecordDecl *RD) {
3957330f729Sjoerg llvm::json::Object Ret;
3967330f729Sjoerg
397*e038c9c4Sjoerg FIELD2("simple", hasSimpleCopyAssignment);
3987330f729Sjoerg FIELD2("trivial", hasTrivialCopyAssignment);
3997330f729Sjoerg FIELD2("nonTrivial", hasNonTrivialCopyAssignment);
4007330f729Sjoerg FIELD2("hasConstParam", hasCopyAssignmentWithConstParam);
4017330f729Sjoerg FIELD2("implicitHasConstParam", implicitCopyAssignmentHasConstParam);
4027330f729Sjoerg FIELD2("userDeclared", hasUserDeclaredCopyAssignment);
4037330f729Sjoerg FIELD2("needsImplicit", needsImplicitCopyAssignment);
4047330f729Sjoerg FIELD2("needsOverloadResolution", needsOverloadResolutionForCopyAssignment);
4057330f729Sjoerg
4067330f729Sjoerg return Ret;
4077330f729Sjoerg }
4087330f729Sjoerg
4097330f729Sjoerg static llvm::json::Object
createMoveAssignmentDefinitionData(const CXXRecordDecl * RD)4107330f729Sjoerg createMoveAssignmentDefinitionData(const CXXRecordDecl *RD) {
4117330f729Sjoerg llvm::json::Object Ret;
4127330f729Sjoerg
4137330f729Sjoerg FIELD2("exists", hasMoveAssignment);
4147330f729Sjoerg FIELD2("simple", hasSimpleMoveAssignment);
4157330f729Sjoerg FIELD2("trivial", hasTrivialMoveAssignment);
4167330f729Sjoerg FIELD2("nonTrivial", hasNonTrivialMoveAssignment);
4177330f729Sjoerg FIELD2("userDeclared", hasUserDeclaredMoveAssignment);
4187330f729Sjoerg FIELD2("needsImplicit", needsImplicitMoveAssignment);
4197330f729Sjoerg FIELD2("needsOverloadResolution", needsOverloadResolutionForMoveAssignment);
4207330f729Sjoerg
4217330f729Sjoerg return Ret;
4227330f729Sjoerg }
4237330f729Sjoerg
4247330f729Sjoerg static llvm::json::Object
createDestructorDefinitionData(const CXXRecordDecl * RD)4257330f729Sjoerg createDestructorDefinitionData(const CXXRecordDecl *RD) {
4267330f729Sjoerg llvm::json::Object Ret;
4277330f729Sjoerg
4287330f729Sjoerg FIELD2("simple", hasSimpleDestructor);
4297330f729Sjoerg FIELD2("irrelevant", hasIrrelevantDestructor);
4307330f729Sjoerg FIELD2("trivial", hasTrivialDestructor);
4317330f729Sjoerg FIELD2("nonTrivial", hasNonTrivialDestructor);
4327330f729Sjoerg FIELD2("userDeclared", hasUserDeclaredDestructor);
4337330f729Sjoerg FIELD2("needsImplicit", needsImplicitDestructor);
4347330f729Sjoerg FIELD2("needsOverloadResolution", needsOverloadResolutionForDestructor);
4357330f729Sjoerg if (!RD->needsOverloadResolutionForDestructor())
4367330f729Sjoerg FIELD2("defaultedIsDeleted", defaultedDestructorIsDeleted);
4377330f729Sjoerg
4387330f729Sjoerg return Ret;
4397330f729Sjoerg }
4407330f729Sjoerg
4417330f729Sjoerg llvm::json::Object
createCXXRecordDefinitionData(const CXXRecordDecl * RD)4427330f729Sjoerg JSONNodeDumper::createCXXRecordDefinitionData(const CXXRecordDecl *RD) {
4437330f729Sjoerg llvm::json::Object Ret;
4447330f729Sjoerg
4457330f729Sjoerg // This data is common to all C++ classes.
4467330f729Sjoerg FIELD1(isGenericLambda);
4477330f729Sjoerg FIELD1(isLambda);
4487330f729Sjoerg FIELD1(isEmpty);
4497330f729Sjoerg FIELD1(isAggregate);
4507330f729Sjoerg FIELD1(isStandardLayout);
4517330f729Sjoerg FIELD1(isTriviallyCopyable);
4527330f729Sjoerg FIELD1(isPOD);
4537330f729Sjoerg FIELD1(isTrivial);
4547330f729Sjoerg FIELD1(isPolymorphic);
4557330f729Sjoerg FIELD1(isAbstract);
4567330f729Sjoerg FIELD1(isLiteral);
4577330f729Sjoerg FIELD1(canPassInRegisters);
4587330f729Sjoerg FIELD1(hasUserDeclaredConstructor);
4597330f729Sjoerg FIELD1(hasConstexprNonCopyMoveConstructor);
4607330f729Sjoerg FIELD1(hasMutableFields);
4617330f729Sjoerg FIELD1(hasVariantMembers);
4627330f729Sjoerg FIELD2("canConstDefaultInit", allowConstDefaultInit);
4637330f729Sjoerg
4647330f729Sjoerg Ret["defaultCtor"] = createDefaultConstructorDefinitionData(RD);
4657330f729Sjoerg Ret["copyCtor"] = createCopyConstructorDefinitionData(RD);
4667330f729Sjoerg Ret["moveCtor"] = createMoveConstructorDefinitionData(RD);
4677330f729Sjoerg Ret["copyAssign"] = createCopyAssignmentDefinitionData(RD);
4687330f729Sjoerg Ret["moveAssign"] = createMoveAssignmentDefinitionData(RD);
4697330f729Sjoerg Ret["dtor"] = createDestructorDefinitionData(RD);
4707330f729Sjoerg
4717330f729Sjoerg return Ret;
4727330f729Sjoerg }
4737330f729Sjoerg
4747330f729Sjoerg #undef FIELD1
4757330f729Sjoerg #undef FIELD2
4767330f729Sjoerg
createAccessSpecifier(AccessSpecifier AS)4777330f729Sjoerg std::string JSONNodeDumper::createAccessSpecifier(AccessSpecifier AS) {
478*e038c9c4Sjoerg const auto AccessSpelling = getAccessSpelling(AS);
479*e038c9c4Sjoerg if (AccessSpelling.empty())
480*e038c9c4Sjoerg return "none";
481*e038c9c4Sjoerg return AccessSpelling.str();
4827330f729Sjoerg }
4837330f729Sjoerg
4847330f729Sjoerg llvm::json::Object
createCXXBaseSpecifier(const CXXBaseSpecifier & BS)4857330f729Sjoerg JSONNodeDumper::createCXXBaseSpecifier(const CXXBaseSpecifier &BS) {
4867330f729Sjoerg llvm::json::Object Ret;
4877330f729Sjoerg
4887330f729Sjoerg Ret["type"] = createQualType(BS.getType());
4897330f729Sjoerg Ret["access"] = createAccessSpecifier(BS.getAccessSpecifier());
4907330f729Sjoerg Ret["writtenAccess"] =
4917330f729Sjoerg createAccessSpecifier(BS.getAccessSpecifierAsWritten());
4927330f729Sjoerg if (BS.isVirtual())
4937330f729Sjoerg Ret["isVirtual"] = true;
4947330f729Sjoerg if (BS.isPackExpansion())
4957330f729Sjoerg Ret["isPackExpansion"] = true;
4967330f729Sjoerg
4977330f729Sjoerg return Ret;
4987330f729Sjoerg }
4997330f729Sjoerg
VisitTypedefType(const TypedefType * TT)5007330f729Sjoerg void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
5017330f729Sjoerg JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
5027330f729Sjoerg }
5037330f729Sjoerg
VisitFunctionType(const FunctionType * T)5047330f729Sjoerg void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
5057330f729Sjoerg FunctionType::ExtInfo E = T->getExtInfo();
5067330f729Sjoerg attributeOnlyIfTrue("noreturn", E.getNoReturn());
5077330f729Sjoerg attributeOnlyIfTrue("producesResult", E.getProducesResult());
5087330f729Sjoerg if (E.getHasRegParm())
5097330f729Sjoerg JOS.attribute("regParm", E.getRegParm());
5107330f729Sjoerg JOS.attribute("cc", FunctionType::getNameForCallConv(E.getCC()));
5117330f729Sjoerg }
5127330f729Sjoerg
VisitFunctionProtoType(const FunctionProtoType * T)5137330f729Sjoerg void JSONNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
5147330f729Sjoerg FunctionProtoType::ExtProtoInfo E = T->getExtProtoInfo();
5157330f729Sjoerg attributeOnlyIfTrue("trailingReturn", E.HasTrailingReturn);
5167330f729Sjoerg attributeOnlyIfTrue("const", T->isConst());
5177330f729Sjoerg attributeOnlyIfTrue("volatile", T->isVolatile());
5187330f729Sjoerg attributeOnlyIfTrue("restrict", T->isRestrict());
5197330f729Sjoerg attributeOnlyIfTrue("variadic", E.Variadic);
5207330f729Sjoerg switch (E.RefQualifier) {
5217330f729Sjoerg case RQ_LValue: JOS.attribute("refQualifier", "&"); break;
5227330f729Sjoerg case RQ_RValue: JOS.attribute("refQualifier", "&&"); break;
5237330f729Sjoerg case RQ_None: break;
5247330f729Sjoerg }
5257330f729Sjoerg switch (E.ExceptionSpec.Type) {
5267330f729Sjoerg case EST_DynamicNone:
5277330f729Sjoerg case EST_Dynamic: {
5287330f729Sjoerg JOS.attribute("exceptionSpec", "throw");
5297330f729Sjoerg llvm::json::Array Types;
5307330f729Sjoerg for (QualType QT : E.ExceptionSpec.Exceptions)
5317330f729Sjoerg Types.push_back(createQualType(QT));
5327330f729Sjoerg JOS.attribute("exceptionTypes", std::move(Types));
5337330f729Sjoerg } break;
5347330f729Sjoerg case EST_MSAny:
5357330f729Sjoerg JOS.attribute("exceptionSpec", "throw");
5367330f729Sjoerg JOS.attribute("throwsAny", true);
5377330f729Sjoerg break;
5387330f729Sjoerg case EST_BasicNoexcept:
5397330f729Sjoerg JOS.attribute("exceptionSpec", "noexcept");
5407330f729Sjoerg break;
5417330f729Sjoerg case EST_NoexceptTrue:
5427330f729Sjoerg case EST_NoexceptFalse:
5437330f729Sjoerg JOS.attribute("exceptionSpec", "noexcept");
5447330f729Sjoerg JOS.attribute("conditionEvaluatesTo",
5457330f729Sjoerg E.ExceptionSpec.Type == EST_NoexceptTrue);
5467330f729Sjoerg //JOS.attributeWithCall("exceptionSpecExpr",
5477330f729Sjoerg // [this, E]() { Visit(E.ExceptionSpec.NoexceptExpr); });
5487330f729Sjoerg break;
5497330f729Sjoerg case EST_NoThrow:
5507330f729Sjoerg JOS.attribute("exceptionSpec", "nothrow");
5517330f729Sjoerg break;
5527330f729Sjoerg // FIXME: I cannot find a way to trigger these cases while dumping the AST. I
5537330f729Sjoerg // suspect you can only run into them when executing an AST dump from within
5547330f729Sjoerg // the debugger, which is not a use case we worry about for the JSON dumping
5557330f729Sjoerg // feature.
5567330f729Sjoerg case EST_DependentNoexcept:
5577330f729Sjoerg case EST_Unevaluated:
5587330f729Sjoerg case EST_Uninstantiated:
5597330f729Sjoerg case EST_Unparsed:
5607330f729Sjoerg case EST_None: break;
5617330f729Sjoerg }
5627330f729Sjoerg VisitFunctionType(T);
5637330f729Sjoerg }
5647330f729Sjoerg
VisitRValueReferenceType(const ReferenceType * RT)5657330f729Sjoerg void JSONNodeDumper::VisitRValueReferenceType(const ReferenceType *RT) {
5667330f729Sjoerg attributeOnlyIfTrue("spelledAsLValue", RT->isSpelledAsLValue());
5677330f729Sjoerg }
5687330f729Sjoerg
VisitArrayType(const ArrayType * AT)5697330f729Sjoerg void JSONNodeDumper::VisitArrayType(const ArrayType *AT) {
5707330f729Sjoerg switch (AT->getSizeModifier()) {
5717330f729Sjoerg case ArrayType::Star:
5727330f729Sjoerg JOS.attribute("sizeModifier", "*");
5737330f729Sjoerg break;
5747330f729Sjoerg case ArrayType::Static:
5757330f729Sjoerg JOS.attribute("sizeModifier", "static");
5767330f729Sjoerg break;
5777330f729Sjoerg case ArrayType::Normal:
5787330f729Sjoerg break;
5797330f729Sjoerg }
5807330f729Sjoerg
5817330f729Sjoerg std::string Str = AT->getIndexTypeQualifiers().getAsString();
5827330f729Sjoerg if (!Str.empty())
5837330f729Sjoerg JOS.attribute("indexTypeQualifiers", Str);
5847330f729Sjoerg }
5857330f729Sjoerg
VisitConstantArrayType(const ConstantArrayType * CAT)5867330f729Sjoerg void JSONNodeDumper::VisitConstantArrayType(const ConstantArrayType *CAT) {
5877330f729Sjoerg // FIXME: this should use ZExt instead of SExt, but JSON doesn't allow a
5887330f729Sjoerg // narrowing conversion to int64_t so it cannot be expressed.
5897330f729Sjoerg JOS.attribute("size", CAT->getSize().getSExtValue());
5907330f729Sjoerg VisitArrayType(CAT);
5917330f729Sjoerg }
5927330f729Sjoerg
VisitDependentSizedExtVectorType(const DependentSizedExtVectorType * VT)5937330f729Sjoerg void JSONNodeDumper::VisitDependentSizedExtVectorType(
5947330f729Sjoerg const DependentSizedExtVectorType *VT) {
5957330f729Sjoerg JOS.attributeObject(
5967330f729Sjoerg "attrLoc", [VT, this] { writeSourceLocation(VT->getAttributeLoc()); });
5977330f729Sjoerg }
5987330f729Sjoerg
VisitVectorType(const VectorType * VT)5997330f729Sjoerg void JSONNodeDumper::VisitVectorType(const VectorType *VT) {
6007330f729Sjoerg JOS.attribute("numElements", VT->getNumElements());
6017330f729Sjoerg switch (VT->getVectorKind()) {
6027330f729Sjoerg case VectorType::GenericVector:
6037330f729Sjoerg break;
6047330f729Sjoerg case VectorType::AltiVecVector:
6057330f729Sjoerg JOS.attribute("vectorKind", "altivec");
6067330f729Sjoerg break;
6077330f729Sjoerg case VectorType::AltiVecPixel:
6087330f729Sjoerg JOS.attribute("vectorKind", "altivec pixel");
6097330f729Sjoerg break;
6107330f729Sjoerg case VectorType::AltiVecBool:
6117330f729Sjoerg JOS.attribute("vectorKind", "altivec bool");
6127330f729Sjoerg break;
6137330f729Sjoerg case VectorType::NeonVector:
6147330f729Sjoerg JOS.attribute("vectorKind", "neon");
6157330f729Sjoerg break;
6167330f729Sjoerg case VectorType::NeonPolyVector:
6177330f729Sjoerg JOS.attribute("vectorKind", "neon poly");
6187330f729Sjoerg break;
619*e038c9c4Sjoerg case VectorType::SveFixedLengthDataVector:
620*e038c9c4Sjoerg JOS.attribute("vectorKind", "fixed-length sve data vector");
621*e038c9c4Sjoerg break;
622*e038c9c4Sjoerg case VectorType::SveFixedLengthPredicateVector:
623*e038c9c4Sjoerg JOS.attribute("vectorKind", "fixed-length sve predicate vector");
624*e038c9c4Sjoerg break;
6257330f729Sjoerg }
6267330f729Sjoerg }
6277330f729Sjoerg
VisitUnresolvedUsingType(const UnresolvedUsingType * UUT)6287330f729Sjoerg void JSONNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *UUT) {
6297330f729Sjoerg JOS.attribute("decl", createBareDeclRef(UUT->getDecl()));
6307330f729Sjoerg }
6317330f729Sjoerg
VisitUnaryTransformType(const UnaryTransformType * UTT)6327330f729Sjoerg void JSONNodeDumper::VisitUnaryTransformType(const UnaryTransformType *UTT) {
6337330f729Sjoerg switch (UTT->getUTTKind()) {
6347330f729Sjoerg case UnaryTransformType::EnumUnderlyingType:
6357330f729Sjoerg JOS.attribute("transformKind", "underlying_type");
6367330f729Sjoerg break;
6377330f729Sjoerg }
6387330f729Sjoerg }
6397330f729Sjoerg
VisitTagType(const TagType * TT)6407330f729Sjoerg void JSONNodeDumper::VisitTagType(const TagType *TT) {
6417330f729Sjoerg JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
6427330f729Sjoerg }
6437330f729Sjoerg
VisitTemplateTypeParmType(const TemplateTypeParmType * TTPT)6447330f729Sjoerg void JSONNodeDumper::VisitTemplateTypeParmType(
6457330f729Sjoerg const TemplateTypeParmType *TTPT) {
6467330f729Sjoerg JOS.attribute("depth", TTPT->getDepth());
6477330f729Sjoerg JOS.attribute("index", TTPT->getIndex());
6487330f729Sjoerg attributeOnlyIfTrue("isPack", TTPT->isParameterPack());
6497330f729Sjoerg JOS.attribute("decl", createBareDeclRef(TTPT->getDecl()));
6507330f729Sjoerg }
6517330f729Sjoerg
VisitAutoType(const AutoType * AT)6527330f729Sjoerg void JSONNodeDumper::VisitAutoType(const AutoType *AT) {
6537330f729Sjoerg JOS.attribute("undeduced", !AT->isDeduced());
6547330f729Sjoerg switch (AT->getKeyword()) {
6557330f729Sjoerg case AutoTypeKeyword::Auto:
6567330f729Sjoerg JOS.attribute("typeKeyword", "auto");
6577330f729Sjoerg break;
6587330f729Sjoerg case AutoTypeKeyword::DecltypeAuto:
6597330f729Sjoerg JOS.attribute("typeKeyword", "decltype(auto)");
6607330f729Sjoerg break;
6617330f729Sjoerg case AutoTypeKeyword::GNUAutoType:
6627330f729Sjoerg JOS.attribute("typeKeyword", "__auto_type");
6637330f729Sjoerg break;
6647330f729Sjoerg }
6657330f729Sjoerg }
6667330f729Sjoerg
VisitTemplateSpecializationType(const TemplateSpecializationType * TST)6677330f729Sjoerg void JSONNodeDumper::VisitTemplateSpecializationType(
6687330f729Sjoerg const TemplateSpecializationType *TST) {
6697330f729Sjoerg attributeOnlyIfTrue("isAlias", TST->isTypeAlias());
6707330f729Sjoerg
6717330f729Sjoerg std::string Str;
6727330f729Sjoerg llvm::raw_string_ostream OS(Str);
6737330f729Sjoerg TST->getTemplateName().print(OS, PrintPolicy);
6747330f729Sjoerg JOS.attribute("templateName", OS.str());
6757330f729Sjoerg }
6767330f729Sjoerg
VisitInjectedClassNameType(const InjectedClassNameType * ICNT)6777330f729Sjoerg void JSONNodeDumper::VisitInjectedClassNameType(
6787330f729Sjoerg const InjectedClassNameType *ICNT) {
6797330f729Sjoerg JOS.attribute("decl", createBareDeclRef(ICNT->getDecl()));
6807330f729Sjoerg }
6817330f729Sjoerg
VisitObjCInterfaceType(const ObjCInterfaceType * OIT)6827330f729Sjoerg void JSONNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
6837330f729Sjoerg JOS.attribute("decl", createBareDeclRef(OIT->getDecl()));
6847330f729Sjoerg }
6857330f729Sjoerg
VisitPackExpansionType(const PackExpansionType * PET)6867330f729Sjoerg void JSONNodeDumper::VisitPackExpansionType(const PackExpansionType *PET) {
6877330f729Sjoerg if (llvm::Optional<unsigned> N = PET->getNumExpansions())
6887330f729Sjoerg JOS.attribute("numExpansions", *N);
6897330f729Sjoerg }
6907330f729Sjoerg
VisitElaboratedType(const ElaboratedType * ET)6917330f729Sjoerg void JSONNodeDumper::VisitElaboratedType(const ElaboratedType *ET) {
6927330f729Sjoerg if (const NestedNameSpecifier *NNS = ET->getQualifier()) {
6937330f729Sjoerg std::string Str;
6947330f729Sjoerg llvm::raw_string_ostream OS(Str);
6957330f729Sjoerg NNS->print(OS, PrintPolicy, /*ResolveTemplateArgs*/ true);
6967330f729Sjoerg JOS.attribute("qualifier", OS.str());
6977330f729Sjoerg }
6987330f729Sjoerg if (const TagDecl *TD = ET->getOwnedTagDecl())
6997330f729Sjoerg JOS.attribute("ownedTagDecl", createBareDeclRef(TD));
7007330f729Sjoerg }
7017330f729Sjoerg
VisitMacroQualifiedType(const MacroQualifiedType * MQT)7027330f729Sjoerg void JSONNodeDumper::VisitMacroQualifiedType(const MacroQualifiedType *MQT) {
7037330f729Sjoerg JOS.attribute("macroName", MQT->getMacroIdentifier()->getName());
7047330f729Sjoerg }
7057330f729Sjoerg
VisitMemberPointerType(const MemberPointerType * MPT)7067330f729Sjoerg void JSONNodeDumper::VisitMemberPointerType(const MemberPointerType *MPT) {
7077330f729Sjoerg attributeOnlyIfTrue("isData", MPT->isMemberDataPointer());
7087330f729Sjoerg attributeOnlyIfTrue("isFunction", MPT->isMemberFunctionPointer());
7097330f729Sjoerg }
7107330f729Sjoerg
VisitNamedDecl(const NamedDecl * ND)7117330f729Sjoerg void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
712*e038c9c4Sjoerg if (ND && ND->getDeclName()) {
7137330f729Sjoerg JOS.attribute("name", ND->getNameAsString());
714*e038c9c4Sjoerg std::string MangledName = ASTNameGen.getName(ND);
715*e038c9c4Sjoerg if (!MangledName.empty())
716*e038c9c4Sjoerg JOS.attribute("mangledName", MangledName);
717*e038c9c4Sjoerg }
7187330f729Sjoerg }
7197330f729Sjoerg
VisitTypedefDecl(const TypedefDecl * TD)7207330f729Sjoerg void JSONNodeDumper::VisitTypedefDecl(const TypedefDecl *TD) {
7217330f729Sjoerg VisitNamedDecl(TD);
7227330f729Sjoerg JOS.attribute("type", createQualType(TD->getUnderlyingType()));
7237330f729Sjoerg }
7247330f729Sjoerg
VisitTypeAliasDecl(const TypeAliasDecl * TAD)7257330f729Sjoerg void JSONNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *TAD) {
7267330f729Sjoerg VisitNamedDecl(TAD);
7277330f729Sjoerg JOS.attribute("type", createQualType(TAD->getUnderlyingType()));
7287330f729Sjoerg }
7297330f729Sjoerg
VisitNamespaceDecl(const NamespaceDecl * ND)7307330f729Sjoerg void JSONNodeDumper::VisitNamespaceDecl(const NamespaceDecl *ND) {
7317330f729Sjoerg VisitNamedDecl(ND);
7327330f729Sjoerg attributeOnlyIfTrue("isInline", ND->isInline());
7337330f729Sjoerg if (!ND->isOriginalNamespace())
7347330f729Sjoerg JOS.attribute("originalNamespace",
7357330f729Sjoerg createBareDeclRef(ND->getOriginalNamespace()));
7367330f729Sjoerg }
7377330f729Sjoerg
VisitUsingDirectiveDecl(const UsingDirectiveDecl * UDD)7387330f729Sjoerg void JSONNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD) {
7397330f729Sjoerg JOS.attribute("nominatedNamespace",
7407330f729Sjoerg createBareDeclRef(UDD->getNominatedNamespace()));
7417330f729Sjoerg }
7427330f729Sjoerg
VisitNamespaceAliasDecl(const NamespaceAliasDecl * NAD)7437330f729Sjoerg void JSONNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD) {
7447330f729Sjoerg VisitNamedDecl(NAD);
7457330f729Sjoerg JOS.attribute("aliasedNamespace",
7467330f729Sjoerg createBareDeclRef(NAD->getAliasedNamespace()));
7477330f729Sjoerg }
7487330f729Sjoerg
VisitUsingDecl(const UsingDecl * UD)7497330f729Sjoerg void JSONNodeDumper::VisitUsingDecl(const UsingDecl *UD) {
7507330f729Sjoerg std::string Name;
7517330f729Sjoerg if (const NestedNameSpecifier *NNS = UD->getQualifier()) {
7527330f729Sjoerg llvm::raw_string_ostream SOS(Name);
7537330f729Sjoerg NNS->print(SOS, UD->getASTContext().getPrintingPolicy());
7547330f729Sjoerg }
7557330f729Sjoerg Name += UD->getNameAsString();
7567330f729Sjoerg JOS.attribute("name", Name);
7577330f729Sjoerg }
7587330f729Sjoerg
VisitUsingShadowDecl(const UsingShadowDecl * USD)7597330f729Sjoerg void JSONNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *USD) {
7607330f729Sjoerg JOS.attribute("target", createBareDeclRef(USD->getTargetDecl()));
7617330f729Sjoerg }
7627330f729Sjoerg
VisitVarDecl(const VarDecl * VD)7637330f729Sjoerg void JSONNodeDumper::VisitVarDecl(const VarDecl *VD) {
7647330f729Sjoerg VisitNamedDecl(VD);
7657330f729Sjoerg JOS.attribute("type", createQualType(VD->getType()));
7667330f729Sjoerg
7677330f729Sjoerg StorageClass SC = VD->getStorageClass();
7687330f729Sjoerg if (SC != SC_None)
7697330f729Sjoerg JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC));
7707330f729Sjoerg switch (VD->getTLSKind()) {
7717330f729Sjoerg case VarDecl::TLS_Dynamic: JOS.attribute("tls", "dynamic"); break;
7727330f729Sjoerg case VarDecl::TLS_Static: JOS.attribute("tls", "static"); break;
7737330f729Sjoerg case VarDecl::TLS_None: break;
7747330f729Sjoerg }
7757330f729Sjoerg attributeOnlyIfTrue("nrvo", VD->isNRVOVariable());
7767330f729Sjoerg attributeOnlyIfTrue("inline", VD->isInline());
7777330f729Sjoerg attributeOnlyIfTrue("constexpr", VD->isConstexpr());
7787330f729Sjoerg attributeOnlyIfTrue("modulePrivate", VD->isModulePrivate());
7797330f729Sjoerg if (VD->hasInit()) {
7807330f729Sjoerg switch (VD->getInitStyle()) {
7817330f729Sjoerg case VarDecl::CInit: JOS.attribute("init", "c"); break;
7827330f729Sjoerg case VarDecl::CallInit: JOS.attribute("init", "call"); break;
7837330f729Sjoerg case VarDecl::ListInit: JOS.attribute("init", "list"); break;
7847330f729Sjoerg }
7857330f729Sjoerg }
7867330f729Sjoerg attributeOnlyIfTrue("isParameterPack", VD->isParameterPack());
7877330f729Sjoerg }
7887330f729Sjoerg
VisitFieldDecl(const FieldDecl * FD)7897330f729Sjoerg void JSONNodeDumper::VisitFieldDecl(const FieldDecl *FD) {
7907330f729Sjoerg VisitNamedDecl(FD);
7917330f729Sjoerg JOS.attribute("type", createQualType(FD->getType()));
7927330f729Sjoerg attributeOnlyIfTrue("mutable", FD->isMutable());
7937330f729Sjoerg attributeOnlyIfTrue("modulePrivate", FD->isModulePrivate());
7947330f729Sjoerg attributeOnlyIfTrue("isBitfield", FD->isBitField());
7957330f729Sjoerg attributeOnlyIfTrue("hasInClassInitializer", FD->hasInClassInitializer());
7967330f729Sjoerg }
7977330f729Sjoerg
VisitFunctionDecl(const FunctionDecl * FD)7987330f729Sjoerg void JSONNodeDumper::VisitFunctionDecl(const FunctionDecl *FD) {
7997330f729Sjoerg VisitNamedDecl(FD);
8007330f729Sjoerg JOS.attribute("type", createQualType(FD->getType()));
8017330f729Sjoerg StorageClass SC = FD->getStorageClass();
8027330f729Sjoerg if (SC != SC_None)
8037330f729Sjoerg JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC));
8047330f729Sjoerg attributeOnlyIfTrue("inline", FD->isInlineSpecified());
8057330f729Sjoerg attributeOnlyIfTrue("virtual", FD->isVirtualAsWritten());
8067330f729Sjoerg attributeOnlyIfTrue("pure", FD->isPure());
8077330f729Sjoerg attributeOnlyIfTrue("explicitlyDeleted", FD->isDeletedAsWritten());
8087330f729Sjoerg attributeOnlyIfTrue("constexpr", FD->isConstexpr());
8097330f729Sjoerg attributeOnlyIfTrue("variadic", FD->isVariadic());
8107330f729Sjoerg
8117330f729Sjoerg if (FD->isDefaulted())
8127330f729Sjoerg JOS.attribute("explicitlyDefaulted",
8137330f729Sjoerg FD->isDeleted() ? "deleted" : "default");
8147330f729Sjoerg }
8157330f729Sjoerg
VisitEnumDecl(const EnumDecl * ED)8167330f729Sjoerg void JSONNodeDumper::VisitEnumDecl(const EnumDecl *ED) {
8177330f729Sjoerg VisitNamedDecl(ED);
8187330f729Sjoerg if (ED->isFixed())
8197330f729Sjoerg JOS.attribute("fixedUnderlyingType", createQualType(ED->getIntegerType()));
8207330f729Sjoerg if (ED->isScoped())
8217330f729Sjoerg JOS.attribute("scopedEnumTag",
8227330f729Sjoerg ED->isScopedUsingClassTag() ? "class" : "struct");
8237330f729Sjoerg }
VisitEnumConstantDecl(const EnumConstantDecl * ECD)8247330f729Sjoerg void JSONNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *ECD) {
8257330f729Sjoerg VisitNamedDecl(ECD);
8267330f729Sjoerg JOS.attribute("type", createQualType(ECD->getType()));
8277330f729Sjoerg }
8287330f729Sjoerg
VisitRecordDecl(const RecordDecl * RD)8297330f729Sjoerg void JSONNodeDumper::VisitRecordDecl(const RecordDecl *RD) {
8307330f729Sjoerg VisitNamedDecl(RD);
8317330f729Sjoerg JOS.attribute("tagUsed", RD->getKindName());
8327330f729Sjoerg attributeOnlyIfTrue("completeDefinition", RD->isCompleteDefinition());
8337330f729Sjoerg }
VisitCXXRecordDecl(const CXXRecordDecl * RD)8347330f729Sjoerg void JSONNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *RD) {
8357330f729Sjoerg VisitRecordDecl(RD);
8367330f729Sjoerg
8377330f729Sjoerg // All other information requires a complete definition.
8387330f729Sjoerg if (!RD->isCompleteDefinition())
8397330f729Sjoerg return;
8407330f729Sjoerg
8417330f729Sjoerg JOS.attribute("definitionData", createCXXRecordDefinitionData(RD));
8427330f729Sjoerg if (RD->getNumBases()) {
8437330f729Sjoerg JOS.attributeArray("bases", [this, RD] {
8447330f729Sjoerg for (const auto &Spec : RD->bases())
8457330f729Sjoerg JOS.value(createCXXBaseSpecifier(Spec));
8467330f729Sjoerg });
8477330f729Sjoerg }
8487330f729Sjoerg }
8497330f729Sjoerg
VisitTemplateTypeParmDecl(const TemplateTypeParmDecl * D)8507330f729Sjoerg void JSONNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
8517330f729Sjoerg VisitNamedDecl(D);
8527330f729Sjoerg JOS.attribute("tagUsed", D->wasDeclaredWithTypename() ? "typename" : "class");
8537330f729Sjoerg JOS.attribute("depth", D->getDepth());
8547330f729Sjoerg JOS.attribute("index", D->getIndex());
8557330f729Sjoerg attributeOnlyIfTrue("isParameterPack", D->isParameterPack());
8567330f729Sjoerg
8577330f729Sjoerg if (D->hasDefaultArgument())
8587330f729Sjoerg JOS.attributeObject("defaultArg", [=] {
8597330f729Sjoerg Visit(D->getDefaultArgument(), SourceRange(),
8607330f729Sjoerg D->getDefaultArgStorage().getInheritedFrom(),
8617330f729Sjoerg D->defaultArgumentWasInherited() ? "inherited from" : "previous");
8627330f729Sjoerg });
8637330f729Sjoerg }
8647330f729Sjoerg
VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl * D)8657330f729Sjoerg void JSONNodeDumper::VisitNonTypeTemplateParmDecl(
8667330f729Sjoerg const NonTypeTemplateParmDecl *D) {
8677330f729Sjoerg VisitNamedDecl(D);
8687330f729Sjoerg JOS.attribute("type", createQualType(D->getType()));
8697330f729Sjoerg JOS.attribute("depth", D->getDepth());
8707330f729Sjoerg JOS.attribute("index", D->getIndex());
8717330f729Sjoerg attributeOnlyIfTrue("isParameterPack", D->isParameterPack());
8727330f729Sjoerg
8737330f729Sjoerg if (D->hasDefaultArgument())
8747330f729Sjoerg JOS.attributeObject("defaultArg", [=] {
8757330f729Sjoerg Visit(D->getDefaultArgument(), SourceRange(),
8767330f729Sjoerg D->getDefaultArgStorage().getInheritedFrom(),
8777330f729Sjoerg D->defaultArgumentWasInherited() ? "inherited from" : "previous");
8787330f729Sjoerg });
8797330f729Sjoerg }
8807330f729Sjoerg
VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl * D)8817330f729Sjoerg void JSONNodeDumper::VisitTemplateTemplateParmDecl(
8827330f729Sjoerg const TemplateTemplateParmDecl *D) {
8837330f729Sjoerg VisitNamedDecl(D);
8847330f729Sjoerg JOS.attribute("depth", D->getDepth());
8857330f729Sjoerg JOS.attribute("index", D->getIndex());
8867330f729Sjoerg attributeOnlyIfTrue("isParameterPack", D->isParameterPack());
8877330f729Sjoerg
8887330f729Sjoerg if (D->hasDefaultArgument())
8897330f729Sjoerg JOS.attributeObject("defaultArg", [=] {
890*e038c9c4Sjoerg const auto *InheritedFrom = D->getDefaultArgStorage().getInheritedFrom();
8917330f729Sjoerg Visit(D->getDefaultArgument().getArgument(),
892*e038c9c4Sjoerg InheritedFrom ? InheritedFrom->getSourceRange() : SourceLocation{},
893*e038c9c4Sjoerg InheritedFrom,
8947330f729Sjoerg D->defaultArgumentWasInherited() ? "inherited from" : "previous");
8957330f729Sjoerg });
8967330f729Sjoerg }
8977330f729Sjoerg
VisitLinkageSpecDecl(const LinkageSpecDecl * LSD)8987330f729Sjoerg void JSONNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *LSD) {
8997330f729Sjoerg StringRef Lang;
9007330f729Sjoerg switch (LSD->getLanguage()) {
9017330f729Sjoerg case LinkageSpecDecl::lang_c: Lang = "C"; break;
9027330f729Sjoerg case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
9037330f729Sjoerg }
9047330f729Sjoerg JOS.attribute("language", Lang);
9057330f729Sjoerg attributeOnlyIfTrue("hasBraces", LSD->hasBraces());
9067330f729Sjoerg }
9077330f729Sjoerg
VisitAccessSpecDecl(const AccessSpecDecl * ASD)9087330f729Sjoerg void JSONNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *ASD) {
9097330f729Sjoerg JOS.attribute("access", createAccessSpecifier(ASD->getAccess()));
9107330f729Sjoerg }
9117330f729Sjoerg
VisitFriendDecl(const FriendDecl * FD)9127330f729Sjoerg void JSONNodeDumper::VisitFriendDecl(const FriendDecl *FD) {
9137330f729Sjoerg if (const TypeSourceInfo *T = FD->getFriendType())
9147330f729Sjoerg JOS.attribute("type", createQualType(T->getType()));
9157330f729Sjoerg }
9167330f729Sjoerg
VisitObjCIvarDecl(const ObjCIvarDecl * D)9177330f729Sjoerg void JSONNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
9187330f729Sjoerg VisitNamedDecl(D);
9197330f729Sjoerg JOS.attribute("type", createQualType(D->getType()));
9207330f729Sjoerg attributeOnlyIfTrue("synthesized", D->getSynthesize());
9217330f729Sjoerg switch (D->getAccessControl()) {
9227330f729Sjoerg case ObjCIvarDecl::None: JOS.attribute("access", "none"); break;
9237330f729Sjoerg case ObjCIvarDecl::Private: JOS.attribute("access", "private"); break;
9247330f729Sjoerg case ObjCIvarDecl::Protected: JOS.attribute("access", "protected"); break;
9257330f729Sjoerg case ObjCIvarDecl::Public: JOS.attribute("access", "public"); break;
9267330f729Sjoerg case ObjCIvarDecl::Package: JOS.attribute("access", "package"); break;
9277330f729Sjoerg }
9287330f729Sjoerg }
9297330f729Sjoerg
VisitObjCMethodDecl(const ObjCMethodDecl * D)9307330f729Sjoerg void JSONNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
9317330f729Sjoerg VisitNamedDecl(D);
9327330f729Sjoerg JOS.attribute("returnType", createQualType(D->getReturnType()));
9337330f729Sjoerg JOS.attribute("instance", D->isInstanceMethod());
9347330f729Sjoerg attributeOnlyIfTrue("variadic", D->isVariadic());
9357330f729Sjoerg }
9367330f729Sjoerg
VisitObjCTypeParamDecl(const ObjCTypeParamDecl * D)9377330f729Sjoerg void JSONNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
9387330f729Sjoerg VisitNamedDecl(D);
9397330f729Sjoerg JOS.attribute("type", createQualType(D->getUnderlyingType()));
9407330f729Sjoerg attributeOnlyIfTrue("bounded", D->hasExplicitBound());
9417330f729Sjoerg switch (D->getVariance()) {
9427330f729Sjoerg case ObjCTypeParamVariance::Invariant:
9437330f729Sjoerg break;
9447330f729Sjoerg case ObjCTypeParamVariance::Covariant:
9457330f729Sjoerg JOS.attribute("variance", "covariant");
9467330f729Sjoerg break;
9477330f729Sjoerg case ObjCTypeParamVariance::Contravariant:
9487330f729Sjoerg JOS.attribute("variance", "contravariant");
9497330f729Sjoerg break;
9507330f729Sjoerg }
9517330f729Sjoerg }
9527330f729Sjoerg
VisitObjCCategoryDecl(const ObjCCategoryDecl * D)9537330f729Sjoerg void JSONNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
9547330f729Sjoerg VisitNamedDecl(D);
9557330f729Sjoerg JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
9567330f729Sjoerg JOS.attribute("implementation", createBareDeclRef(D->getImplementation()));
9577330f729Sjoerg
9587330f729Sjoerg llvm::json::Array Protocols;
9597330f729Sjoerg for (const auto* P : D->protocols())
9607330f729Sjoerg Protocols.push_back(createBareDeclRef(P));
9617330f729Sjoerg if (!Protocols.empty())
9627330f729Sjoerg JOS.attribute("protocols", std::move(Protocols));
9637330f729Sjoerg }
9647330f729Sjoerg
VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl * D)9657330f729Sjoerg void JSONNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
9667330f729Sjoerg VisitNamedDecl(D);
9677330f729Sjoerg JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
9687330f729Sjoerg JOS.attribute("categoryDecl", createBareDeclRef(D->getCategoryDecl()));
9697330f729Sjoerg }
9707330f729Sjoerg
VisitObjCProtocolDecl(const ObjCProtocolDecl * D)9717330f729Sjoerg void JSONNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
9727330f729Sjoerg VisitNamedDecl(D);
9737330f729Sjoerg
9747330f729Sjoerg llvm::json::Array Protocols;
9757330f729Sjoerg for (const auto *P : D->protocols())
9767330f729Sjoerg Protocols.push_back(createBareDeclRef(P));
9777330f729Sjoerg if (!Protocols.empty())
9787330f729Sjoerg JOS.attribute("protocols", std::move(Protocols));
9797330f729Sjoerg }
9807330f729Sjoerg
VisitObjCInterfaceDecl(const ObjCInterfaceDecl * D)9817330f729Sjoerg void JSONNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
9827330f729Sjoerg VisitNamedDecl(D);
9837330f729Sjoerg JOS.attribute("super", createBareDeclRef(D->getSuperClass()));
9847330f729Sjoerg JOS.attribute("implementation", createBareDeclRef(D->getImplementation()));
9857330f729Sjoerg
9867330f729Sjoerg llvm::json::Array Protocols;
9877330f729Sjoerg for (const auto* P : D->protocols())
9887330f729Sjoerg Protocols.push_back(createBareDeclRef(P));
9897330f729Sjoerg if (!Protocols.empty())
9907330f729Sjoerg JOS.attribute("protocols", std::move(Protocols));
9917330f729Sjoerg }
9927330f729Sjoerg
VisitObjCImplementationDecl(const ObjCImplementationDecl * D)9937330f729Sjoerg void JSONNodeDumper::VisitObjCImplementationDecl(
9947330f729Sjoerg const ObjCImplementationDecl *D) {
9957330f729Sjoerg VisitNamedDecl(D);
9967330f729Sjoerg JOS.attribute("super", createBareDeclRef(D->getSuperClass()));
9977330f729Sjoerg JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
9987330f729Sjoerg }
9997330f729Sjoerg
VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl * D)10007330f729Sjoerg void JSONNodeDumper::VisitObjCCompatibleAliasDecl(
10017330f729Sjoerg const ObjCCompatibleAliasDecl *D) {
10027330f729Sjoerg VisitNamedDecl(D);
10037330f729Sjoerg JOS.attribute("interface", createBareDeclRef(D->getClassInterface()));
10047330f729Sjoerg }
10057330f729Sjoerg
VisitObjCPropertyDecl(const ObjCPropertyDecl * D)10067330f729Sjoerg void JSONNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
10077330f729Sjoerg VisitNamedDecl(D);
10087330f729Sjoerg JOS.attribute("type", createQualType(D->getType()));
10097330f729Sjoerg
10107330f729Sjoerg switch (D->getPropertyImplementation()) {
10117330f729Sjoerg case ObjCPropertyDecl::None: break;
10127330f729Sjoerg case ObjCPropertyDecl::Required: JOS.attribute("control", "required"); break;
10137330f729Sjoerg case ObjCPropertyDecl::Optional: JOS.attribute("control", "optional"); break;
10147330f729Sjoerg }
10157330f729Sjoerg
1016*e038c9c4Sjoerg ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes();
1017*e038c9c4Sjoerg if (Attrs != ObjCPropertyAttribute::kind_noattr) {
1018*e038c9c4Sjoerg if (Attrs & ObjCPropertyAttribute::kind_getter)
10197330f729Sjoerg JOS.attribute("getter", createBareDeclRef(D->getGetterMethodDecl()));
1020*e038c9c4Sjoerg if (Attrs & ObjCPropertyAttribute::kind_setter)
10217330f729Sjoerg JOS.attribute("setter", createBareDeclRef(D->getSetterMethodDecl()));
1022*e038c9c4Sjoerg attributeOnlyIfTrue("readonly",
1023*e038c9c4Sjoerg Attrs & ObjCPropertyAttribute::kind_readonly);
1024*e038c9c4Sjoerg attributeOnlyIfTrue("assign", Attrs & ObjCPropertyAttribute::kind_assign);
10257330f729Sjoerg attributeOnlyIfTrue("readwrite",
1026*e038c9c4Sjoerg Attrs & ObjCPropertyAttribute::kind_readwrite);
1027*e038c9c4Sjoerg attributeOnlyIfTrue("retain", Attrs & ObjCPropertyAttribute::kind_retain);
1028*e038c9c4Sjoerg attributeOnlyIfTrue("copy", Attrs & ObjCPropertyAttribute::kind_copy);
10297330f729Sjoerg attributeOnlyIfTrue("nonatomic",
1030*e038c9c4Sjoerg Attrs & ObjCPropertyAttribute::kind_nonatomic);
1031*e038c9c4Sjoerg attributeOnlyIfTrue("atomic", Attrs & ObjCPropertyAttribute::kind_atomic);
1032*e038c9c4Sjoerg attributeOnlyIfTrue("weak", Attrs & ObjCPropertyAttribute::kind_weak);
1033*e038c9c4Sjoerg attributeOnlyIfTrue("strong", Attrs & ObjCPropertyAttribute::kind_strong);
10347330f729Sjoerg attributeOnlyIfTrue("unsafe_unretained",
1035*e038c9c4Sjoerg Attrs & ObjCPropertyAttribute::kind_unsafe_unretained);
1036*e038c9c4Sjoerg attributeOnlyIfTrue("class", Attrs & ObjCPropertyAttribute::kind_class);
1037*e038c9c4Sjoerg attributeOnlyIfTrue("direct", Attrs & ObjCPropertyAttribute::kind_direct);
10387330f729Sjoerg attributeOnlyIfTrue("nullability",
1039*e038c9c4Sjoerg Attrs & ObjCPropertyAttribute::kind_nullability);
10407330f729Sjoerg attributeOnlyIfTrue("null_resettable",
1041*e038c9c4Sjoerg Attrs & ObjCPropertyAttribute::kind_null_resettable);
10427330f729Sjoerg }
10437330f729Sjoerg }
10447330f729Sjoerg
VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl * D)10457330f729Sjoerg void JSONNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
10467330f729Sjoerg VisitNamedDecl(D->getPropertyDecl());
10477330f729Sjoerg JOS.attribute("implKind", D->getPropertyImplementation() ==
10487330f729Sjoerg ObjCPropertyImplDecl::Synthesize
10497330f729Sjoerg ? "synthesize"
10507330f729Sjoerg : "dynamic");
10517330f729Sjoerg JOS.attribute("propertyDecl", createBareDeclRef(D->getPropertyDecl()));
10527330f729Sjoerg JOS.attribute("ivarDecl", createBareDeclRef(D->getPropertyIvarDecl()));
10537330f729Sjoerg }
10547330f729Sjoerg
VisitBlockDecl(const BlockDecl * D)10557330f729Sjoerg void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) {
10567330f729Sjoerg attributeOnlyIfTrue("variadic", D->isVariadic());
10577330f729Sjoerg attributeOnlyIfTrue("capturesThis", D->capturesCXXThis());
10587330f729Sjoerg }
10597330f729Sjoerg
VisitObjCEncodeExpr(const ObjCEncodeExpr * OEE)10607330f729Sjoerg void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) {
10617330f729Sjoerg JOS.attribute("encodedType", createQualType(OEE->getEncodedType()));
10627330f729Sjoerg }
10637330f729Sjoerg
VisitObjCMessageExpr(const ObjCMessageExpr * OME)10647330f729Sjoerg void JSONNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *OME) {
10657330f729Sjoerg std::string Str;
10667330f729Sjoerg llvm::raw_string_ostream OS(Str);
10677330f729Sjoerg
10687330f729Sjoerg OME->getSelector().print(OS);
10697330f729Sjoerg JOS.attribute("selector", OS.str());
10707330f729Sjoerg
10717330f729Sjoerg switch (OME->getReceiverKind()) {
10727330f729Sjoerg case ObjCMessageExpr::Instance:
10737330f729Sjoerg JOS.attribute("receiverKind", "instance");
10747330f729Sjoerg break;
10757330f729Sjoerg case ObjCMessageExpr::Class:
10767330f729Sjoerg JOS.attribute("receiverKind", "class");
10777330f729Sjoerg JOS.attribute("classType", createQualType(OME->getClassReceiver()));
10787330f729Sjoerg break;
10797330f729Sjoerg case ObjCMessageExpr::SuperInstance:
10807330f729Sjoerg JOS.attribute("receiverKind", "super (instance)");
10817330f729Sjoerg JOS.attribute("superType", createQualType(OME->getSuperType()));
10827330f729Sjoerg break;
10837330f729Sjoerg case ObjCMessageExpr::SuperClass:
10847330f729Sjoerg JOS.attribute("receiverKind", "super (class)");
10857330f729Sjoerg JOS.attribute("superType", createQualType(OME->getSuperType()));
10867330f729Sjoerg break;
10877330f729Sjoerg }
10887330f729Sjoerg
10897330f729Sjoerg QualType CallReturnTy = OME->getCallReturnType(Ctx);
10907330f729Sjoerg if (OME->getType() != CallReturnTy)
10917330f729Sjoerg JOS.attribute("callReturnType", createQualType(CallReturnTy));
10927330f729Sjoerg }
10937330f729Sjoerg
VisitObjCBoxedExpr(const ObjCBoxedExpr * OBE)10947330f729Sjoerg void JSONNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE) {
10957330f729Sjoerg if (const ObjCMethodDecl *MD = OBE->getBoxingMethod()) {
10967330f729Sjoerg std::string Str;
10977330f729Sjoerg llvm::raw_string_ostream OS(Str);
10987330f729Sjoerg
10997330f729Sjoerg MD->getSelector().print(OS);
11007330f729Sjoerg JOS.attribute("selector", OS.str());
11017330f729Sjoerg }
11027330f729Sjoerg }
11037330f729Sjoerg
VisitObjCSelectorExpr(const ObjCSelectorExpr * OSE)11047330f729Sjoerg void JSONNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE) {
11057330f729Sjoerg std::string Str;
11067330f729Sjoerg llvm::raw_string_ostream OS(Str);
11077330f729Sjoerg
11087330f729Sjoerg OSE->getSelector().print(OS);
11097330f729Sjoerg JOS.attribute("selector", OS.str());
11107330f729Sjoerg }
11117330f729Sjoerg
VisitObjCProtocolExpr(const ObjCProtocolExpr * OPE)11127330f729Sjoerg void JSONNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) {
11137330f729Sjoerg JOS.attribute("protocol", createBareDeclRef(OPE->getProtocol()));
11147330f729Sjoerg }
11157330f729Sjoerg
VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr * OPRE)11167330f729Sjoerg void JSONNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) {
11177330f729Sjoerg if (OPRE->isImplicitProperty()) {
11187330f729Sjoerg JOS.attribute("propertyKind", "implicit");
11197330f729Sjoerg if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertyGetter())
11207330f729Sjoerg JOS.attribute("getter", createBareDeclRef(MD));
11217330f729Sjoerg if (const ObjCMethodDecl *MD = OPRE->getImplicitPropertySetter())
11227330f729Sjoerg JOS.attribute("setter", createBareDeclRef(MD));
11237330f729Sjoerg } else {
11247330f729Sjoerg JOS.attribute("propertyKind", "explicit");
11257330f729Sjoerg JOS.attribute("property", createBareDeclRef(OPRE->getExplicitProperty()));
11267330f729Sjoerg }
11277330f729Sjoerg
11287330f729Sjoerg attributeOnlyIfTrue("isSuperReceiver", OPRE->isSuperReceiver());
11297330f729Sjoerg attributeOnlyIfTrue("isMessagingGetter", OPRE->isMessagingGetter());
11307330f729Sjoerg attributeOnlyIfTrue("isMessagingSetter", OPRE->isMessagingSetter());
11317330f729Sjoerg }
11327330f729Sjoerg
VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr * OSRE)11337330f729Sjoerg void JSONNodeDumper::VisitObjCSubscriptRefExpr(
11347330f729Sjoerg const ObjCSubscriptRefExpr *OSRE) {
11357330f729Sjoerg JOS.attribute("subscriptKind",
11367330f729Sjoerg OSRE->isArraySubscriptRefExpr() ? "array" : "dictionary");
11377330f729Sjoerg
11387330f729Sjoerg if (const ObjCMethodDecl *MD = OSRE->getAtIndexMethodDecl())
11397330f729Sjoerg JOS.attribute("getter", createBareDeclRef(MD));
11407330f729Sjoerg if (const ObjCMethodDecl *MD = OSRE->setAtIndexMethodDecl())
11417330f729Sjoerg JOS.attribute("setter", createBareDeclRef(MD));
11427330f729Sjoerg }
11437330f729Sjoerg
VisitObjCIvarRefExpr(const ObjCIvarRefExpr * OIRE)11447330f729Sjoerg void JSONNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE) {
11457330f729Sjoerg JOS.attribute("decl", createBareDeclRef(OIRE->getDecl()));
11467330f729Sjoerg attributeOnlyIfTrue("isFreeIvar", OIRE->isFreeIvar());
11477330f729Sjoerg JOS.attribute("isArrow", OIRE->isArrow());
11487330f729Sjoerg }
11497330f729Sjoerg
VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr * OBLE)11507330f729Sjoerg void JSONNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE) {
11517330f729Sjoerg JOS.attribute("value", OBLE->getValue() ? "__objc_yes" : "__objc_no");
11527330f729Sjoerg }
11537330f729Sjoerg
VisitDeclRefExpr(const DeclRefExpr * DRE)11547330f729Sjoerg void JSONNodeDumper::VisitDeclRefExpr(const DeclRefExpr *DRE) {
11557330f729Sjoerg JOS.attribute("referencedDecl", createBareDeclRef(DRE->getDecl()));
11567330f729Sjoerg if (DRE->getDecl() != DRE->getFoundDecl())
11577330f729Sjoerg JOS.attribute("foundReferencedDecl",
11587330f729Sjoerg createBareDeclRef(DRE->getFoundDecl()));
11597330f729Sjoerg switch (DRE->isNonOdrUse()) {
11607330f729Sjoerg case NOUR_None: break;
11617330f729Sjoerg case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break;
11627330f729Sjoerg case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
11637330f729Sjoerg case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
11647330f729Sjoerg }
11657330f729Sjoerg }
11667330f729Sjoerg
VisitPredefinedExpr(const PredefinedExpr * PE)11677330f729Sjoerg void JSONNodeDumper::VisitPredefinedExpr(const PredefinedExpr *PE) {
11687330f729Sjoerg JOS.attribute("name", PredefinedExpr::getIdentKindName(PE->getIdentKind()));
11697330f729Sjoerg }
11707330f729Sjoerg
VisitUnaryOperator(const UnaryOperator * UO)11717330f729Sjoerg void JSONNodeDumper::VisitUnaryOperator(const UnaryOperator *UO) {
11727330f729Sjoerg JOS.attribute("isPostfix", UO->isPostfix());
11737330f729Sjoerg JOS.attribute("opcode", UnaryOperator::getOpcodeStr(UO->getOpcode()));
11747330f729Sjoerg if (!UO->canOverflow())
11757330f729Sjoerg JOS.attribute("canOverflow", false);
11767330f729Sjoerg }
11777330f729Sjoerg
VisitBinaryOperator(const BinaryOperator * BO)11787330f729Sjoerg void JSONNodeDumper::VisitBinaryOperator(const BinaryOperator *BO) {
11797330f729Sjoerg JOS.attribute("opcode", BinaryOperator::getOpcodeStr(BO->getOpcode()));
11807330f729Sjoerg }
11817330f729Sjoerg
VisitCompoundAssignOperator(const CompoundAssignOperator * CAO)11827330f729Sjoerg void JSONNodeDumper::VisitCompoundAssignOperator(
11837330f729Sjoerg const CompoundAssignOperator *CAO) {
11847330f729Sjoerg VisitBinaryOperator(CAO);
11857330f729Sjoerg JOS.attribute("computeLHSType", createQualType(CAO->getComputationLHSType()));
11867330f729Sjoerg JOS.attribute("computeResultType",
11877330f729Sjoerg createQualType(CAO->getComputationResultType()));
11887330f729Sjoerg }
11897330f729Sjoerg
VisitMemberExpr(const MemberExpr * ME)11907330f729Sjoerg void JSONNodeDumper::VisitMemberExpr(const MemberExpr *ME) {
11917330f729Sjoerg // Note, we always write this Boolean field because the information it conveys
11927330f729Sjoerg // is critical to understanding the AST node.
11937330f729Sjoerg ValueDecl *VD = ME->getMemberDecl();
11947330f729Sjoerg JOS.attribute("name", VD && VD->getDeclName() ? VD->getNameAsString() : "");
11957330f729Sjoerg JOS.attribute("isArrow", ME->isArrow());
11967330f729Sjoerg JOS.attribute("referencedMemberDecl", createPointerRepresentation(VD));
11977330f729Sjoerg switch (ME->isNonOdrUse()) {
11987330f729Sjoerg case NOUR_None: break;
11997330f729Sjoerg case NOUR_Unevaluated: JOS.attribute("nonOdrUseReason", "unevaluated"); break;
12007330f729Sjoerg case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
12017330f729Sjoerg case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
12027330f729Sjoerg }
12037330f729Sjoerg }
12047330f729Sjoerg
VisitCXXNewExpr(const CXXNewExpr * NE)12057330f729Sjoerg void JSONNodeDumper::VisitCXXNewExpr(const CXXNewExpr *NE) {
12067330f729Sjoerg attributeOnlyIfTrue("isGlobal", NE->isGlobalNew());
12077330f729Sjoerg attributeOnlyIfTrue("isArray", NE->isArray());
12087330f729Sjoerg attributeOnlyIfTrue("isPlacement", NE->getNumPlacementArgs() != 0);
12097330f729Sjoerg switch (NE->getInitializationStyle()) {
12107330f729Sjoerg case CXXNewExpr::NoInit: break;
12117330f729Sjoerg case CXXNewExpr::CallInit: JOS.attribute("initStyle", "call"); break;
12127330f729Sjoerg case CXXNewExpr::ListInit: JOS.attribute("initStyle", "list"); break;
12137330f729Sjoerg }
12147330f729Sjoerg if (const FunctionDecl *FD = NE->getOperatorNew())
12157330f729Sjoerg JOS.attribute("operatorNewDecl", createBareDeclRef(FD));
12167330f729Sjoerg if (const FunctionDecl *FD = NE->getOperatorDelete())
12177330f729Sjoerg JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD));
12187330f729Sjoerg }
VisitCXXDeleteExpr(const CXXDeleteExpr * DE)12197330f729Sjoerg void JSONNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *DE) {
12207330f729Sjoerg attributeOnlyIfTrue("isGlobal", DE->isGlobalDelete());
12217330f729Sjoerg attributeOnlyIfTrue("isArray", DE->isArrayForm());
12227330f729Sjoerg attributeOnlyIfTrue("isArrayAsWritten", DE->isArrayFormAsWritten());
12237330f729Sjoerg if (const FunctionDecl *FD = DE->getOperatorDelete())
12247330f729Sjoerg JOS.attribute("operatorDeleteDecl", createBareDeclRef(FD));
12257330f729Sjoerg }
12267330f729Sjoerg
VisitCXXThisExpr(const CXXThisExpr * TE)12277330f729Sjoerg void JSONNodeDumper::VisitCXXThisExpr(const CXXThisExpr *TE) {
12287330f729Sjoerg attributeOnlyIfTrue("implicit", TE->isImplicit());
12297330f729Sjoerg }
12307330f729Sjoerg
VisitCastExpr(const CastExpr * CE)12317330f729Sjoerg void JSONNodeDumper::VisitCastExpr(const CastExpr *CE) {
12327330f729Sjoerg JOS.attribute("castKind", CE->getCastKindName());
12337330f729Sjoerg llvm::json::Array Path = createCastPath(CE);
12347330f729Sjoerg if (!Path.empty())
12357330f729Sjoerg JOS.attribute("path", std::move(Path));
12367330f729Sjoerg // FIXME: This may not be useful information as it can be obtusely gleaned
12377330f729Sjoerg // from the inner[] array.
12387330f729Sjoerg if (const NamedDecl *ND = CE->getConversionFunction())
12397330f729Sjoerg JOS.attribute("conversionFunc", createBareDeclRef(ND));
12407330f729Sjoerg }
12417330f729Sjoerg
VisitImplicitCastExpr(const ImplicitCastExpr * ICE)12427330f729Sjoerg void JSONNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *ICE) {
12437330f729Sjoerg VisitCastExpr(ICE);
12447330f729Sjoerg attributeOnlyIfTrue("isPartOfExplicitCast", ICE->isPartOfExplicitCast());
12457330f729Sjoerg }
12467330f729Sjoerg
VisitCallExpr(const CallExpr * CE)12477330f729Sjoerg void JSONNodeDumper::VisitCallExpr(const CallExpr *CE) {
12487330f729Sjoerg attributeOnlyIfTrue("adl", CE->usesADL());
12497330f729Sjoerg }
12507330f729Sjoerg
VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr * TTE)12517330f729Sjoerg void JSONNodeDumper::VisitUnaryExprOrTypeTraitExpr(
12527330f729Sjoerg const UnaryExprOrTypeTraitExpr *TTE) {
1253*e038c9c4Sjoerg JOS.attribute("name", getTraitSpelling(TTE->getKind()));
12547330f729Sjoerg if (TTE->isArgumentType())
12557330f729Sjoerg JOS.attribute("argType", createQualType(TTE->getArgumentType()));
12567330f729Sjoerg }
12577330f729Sjoerg
VisitSizeOfPackExpr(const SizeOfPackExpr * SOPE)12587330f729Sjoerg void JSONNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE) {
12597330f729Sjoerg VisitNamedDecl(SOPE->getPack());
12607330f729Sjoerg }
12617330f729Sjoerg
VisitUnresolvedLookupExpr(const UnresolvedLookupExpr * ULE)12627330f729Sjoerg void JSONNodeDumper::VisitUnresolvedLookupExpr(
12637330f729Sjoerg const UnresolvedLookupExpr *ULE) {
12647330f729Sjoerg JOS.attribute("usesADL", ULE->requiresADL());
12657330f729Sjoerg JOS.attribute("name", ULE->getName().getAsString());
12667330f729Sjoerg
12677330f729Sjoerg JOS.attributeArray("lookups", [this, ULE] {
12687330f729Sjoerg for (const NamedDecl *D : ULE->decls())
12697330f729Sjoerg JOS.value(createBareDeclRef(D));
12707330f729Sjoerg });
12717330f729Sjoerg }
12727330f729Sjoerg
VisitAddrLabelExpr(const AddrLabelExpr * ALE)12737330f729Sjoerg void JSONNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *ALE) {
12747330f729Sjoerg JOS.attribute("name", ALE->getLabel()->getName());
12757330f729Sjoerg JOS.attribute("labelDeclId", createPointerRepresentation(ALE->getLabel()));
12767330f729Sjoerg }
12777330f729Sjoerg
VisitCXXTypeidExpr(const CXXTypeidExpr * CTE)12787330f729Sjoerg void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) {
12797330f729Sjoerg if (CTE->isTypeOperand()) {
12807330f729Sjoerg QualType Adjusted = CTE->getTypeOperand(Ctx);
12817330f729Sjoerg QualType Unadjusted = CTE->getTypeOperandSourceInfo()->getType();
12827330f729Sjoerg JOS.attribute("typeArg", createQualType(Unadjusted));
12837330f729Sjoerg if (Adjusted != Unadjusted)
12847330f729Sjoerg JOS.attribute("adjustedTypeArg", createQualType(Adjusted));
12857330f729Sjoerg }
12867330f729Sjoerg }
12877330f729Sjoerg
VisitConstantExpr(const ConstantExpr * CE)12887330f729Sjoerg void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) {
1289*e038c9c4Sjoerg if (CE->getResultAPValueKind() != APValue::None)
1290*e038c9c4Sjoerg Visit(CE->getAPValueResult(), CE->getType());
12917330f729Sjoerg }
12927330f729Sjoerg
VisitInitListExpr(const InitListExpr * ILE)12937330f729Sjoerg void JSONNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
12947330f729Sjoerg if (const FieldDecl *FD = ILE->getInitializedFieldInUnion())
12957330f729Sjoerg JOS.attribute("field", createBareDeclRef(FD));
12967330f729Sjoerg }
12977330f729Sjoerg
VisitGenericSelectionExpr(const GenericSelectionExpr * GSE)12987330f729Sjoerg void JSONNodeDumper::VisitGenericSelectionExpr(
12997330f729Sjoerg const GenericSelectionExpr *GSE) {
13007330f729Sjoerg attributeOnlyIfTrue("resultDependent", GSE->isResultDependent());
13017330f729Sjoerg }
13027330f729Sjoerg
VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr * UCE)13037330f729Sjoerg void JSONNodeDumper::VisitCXXUnresolvedConstructExpr(
13047330f729Sjoerg const CXXUnresolvedConstructExpr *UCE) {
13057330f729Sjoerg if (UCE->getType() != UCE->getTypeAsWritten())
13067330f729Sjoerg JOS.attribute("typeAsWritten", createQualType(UCE->getTypeAsWritten()));
13077330f729Sjoerg attributeOnlyIfTrue("list", UCE->isListInitialization());
13087330f729Sjoerg }
13097330f729Sjoerg
VisitCXXConstructExpr(const CXXConstructExpr * CE)13107330f729Sjoerg void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) {
13117330f729Sjoerg CXXConstructorDecl *Ctor = CE->getConstructor();
13127330f729Sjoerg JOS.attribute("ctorType", createQualType(Ctor->getType()));
13137330f729Sjoerg attributeOnlyIfTrue("elidable", CE->isElidable());
13147330f729Sjoerg attributeOnlyIfTrue("list", CE->isListInitialization());
13157330f729Sjoerg attributeOnlyIfTrue("initializer_list", CE->isStdInitListInitialization());
13167330f729Sjoerg attributeOnlyIfTrue("zeroing", CE->requiresZeroInitialization());
13177330f729Sjoerg attributeOnlyIfTrue("hadMultipleCandidates", CE->hadMultipleCandidates());
13187330f729Sjoerg
13197330f729Sjoerg switch (CE->getConstructionKind()) {
13207330f729Sjoerg case CXXConstructExpr::CK_Complete:
13217330f729Sjoerg JOS.attribute("constructionKind", "complete");
13227330f729Sjoerg break;
13237330f729Sjoerg case CXXConstructExpr::CK_Delegating:
13247330f729Sjoerg JOS.attribute("constructionKind", "delegating");
13257330f729Sjoerg break;
13267330f729Sjoerg case CXXConstructExpr::CK_NonVirtualBase:
13277330f729Sjoerg JOS.attribute("constructionKind", "non-virtual base");
13287330f729Sjoerg break;
13297330f729Sjoerg case CXXConstructExpr::CK_VirtualBase:
13307330f729Sjoerg JOS.attribute("constructionKind", "virtual base");
13317330f729Sjoerg break;
13327330f729Sjoerg }
13337330f729Sjoerg }
13347330f729Sjoerg
VisitExprWithCleanups(const ExprWithCleanups * EWC)13357330f729Sjoerg void JSONNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *EWC) {
13367330f729Sjoerg attributeOnlyIfTrue("cleanupsHaveSideEffects",
13377330f729Sjoerg EWC->cleanupsHaveSideEffects());
13387330f729Sjoerg if (EWC->getNumObjects()) {
13397330f729Sjoerg JOS.attributeArray("cleanups", [this, EWC] {
13407330f729Sjoerg for (const ExprWithCleanups::CleanupObject &CO : EWC->getObjects())
1341*e038c9c4Sjoerg if (auto *BD = CO.dyn_cast<BlockDecl *>()) {
1342*e038c9c4Sjoerg JOS.value(createBareDeclRef(BD));
1343*e038c9c4Sjoerg } else if (auto *CLE = CO.dyn_cast<CompoundLiteralExpr *>()) {
1344*e038c9c4Sjoerg llvm::json::Object Obj;
1345*e038c9c4Sjoerg Obj["id"] = createPointerRepresentation(CLE);
1346*e038c9c4Sjoerg Obj["kind"] = CLE->getStmtClassName();
1347*e038c9c4Sjoerg JOS.value(std::move(Obj));
1348*e038c9c4Sjoerg } else {
1349*e038c9c4Sjoerg llvm_unreachable("unexpected cleanup object type");
1350*e038c9c4Sjoerg }
13517330f729Sjoerg });
13527330f729Sjoerg }
13537330f729Sjoerg }
13547330f729Sjoerg
VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr * BTE)13557330f729Sjoerg void JSONNodeDumper::VisitCXXBindTemporaryExpr(
13567330f729Sjoerg const CXXBindTemporaryExpr *BTE) {
13577330f729Sjoerg const CXXTemporary *Temp = BTE->getTemporary();
13587330f729Sjoerg JOS.attribute("temp", createPointerRepresentation(Temp));
13597330f729Sjoerg if (const CXXDestructorDecl *Dtor = Temp->getDestructor())
13607330f729Sjoerg JOS.attribute("dtor", createBareDeclRef(Dtor));
13617330f729Sjoerg }
13627330f729Sjoerg
VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr * MTE)13637330f729Sjoerg void JSONNodeDumper::VisitMaterializeTemporaryExpr(
13647330f729Sjoerg const MaterializeTemporaryExpr *MTE) {
13657330f729Sjoerg if (const ValueDecl *VD = MTE->getExtendingDecl())
13667330f729Sjoerg JOS.attribute("extendingDecl", createBareDeclRef(VD));
13677330f729Sjoerg
13687330f729Sjoerg switch (MTE->getStorageDuration()) {
13697330f729Sjoerg case SD_Automatic:
13707330f729Sjoerg JOS.attribute("storageDuration", "automatic");
13717330f729Sjoerg break;
13727330f729Sjoerg case SD_Dynamic:
13737330f729Sjoerg JOS.attribute("storageDuration", "dynamic");
13747330f729Sjoerg break;
13757330f729Sjoerg case SD_FullExpression:
13767330f729Sjoerg JOS.attribute("storageDuration", "full expression");
13777330f729Sjoerg break;
13787330f729Sjoerg case SD_Static:
13797330f729Sjoerg JOS.attribute("storageDuration", "static");
13807330f729Sjoerg break;
13817330f729Sjoerg case SD_Thread:
13827330f729Sjoerg JOS.attribute("storageDuration", "thread");
13837330f729Sjoerg break;
13847330f729Sjoerg }
13857330f729Sjoerg
13867330f729Sjoerg attributeOnlyIfTrue("boundToLValueRef", MTE->isBoundToLvalueReference());
13877330f729Sjoerg }
13887330f729Sjoerg
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr * DSME)13897330f729Sjoerg void JSONNodeDumper::VisitCXXDependentScopeMemberExpr(
13907330f729Sjoerg const CXXDependentScopeMemberExpr *DSME) {
13917330f729Sjoerg JOS.attribute("isArrow", DSME->isArrow());
13927330f729Sjoerg JOS.attribute("member", DSME->getMember().getAsString());
13937330f729Sjoerg attributeOnlyIfTrue("hasTemplateKeyword", DSME->hasTemplateKeyword());
13947330f729Sjoerg attributeOnlyIfTrue("hasExplicitTemplateArgs",
13957330f729Sjoerg DSME->hasExplicitTemplateArgs());
13967330f729Sjoerg
13977330f729Sjoerg if (DSME->getNumTemplateArgs()) {
13987330f729Sjoerg JOS.attributeArray("explicitTemplateArgs", [DSME, this] {
13997330f729Sjoerg for (const TemplateArgumentLoc &TAL : DSME->template_arguments())
14007330f729Sjoerg JOS.object(
14017330f729Sjoerg [&TAL, this] { Visit(TAL.getArgument(), TAL.getSourceRange()); });
14027330f729Sjoerg });
14037330f729Sjoerg }
14047330f729Sjoerg }
14057330f729Sjoerg
VisitIntegerLiteral(const IntegerLiteral * IL)14067330f729Sjoerg void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
14077330f729Sjoerg JOS.attribute("value",
14087330f729Sjoerg IL->getValue().toString(
14097330f729Sjoerg /*Radix=*/10, IL->getType()->isSignedIntegerType()));
14107330f729Sjoerg }
VisitCharacterLiteral(const CharacterLiteral * CL)14117330f729Sjoerg void JSONNodeDumper::VisitCharacterLiteral(const CharacterLiteral *CL) {
14127330f729Sjoerg // FIXME: This should probably print the character literal as a string,
14137330f729Sjoerg // rather than as a numerical value. It would be nice if the behavior matched
14147330f729Sjoerg // what we do to print a string literal; right now, it is impossible to tell
14157330f729Sjoerg // the difference between 'a' and L'a' in C from the JSON output.
14167330f729Sjoerg JOS.attribute("value", CL->getValue());
14177330f729Sjoerg }
VisitFixedPointLiteral(const FixedPointLiteral * FPL)14187330f729Sjoerg void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) {
14197330f729Sjoerg JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10));
14207330f729Sjoerg }
VisitFloatingLiteral(const FloatingLiteral * FL)14217330f729Sjoerg void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) {
1422*e038c9c4Sjoerg llvm::SmallString<16> Buffer;
14237330f729Sjoerg FL->getValue().toString(Buffer);
14247330f729Sjoerg JOS.attribute("value", Buffer);
14257330f729Sjoerg }
VisitStringLiteral(const StringLiteral * SL)14267330f729Sjoerg void JSONNodeDumper::VisitStringLiteral(const StringLiteral *SL) {
14277330f729Sjoerg std::string Buffer;
14287330f729Sjoerg llvm::raw_string_ostream SS(Buffer);
14297330f729Sjoerg SL->outputString(SS);
14307330f729Sjoerg JOS.attribute("value", SS.str());
14317330f729Sjoerg }
VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr * BLE)14327330f729Sjoerg void JSONNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE) {
14337330f729Sjoerg JOS.attribute("value", BLE->getValue());
14347330f729Sjoerg }
14357330f729Sjoerg
VisitIfStmt(const IfStmt * IS)14367330f729Sjoerg void JSONNodeDumper::VisitIfStmt(const IfStmt *IS) {
14377330f729Sjoerg attributeOnlyIfTrue("hasInit", IS->hasInitStorage());
14387330f729Sjoerg attributeOnlyIfTrue("hasVar", IS->hasVarStorage());
14397330f729Sjoerg attributeOnlyIfTrue("hasElse", IS->hasElseStorage());
14407330f729Sjoerg attributeOnlyIfTrue("isConstexpr", IS->isConstexpr());
14417330f729Sjoerg }
14427330f729Sjoerg
VisitSwitchStmt(const SwitchStmt * SS)14437330f729Sjoerg void JSONNodeDumper::VisitSwitchStmt(const SwitchStmt *SS) {
14447330f729Sjoerg attributeOnlyIfTrue("hasInit", SS->hasInitStorage());
14457330f729Sjoerg attributeOnlyIfTrue("hasVar", SS->hasVarStorage());
14467330f729Sjoerg }
VisitCaseStmt(const CaseStmt * CS)14477330f729Sjoerg void JSONNodeDumper::VisitCaseStmt(const CaseStmt *CS) {
14487330f729Sjoerg attributeOnlyIfTrue("isGNURange", CS->caseStmtIsGNURange());
14497330f729Sjoerg }
14507330f729Sjoerg
VisitLabelStmt(const LabelStmt * LS)14517330f729Sjoerg void JSONNodeDumper::VisitLabelStmt(const LabelStmt *LS) {
14527330f729Sjoerg JOS.attribute("name", LS->getName());
14537330f729Sjoerg JOS.attribute("declId", createPointerRepresentation(LS->getDecl()));
1454*e038c9c4Sjoerg attributeOnlyIfTrue("sideEntry", LS->isSideEntry());
14557330f729Sjoerg }
VisitGotoStmt(const GotoStmt * GS)14567330f729Sjoerg void JSONNodeDumper::VisitGotoStmt(const GotoStmt *GS) {
14577330f729Sjoerg JOS.attribute("targetLabelDeclId",
14587330f729Sjoerg createPointerRepresentation(GS->getLabel()));
14597330f729Sjoerg }
14607330f729Sjoerg
VisitWhileStmt(const WhileStmt * WS)14617330f729Sjoerg void JSONNodeDumper::VisitWhileStmt(const WhileStmt *WS) {
14627330f729Sjoerg attributeOnlyIfTrue("hasVar", WS->hasVarStorage());
14637330f729Sjoerg }
14647330f729Sjoerg
VisitObjCAtCatchStmt(const ObjCAtCatchStmt * OACS)14657330f729Sjoerg void JSONNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt* OACS) {
14667330f729Sjoerg // FIXME: it would be nice for the ASTNodeTraverser would handle the catch
14677330f729Sjoerg // parameter the same way for C++ and ObjC rather. In this case, C++ gets a
14687330f729Sjoerg // null child node and ObjC gets no child node.
14697330f729Sjoerg attributeOnlyIfTrue("isCatchAll", OACS->getCatchParamDecl() == nullptr);
14707330f729Sjoerg }
14717330f729Sjoerg
VisitNullTemplateArgument(const TemplateArgument & TA)14727330f729Sjoerg void JSONNodeDumper::VisitNullTemplateArgument(const TemplateArgument &TA) {
14737330f729Sjoerg JOS.attribute("isNull", true);
14747330f729Sjoerg }
VisitTypeTemplateArgument(const TemplateArgument & TA)14757330f729Sjoerg void JSONNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
14767330f729Sjoerg JOS.attribute("type", createQualType(TA.getAsType()));
14777330f729Sjoerg }
VisitDeclarationTemplateArgument(const TemplateArgument & TA)14787330f729Sjoerg void JSONNodeDumper::VisitDeclarationTemplateArgument(
14797330f729Sjoerg const TemplateArgument &TA) {
14807330f729Sjoerg JOS.attribute("decl", createBareDeclRef(TA.getAsDecl()));
14817330f729Sjoerg }
VisitNullPtrTemplateArgument(const TemplateArgument & TA)14827330f729Sjoerg void JSONNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
14837330f729Sjoerg JOS.attribute("isNullptr", true);
14847330f729Sjoerg }
VisitIntegralTemplateArgument(const TemplateArgument & TA)14857330f729Sjoerg void JSONNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
14867330f729Sjoerg JOS.attribute("value", TA.getAsIntegral().getSExtValue());
14877330f729Sjoerg }
VisitTemplateTemplateArgument(const TemplateArgument & TA)14887330f729Sjoerg void JSONNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
14897330f729Sjoerg // FIXME: cannot just call dump() on the argument, as that doesn't specify
14907330f729Sjoerg // the output format.
14917330f729Sjoerg }
VisitTemplateExpansionTemplateArgument(const TemplateArgument & TA)14927330f729Sjoerg void JSONNodeDumper::VisitTemplateExpansionTemplateArgument(
14937330f729Sjoerg const TemplateArgument &TA) {
14947330f729Sjoerg // FIXME: cannot just call dump() on the argument, as that doesn't specify
14957330f729Sjoerg // the output format.
14967330f729Sjoerg }
VisitExpressionTemplateArgument(const TemplateArgument & TA)14977330f729Sjoerg void JSONNodeDumper::VisitExpressionTemplateArgument(
14987330f729Sjoerg const TemplateArgument &TA) {
14997330f729Sjoerg JOS.attribute("isExpr", true);
15007330f729Sjoerg }
VisitPackTemplateArgument(const TemplateArgument & TA)15017330f729Sjoerg void JSONNodeDumper::VisitPackTemplateArgument(const TemplateArgument &TA) {
15027330f729Sjoerg JOS.attribute("isPack", true);
15037330f729Sjoerg }
15047330f729Sjoerg
getCommentCommandName(unsigned CommandID) const15057330f729Sjoerg StringRef JSONNodeDumper::getCommentCommandName(unsigned CommandID) const {
15067330f729Sjoerg if (Traits)
15077330f729Sjoerg return Traits->getCommandInfo(CommandID)->Name;
15087330f729Sjoerg if (const comments::CommandInfo *Info =
15097330f729Sjoerg comments::CommandTraits::getBuiltinCommandInfo(CommandID))
15107330f729Sjoerg return Info->Name;
15117330f729Sjoerg return "<invalid>";
15127330f729Sjoerg }
15137330f729Sjoerg
visitTextComment(const comments::TextComment * C,const comments::FullComment *)15147330f729Sjoerg void JSONNodeDumper::visitTextComment(const comments::TextComment *C,
15157330f729Sjoerg const comments::FullComment *) {
15167330f729Sjoerg JOS.attribute("text", C->getText());
15177330f729Sjoerg }
15187330f729Sjoerg
visitInlineCommandComment(const comments::InlineCommandComment * C,const comments::FullComment *)15197330f729Sjoerg void JSONNodeDumper::visitInlineCommandComment(
15207330f729Sjoerg const comments::InlineCommandComment *C, const comments::FullComment *) {
15217330f729Sjoerg JOS.attribute("name", getCommentCommandName(C->getCommandID()));
15227330f729Sjoerg
15237330f729Sjoerg switch (C->getRenderKind()) {
15247330f729Sjoerg case comments::InlineCommandComment::RenderNormal:
15257330f729Sjoerg JOS.attribute("renderKind", "normal");
15267330f729Sjoerg break;
15277330f729Sjoerg case comments::InlineCommandComment::RenderBold:
15287330f729Sjoerg JOS.attribute("renderKind", "bold");
15297330f729Sjoerg break;
15307330f729Sjoerg case comments::InlineCommandComment::RenderEmphasized:
15317330f729Sjoerg JOS.attribute("renderKind", "emphasized");
15327330f729Sjoerg break;
15337330f729Sjoerg case comments::InlineCommandComment::RenderMonospaced:
15347330f729Sjoerg JOS.attribute("renderKind", "monospaced");
15357330f729Sjoerg break;
1536*e038c9c4Sjoerg case comments::InlineCommandComment::RenderAnchor:
1537*e038c9c4Sjoerg JOS.attribute("renderKind", "anchor");
1538*e038c9c4Sjoerg break;
15397330f729Sjoerg }
15407330f729Sjoerg
15417330f729Sjoerg llvm::json::Array Args;
15427330f729Sjoerg for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I)
15437330f729Sjoerg Args.push_back(C->getArgText(I));
15447330f729Sjoerg
15457330f729Sjoerg if (!Args.empty())
15467330f729Sjoerg JOS.attribute("args", std::move(Args));
15477330f729Sjoerg }
15487330f729Sjoerg
visitHTMLStartTagComment(const comments::HTMLStartTagComment * C,const comments::FullComment *)15497330f729Sjoerg void JSONNodeDumper::visitHTMLStartTagComment(
15507330f729Sjoerg const comments::HTMLStartTagComment *C, const comments::FullComment *) {
15517330f729Sjoerg JOS.attribute("name", C->getTagName());
15527330f729Sjoerg attributeOnlyIfTrue("selfClosing", C->isSelfClosing());
15537330f729Sjoerg attributeOnlyIfTrue("malformed", C->isMalformed());
15547330f729Sjoerg
15557330f729Sjoerg llvm::json::Array Attrs;
15567330f729Sjoerg for (unsigned I = 0, E = C->getNumAttrs(); I < E; ++I)
15577330f729Sjoerg Attrs.push_back(
15587330f729Sjoerg {{"name", C->getAttr(I).Name}, {"value", C->getAttr(I).Value}});
15597330f729Sjoerg
15607330f729Sjoerg if (!Attrs.empty())
15617330f729Sjoerg JOS.attribute("attrs", std::move(Attrs));
15627330f729Sjoerg }
15637330f729Sjoerg
visitHTMLEndTagComment(const comments::HTMLEndTagComment * C,const comments::FullComment *)15647330f729Sjoerg void JSONNodeDumper::visitHTMLEndTagComment(
15657330f729Sjoerg const comments::HTMLEndTagComment *C, const comments::FullComment *) {
15667330f729Sjoerg JOS.attribute("name", C->getTagName());
15677330f729Sjoerg }
15687330f729Sjoerg
visitBlockCommandComment(const comments::BlockCommandComment * C,const comments::FullComment *)15697330f729Sjoerg void JSONNodeDumper::visitBlockCommandComment(
15707330f729Sjoerg const comments::BlockCommandComment *C, const comments::FullComment *) {
15717330f729Sjoerg JOS.attribute("name", getCommentCommandName(C->getCommandID()));
15727330f729Sjoerg
15737330f729Sjoerg llvm::json::Array Args;
15747330f729Sjoerg for (unsigned I = 0, E = C->getNumArgs(); I < E; ++I)
15757330f729Sjoerg Args.push_back(C->getArgText(I));
15767330f729Sjoerg
15777330f729Sjoerg if (!Args.empty())
15787330f729Sjoerg JOS.attribute("args", std::move(Args));
15797330f729Sjoerg }
15807330f729Sjoerg
visitParamCommandComment(const comments::ParamCommandComment * C,const comments::FullComment * FC)15817330f729Sjoerg void JSONNodeDumper::visitParamCommandComment(
15827330f729Sjoerg const comments::ParamCommandComment *C, const comments::FullComment *FC) {
15837330f729Sjoerg switch (C->getDirection()) {
15847330f729Sjoerg case comments::ParamCommandComment::In:
15857330f729Sjoerg JOS.attribute("direction", "in");
15867330f729Sjoerg break;
15877330f729Sjoerg case comments::ParamCommandComment::Out:
15887330f729Sjoerg JOS.attribute("direction", "out");
15897330f729Sjoerg break;
15907330f729Sjoerg case comments::ParamCommandComment::InOut:
15917330f729Sjoerg JOS.attribute("direction", "in,out");
15927330f729Sjoerg break;
15937330f729Sjoerg }
15947330f729Sjoerg attributeOnlyIfTrue("explicit", C->isDirectionExplicit());
15957330f729Sjoerg
15967330f729Sjoerg if (C->hasParamName())
15977330f729Sjoerg JOS.attribute("param", C->isParamIndexValid() ? C->getParamName(FC)
15987330f729Sjoerg : C->getParamNameAsWritten());
15997330f729Sjoerg
16007330f729Sjoerg if (C->isParamIndexValid() && !C->isVarArgParam())
16017330f729Sjoerg JOS.attribute("paramIdx", C->getParamIndex());
16027330f729Sjoerg }
16037330f729Sjoerg
visitTParamCommandComment(const comments::TParamCommandComment * C,const comments::FullComment * FC)16047330f729Sjoerg void JSONNodeDumper::visitTParamCommandComment(
16057330f729Sjoerg const comments::TParamCommandComment *C, const comments::FullComment *FC) {
16067330f729Sjoerg if (C->hasParamName())
16077330f729Sjoerg JOS.attribute("param", C->isPositionValid() ? C->getParamName(FC)
16087330f729Sjoerg : C->getParamNameAsWritten());
16097330f729Sjoerg if (C->isPositionValid()) {
16107330f729Sjoerg llvm::json::Array Positions;
16117330f729Sjoerg for (unsigned I = 0, E = C->getDepth(); I < E; ++I)
16127330f729Sjoerg Positions.push_back(C->getIndex(I));
16137330f729Sjoerg
16147330f729Sjoerg if (!Positions.empty())
16157330f729Sjoerg JOS.attribute("positions", std::move(Positions));
16167330f729Sjoerg }
16177330f729Sjoerg }
16187330f729Sjoerg
visitVerbatimBlockComment(const comments::VerbatimBlockComment * C,const comments::FullComment *)16197330f729Sjoerg void JSONNodeDumper::visitVerbatimBlockComment(
16207330f729Sjoerg const comments::VerbatimBlockComment *C, const comments::FullComment *) {
16217330f729Sjoerg JOS.attribute("name", getCommentCommandName(C->getCommandID()));
16227330f729Sjoerg JOS.attribute("closeName", C->getCloseName());
16237330f729Sjoerg }
16247330f729Sjoerg
visitVerbatimBlockLineComment(const comments::VerbatimBlockLineComment * C,const comments::FullComment *)16257330f729Sjoerg void JSONNodeDumper::visitVerbatimBlockLineComment(
16267330f729Sjoerg const comments::VerbatimBlockLineComment *C,
16277330f729Sjoerg const comments::FullComment *) {
16287330f729Sjoerg JOS.attribute("text", C->getText());
16297330f729Sjoerg }
16307330f729Sjoerg
visitVerbatimLineComment(const comments::VerbatimLineComment * C,const comments::FullComment *)16317330f729Sjoerg void JSONNodeDumper::visitVerbatimLineComment(
16327330f729Sjoerg const comments::VerbatimLineComment *C, const comments::FullComment *) {
16337330f729Sjoerg JOS.attribute("text", C->getText());
16347330f729Sjoerg }
1635