aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp142
1 files changed, 132 insertions, 10 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp b/contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp
index 7b99546bbe2d..958b0e6cf2ef 100644
--- a/contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp
+++ b/contrib/llvm-project/clang/lib/AST/JSONNodeDumper.cpp
@@ -1,8 +1,10 @@
#include "clang/AST/JSONNodeDumper.h"
+#include "clang/AST/Type.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Lex/Lexer.h"
-#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/StringExtras.h"
+#include <optional>
using namespace clang;
@@ -59,7 +61,9 @@ void JSONNodeDumper::Visit(const Stmt *S) {
switch (E->getValueKind()) {
case VK_LValue: Category = "lvalue"; break;
case VK_XValue: Category = "xvalue"; break;
- case VK_RValue: Category = "rvalue"; break;
+ case VK_PRValue:
+ Category = "prvalue";
+ break;
}
JOS.attribute("valueCategory", Category);
}
@@ -183,6 +187,35 @@ void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
attributeOnlyIfTrue("selected", A.isSelected());
}
+void JSONNodeDumper::Visit(const concepts::Requirement *R) {
+ if (!R)
+ return;
+
+ switch (R->getKind()) {
+ case concepts::Requirement::RK_Type:
+ JOS.attribute("kind", "TypeRequirement");
+ break;
+ case concepts::Requirement::RK_Simple:
+ JOS.attribute("kind", "SimpleRequirement");
+ break;
+ case concepts::Requirement::RK_Compound:
+ JOS.attribute("kind", "CompoundRequirement");
+ break;
+ case concepts::Requirement::RK_Nested:
+ JOS.attribute("kind", "NestedRequirement");
+ break;
+ }
+
+ if (auto *ER = dyn_cast<concepts::ExprRequirement>(R))
+ attributeOnlyIfTrue("noexcept", ER->hasNoexceptRequirement());
+
+ attributeOnlyIfTrue("isDependent", R->isDependent());
+ if (!R->isDependent())
+ JOS.attribute("satisfied", R->isSatisfied());
+ attributeOnlyIfTrue("containsUnexpandedPack",
+ R->containsUnexpandedParameterPack());
+}
+
void JSONNodeDumper::Visit(const APValue &Value, QualType Ty) {
std::string Str;
llvm::raw_string_ostream OS(Str);
@@ -499,6 +532,14 @@ JSONNodeDumper::createCXXBaseSpecifier(const CXXBaseSpecifier &BS) {
void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
+ if (!TT->typeMatchesDecl())
+ JOS.attribute("type", createQualType(TT->desugar()));
+}
+
+void JSONNodeDumper::VisitUsingType(const UsingType *TT) {
+ JOS.attribute("decl", createBareDeclRef(TT->getFoundDecl()));
+ if (!TT->typeMatchesDecl())
+ JOS.attribute("type", createQualType(TT->desugar()));
}
void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
@@ -622,6 +663,9 @@ void JSONNodeDumper::VisitVectorType(const VectorType *VT) {
case VectorType::SveFixedLengthPredicateVector:
JOS.attribute("vectorKind", "fixed-length sve predicate vector");
break;
+ case VectorType::RVVFixedLengthDataVector:
+ JOS.attribute("vectorKind", "fixed-length rvv data vector");
+ break;
}
}
@@ -631,9 +675,11 @@ void JSONNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *UUT) {
void JSONNodeDumper::VisitUnaryTransformType(const UnaryTransformType *UTT) {
switch (UTT->getUTTKind()) {
- case UnaryTransformType::EnumUnderlyingType:
- JOS.attribute("transformKind", "underlying_type");
+#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
+ case UnaryTransformType::Enum: \
+ JOS.attribute("transformKind", #Trait); \
break;
+#include "clang/Basic/TransformTypeTraits.def"
}
}
@@ -649,6 +695,18 @@ void JSONNodeDumper::VisitTemplateTypeParmType(
JOS.attribute("decl", createBareDeclRef(TTPT->getDecl()));
}
+void JSONNodeDumper::VisitSubstTemplateTypeParmType(
+ const SubstTemplateTypeParmType *STTPT) {
+ JOS.attribute("index", STTPT->getIndex());
+ if (auto PackIndex = STTPT->getPackIndex())
+ JOS.attribute("pack_index", *PackIndex);
+}
+
+void JSONNodeDumper::VisitSubstTemplateTypeParmPackType(
+ const SubstTemplateTypeParmPackType *T) {
+ JOS.attribute("index", T->getIndex());
+}
+
void JSONNodeDumper::VisitAutoType(const AutoType *AT) {
JOS.attribute("undeduced", !AT->isDeduced());
switch (AT->getKeyword()) {
@@ -684,7 +742,7 @@ void JSONNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
}
void JSONNodeDumper::VisitPackExpansionType(const PackExpansionType *PET) {
- if (llvm::Optional<unsigned> N = PET->getNumExpansions())
+ if (std::optional<unsigned> N = PET->getNumExpansions())
JOS.attribute("numExpansions", *N);
}
@@ -711,6 +769,23 @@ void JSONNodeDumper::VisitMemberPointerType(const MemberPointerType *MPT) {
void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
if (ND && ND->getDeclName()) {
JOS.attribute("name", ND->getNameAsString());
+ // FIXME: There are likely other contexts in which it makes no sense to ask
+ // for a mangled name.
+ if (isa<RequiresExprBodyDecl>(ND->getDeclContext()))
+ return;
+
+ // If the declaration is dependent or is in a dependent context, then the
+ // mangling is unlikely to be meaningful (and in some cases may cause
+ // "don't know how to mangle this" assertion failures.
+ if (ND->isTemplated())
+ return;
+
+ // Mangled names are not meaningful for locals, and may not be well-defined
+ // in the case of VLAs.
+ auto *VD = dyn_cast<VarDecl>(ND);
+ if (VD && VD->hasLocalStorage())
+ return;
+
std::string MangledName = ASTNameGen.getName(ND);
if (!MangledName.empty())
JOS.attribute("mangledName", MangledName);
@@ -730,6 +805,7 @@ void JSONNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *TAD) {
void JSONNodeDumper::VisitNamespaceDecl(const NamespaceDecl *ND) {
VisitNamedDecl(ND);
attributeOnlyIfTrue("isInline", ND->isInline());
+ attributeOnlyIfTrue("isNested", ND->isNested());
if (!ND->isOriginalNamespace())
JOS.attribute("originalNamespace",
createBareDeclRef(ND->getOriginalNamespace()));
@@ -756,6 +832,10 @@ void JSONNodeDumper::VisitUsingDecl(const UsingDecl *UD) {
JOS.attribute("name", Name);
}
+void JSONNodeDumper::VisitUsingEnumDecl(const UsingEnumDecl *UED) {
+ JOS.attribute("target", createBareDeclRef(UED->getEnumDecl()));
+}
+
void JSONNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *USD) {
JOS.attribute("target", createBareDeclRef(USD->getTargetDecl()));
}
@@ -781,6 +861,9 @@ void JSONNodeDumper::VisitVarDecl(const VarDecl *VD) {
case VarDecl::CInit: JOS.attribute("init", "c"); break;
case VarDecl::CallInit: JOS.attribute("init", "call"); break;
case VarDecl::ListInit: JOS.attribute("init", "list"); break;
+ case VarDecl::ParenListInit:
+ JOS.attribute("init", "paren-list");
+ break;
}
}
attributeOnlyIfTrue("isParameterPack", VD->isParameterPack());
@@ -807,6 +890,7 @@ void JSONNodeDumper::VisitFunctionDecl(const FunctionDecl *FD) {
attributeOnlyIfTrue("explicitlyDeleted", FD->isDeletedAsWritten());
attributeOnlyIfTrue("constexpr", FD->isConstexpr());
attributeOnlyIfTrue("variadic", FD->isVariadic());
+ attributeOnlyIfTrue("immediate", FD->isImmediateFunction());
if (FD->isDefaulted())
JOS.attribute("explicitlyDefaulted",
@@ -847,6 +931,11 @@ void JSONNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *RD) {
}
}
+void JSONNodeDumper::VisitHLSLBufferDecl(const HLSLBufferDecl *D) {
+ VisitNamedDecl(D);
+ JOS.attribute("bufferKind", D->isCBuffer() ? "cbuffer" : "tbuffer");
+}
+
void JSONNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
VisitNamedDecl(D);
JOS.attribute("tagUsed", D->wasDeclaredWithTypename() ? "typename" : "class");
@@ -887,9 +976,10 @@ void JSONNodeDumper::VisitTemplateTemplateParmDecl(
if (D->hasDefaultArgument())
JOS.attributeObject("defaultArg", [=] {
+ const auto *InheritedFrom = D->getDefaultArgStorage().getInheritedFrom();
Visit(D->getDefaultArgument().getArgument(),
- D->getDefaultArgStorage().getInheritedFrom()->getSourceRange(),
- D->getDefaultArgStorage().getInheritedFrom(),
+ InheritedFrom ? InheritedFrom->getSourceRange() : SourceLocation{},
+ InheritedFrom,
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
});
}
@@ -1161,6 +1251,13 @@ void JSONNodeDumper::VisitDeclRefExpr(const DeclRefExpr *DRE) {
case NOUR_Constant: JOS.attribute("nonOdrUseReason", "constant"); break;
case NOUR_Discarded: JOS.attribute("nonOdrUseReason", "discarded"); break;
}
+ attributeOnlyIfTrue("isImmediateEscalating", DRE->isImmediateEscalating());
+}
+
+void JSONNodeDumper::VisitSYCLUniqueStableNameExpr(
+ const SYCLUniqueStableNameExpr *E) {
+ JOS.attribute("typeSourceInfo",
+ createQualType(E->getTypeSourceInfo()->getType()));
}
void JSONNodeDumper::VisitPredefinedExpr(const PredefinedExpr *PE) {
@@ -1314,6 +1411,7 @@ void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) {
attributeOnlyIfTrue("initializer_list", CE->isStdInitListInitialization());
attributeOnlyIfTrue("zeroing", CE->requiresZeroInitialization());
attributeOnlyIfTrue("hadMultipleCandidates", CE->hadMultipleCandidates());
+ attributeOnlyIfTrue("isImmediateEscalating", CE->isImmediateEscalating());
switch (CE->getConstructionKind()) {
case CXXConstructExpr::CK_Complete:
@@ -1402,10 +1500,16 @@ void JSONNodeDumper::VisitCXXDependentScopeMemberExpr(
}
}
+void JSONNodeDumper::VisitRequiresExpr(const RequiresExpr *RE) {
+ if (!RE->isValueDependent())
+ JOS.attribute("satisfied", RE->isSatisfied());
+}
+
void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
- JOS.attribute("value",
- IL->getValue().toString(
- /*Radix=*/10, IL->getType()->isSignedIntegerType()));
+ llvm::SmallString<16> Buffer;
+ IL->getValue().toString(Buffer,
+ /*Radix=*/10, IL->getType()->isSignedIntegerType());
+ JOS.attribute("value", Buffer);
}
void JSONNodeDumper::VisitCharacterLiteral(const CharacterLiteral *CL) {
// FIXME: This should probably print the character literal as a string,
@@ -1437,6 +1541,8 @@ void JSONNodeDumper::VisitIfStmt(const IfStmt *IS) {
attributeOnlyIfTrue("hasVar", IS->hasVarStorage());
attributeOnlyIfTrue("hasElse", IS->hasElseStorage());
attributeOnlyIfTrue("isConstexpr", IS->isConstexpr());
+ attributeOnlyIfTrue("isConsteval", IS->isConsteval());
+ attributeOnlyIfTrue("constevalIsNegated", IS->isNegatedConsteval());
}
void JSONNodeDumper::VisitSwitchStmt(const SwitchStmt *SS) {
@@ -1450,6 +1556,7 @@ void JSONNodeDumper::VisitCaseStmt(const CaseStmt *CS) {
void JSONNodeDumper::VisitLabelStmt(const LabelStmt *LS) {
JOS.attribute("name", LS->getName());
JOS.attribute("declId", createPointerRepresentation(LS->getDecl()));
+ attributeOnlyIfTrue("sideEntry", LS->isSideEntry());
}
void JSONNodeDumper::VisitGotoStmt(const GotoStmt *GS) {
JOS.attribute("targetLabelDeclId",
@@ -1630,3 +1737,18 @@ void JSONNodeDumper::visitVerbatimLineComment(
const comments::VerbatimLineComment *C, const comments::FullComment *) {
JOS.attribute("text", C->getText());
}
+
+llvm::json::Object JSONNodeDumper::createFPOptions(FPOptionsOverride FPO) {
+ llvm::json::Object Ret;
+#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
+ if (FPO.has##NAME##Override()) \
+ Ret.try_emplace(#NAME, static_cast<unsigned>(FPO.get##NAME##Override()));
+#include "clang/Basic/FPOptions.def"
+ return Ret;
+}
+
+void JSONNodeDumper::VisitCompoundStmt(const CompoundStmt *S) {
+ VisitStmt(S);
+ if (S->hasStoredFPFeatures())
+ JOS.attribute("fpoptions", createFPOptions(S->getStoredFPFeatures()));
+}