diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /clang/lib/AST/JSONNodeDumper.cpp | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) | |
download | src-cfca06d7963fa0909f90483b42a6d7d194d01e08.tar.gz src-cfca06d7963fa0909f90483b42a6d7d194d01e08.zip |
Vendor import of llvm-project master 2e10b7a39b9, the last commit beforevendor/llvm-project/llvmorg-11-init-20887-g2e10b7a39b9vendor/llvm-project/master
the llvmorg-12-init tag, from which release/11.x was branched.
Notes
Notes:
svn path=/vendor/llvm-project/master/; revision=363578
svn path=/vendor/llvm-project/llvmorg-11-init-20887-g2e10b7a39b9/; revision=363579; tag=vendor/llvm-project/llvmorg-11-init-20887-g2e10b7a39b9
Diffstat (limited to 'clang/lib/AST/JSONNodeDumper.cpp')
-rw-r--r-- | clang/lib/AST/JSONNodeDumper.cpp | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index c30b07137edc..4bd00ece86ab 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -1,4 +1,6 @@ #include "clang/AST/JSONNodeDumper.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Basic/Specifiers.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/StringSwitch.h" @@ -72,6 +74,7 @@ void JSONNodeDumper::Visit(const Type *T) { JOS.attribute("kind", (llvm::Twine(T->getTypeClassName()) + "Type").str()); JOS.attribute("type", createQualType(QualType(T, 0), /*Desugar*/ false)); + attributeOnlyIfTrue("containsErrors", T->containsErrors()); attributeOnlyIfTrue("isDependent", T->isDependentType()); attributeOnlyIfTrue("isInstantiationDependent", T->isInstantiationDependentType()); @@ -109,7 +112,7 @@ void JSONNodeDumper::Visit(const Decl *D) { JOS.attribute("isReferenced", true); if (const auto *ND = dyn_cast<NamedDecl>(D)) - attributeOnlyIfTrue("isHidden", ND->isHidden()); + attributeOnlyIfTrue("isHidden", !ND->isUnconditionallyVisible()); if (D->getLexicalDeclContext() != D->getDeclContext()) { // Because of multiple inheritance, a DeclContext pointer does not produce @@ -180,6 +183,13 @@ void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { attributeOnlyIfTrue("selected", A.isSelected()); } +void JSONNodeDumper::Visit(const APValue &Value, QualType Ty) { + std::string Str; + llvm::raw_string_ostream OS(Str); + Value.printPretty(OS, Ctx, Ty); + JOS.attribute("value", OS.str()); +} + void JSONNodeDumper::writeIncludeStack(PresumedLoc Loc, bool JustFirst) { if (Loc.isInvalid()) return; @@ -384,6 +394,7 @@ static llvm::json::Object createCopyAssignmentDefinitionData(const CXXRecordDecl *RD) { llvm::json::Object Ret; + FIELD2("simple", hasSimpleCopyAssignment); FIELD2("trivial", hasTrivialCopyAssignment); FIELD2("nonTrivial", hasNonTrivialCopyAssignment); FIELD2("hasConstParam", hasCopyAssignmentWithConstParam); @@ -464,13 +475,10 @@ JSONNodeDumper::createCXXRecordDefinitionData(const CXXRecordDecl *RD) { #undef FIELD2 std::string JSONNodeDumper::createAccessSpecifier(AccessSpecifier AS) { - switch (AS) { - case AS_none: return "none"; - case AS_private: return "private"; - case AS_protected: return "protected"; - case AS_public: return "public"; - } - llvm_unreachable("Unknown access specifier"); + const auto AccessSpelling = getAccessSpelling(AS); + if (AccessSpelling.empty()) + return "none"; + return AccessSpelling.str(); } llvm::json::Object @@ -997,32 +1005,33 @@ void JSONNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { case ObjCPropertyDecl::Required: JOS.attribute("control", "required"); break; case ObjCPropertyDecl::Optional: JOS.attribute("control", "optional"); break; } - - ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes(); - if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) { - if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) + + ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes(); + if (Attrs != ObjCPropertyAttribute::kind_noattr) { + if (Attrs & ObjCPropertyAttribute::kind_getter) JOS.attribute("getter", createBareDeclRef(D->getGetterMethodDecl())); - if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) + if (Attrs & ObjCPropertyAttribute::kind_setter) JOS.attribute("setter", createBareDeclRef(D->getSetterMethodDecl())); - attributeOnlyIfTrue("readonly", Attrs & ObjCPropertyDecl::OBJC_PR_readonly); - attributeOnlyIfTrue("assign", Attrs & ObjCPropertyDecl::OBJC_PR_assign); + attributeOnlyIfTrue("readonly", + Attrs & ObjCPropertyAttribute::kind_readonly); + attributeOnlyIfTrue("assign", Attrs & ObjCPropertyAttribute::kind_assign); attributeOnlyIfTrue("readwrite", - Attrs & ObjCPropertyDecl::OBJC_PR_readwrite); - attributeOnlyIfTrue("retain", Attrs & ObjCPropertyDecl::OBJC_PR_retain); - attributeOnlyIfTrue("copy", Attrs & ObjCPropertyDecl::OBJC_PR_copy); + Attrs & ObjCPropertyAttribute::kind_readwrite); + attributeOnlyIfTrue("retain", Attrs & ObjCPropertyAttribute::kind_retain); + attributeOnlyIfTrue("copy", Attrs & ObjCPropertyAttribute::kind_copy); attributeOnlyIfTrue("nonatomic", - Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic); - attributeOnlyIfTrue("atomic", Attrs & ObjCPropertyDecl::OBJC_PR_atomic); - attributeOnlyIfTrue("weak", Attrs & ObjCPropertyDecl::OBJC_PR_weak); - attributeOnlyIfTrue("strong", Attrs & ObjCPropertyDecl::OBJC_PR_strong); + Attrs & ObjCPropertyAttribute::kind_nonatomic); + attributeOnlyIfTrue("atomic", Attrs & ObjCPropertyAttribute::kind_atomic); + attributeOnlyIfTrue("weak", Attrs & ObjCPropertyAttribute::kind_weak); + attributeOnlyIfTrue("strong", Attrs & ObjCPropertyAttribute::kind_strong); attributeOnlyIfTrue("unsafe_unretained", - Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained); - attributeOnlyIfTrue("class", Attrs & ObjCPropertyDecl::OBJC_PR_class); - attributeOnlyIfTrue("direct", Attrs & ObjCPropertyDecl::OBJC_PR_direct); + Attrs & ObjCPropertyAttribute::kind_unsafe_unretained); + attributeOnlyIfTrue("class", Attrs & ObjCPropertyAttribute::kind_class); + attributeOnlyIfTrue("direct", Attrs & ObjCPropertyAttribute::kind_direct); attributeOnlyIfTrue("nullability", - Attrs & ObjCPropertyDecl::OBJC_PR_nullability); + Attrs & ObjCPropertyAttribute::kind_nullability); attributeOnlyIfTrue("null_resettable", - Attrs & ObjCPropertyDecl::OBJC_PR_null_resettable); + Attrs & ObjCPropertyAttribute::kind_null_resettable); } } @@ -1234,14 +1243,7 @@ void JSONNodeDumper::VisitCallExpr(const CallExpr *CE) { void JSONNodeDumper::VisitUnaryExprOrTypeTraitExpr( const UnaryExprOrTypeTraitExpr *TTE) { - switch (TTE->getKind()) { - case UETT_SizeOf: JOS.attribute("name", "sizeof"); break; - case UETT_AlignOf: JOS.attribute("name", "alignof"); break; - case UETT_VecStep: JOS.attribute("name", "vec_step"); break; - case UETT_PreferredAlignOf: JOS.attribute("name", "__alignof"); break; - case UETT_OpenMPRequiredSimdAlign: - JOS.attribute("name", "__builtin_omp_required_simd_align"); break; - } + JOS.attribute("name", getTraitSpelling(TTE->getKind())); if (TTE->isArgumentType()) JOS.attribute("argType", createQualType(TTE->getArgumentType())); } @@ -1277,12 +1279,8 @@ void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) { } void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) { - if (CE->getResultAPValueKind() != APValue::None) { - std::string Str; - llvm::raw_string_ostream OS(Str); - CE->getAPValueResult().printPretty(OS, Ctx, CE->getType()); - JOS.attribute("value", OS.str()); - } + if (CE->getResultAPValueKind() != APValue::None) + Visit(CE->getAPValueResult(), CE->getType()); } void JSONNodeDumper::VisitInitListExpr(const InitListExpr *ILE) { @@ -1333,7 +1331,16 @@ void JSONNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *EWC) { if (EWC->getNumObjects()) { JOS.attributeArray("cleanups", [this, EWC] { for (const ExprWithCleanups::CleanupObject &CO : EWC->getObjects()) - JOS.value(createBareDeclRef(CO)); + if (auto *BD = CO.dyn_cast<BlockDecl *>()) { + JOS.value(createBareDeclRef(BD)); + } else if (auto *CLE = CO.dyn_cast<CompoundLiteralExpr *>()) { + llvm::json::Object Obj; + Obj["id"] = createPointerRepresentation(CLE); + Obj["kind"] = CLE->getStmtClassName(); + JOS.value(std::move(Obj)); + } else { + llvm_unreachable("unexpected cleanup object type"); + } }); } } |