From: Aaron Ballman Date: Wed, 19 Jun 2019 19:12:22 +0000 (+0000) Subject: Dump the value calculated by a constant expression when dumping the AST to JSON. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d506f2ece4a020ba3eb92f2584dcbbc2924afa71;p=clang Dump the value calculated by a constant expression when dumping the AST to JSON. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363866 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/JSONNodeDumper.h b/include/clang/AST/JSONNodeDumper.h index 024f1f78ce..4c34d79a27 100644 --- a/include/clang/AST/JSONNodeDumper.h +++ b/include/clang/AST/JSONNodeDumper.h @@ -250,6 +250,7 @@ public: void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE); void VisitAddrLabelExpr(const AddrLabelExpr *ALE); void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE); + void VisitConstantExpr(const ConstantExpr *CE); void VisitIntegerLiteral(const IntegerLiteral *IL); void VisitCharacterLiteral(const CharacterLiteral *CL); diff --git a/lib/AST/JSONNodeDumper.cpp b/lib/AST/JSONNodeDumper.cpp index b6768aef27..59da96cee2 100644 --- a/lib/AST/JSONNodeDumper.cpp +++ b/lib/AST/JSONNodeDumper.cpp @@ -975,6 +975,15 @@ 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()); + } +} + void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) { JOS.attribute("value", IL->getValue().toString( diff --git a/test/AST/ast-dump-if-json.cpp b/test/AST/ast-dump-if-json.cpp index 59a7bcbc5d..1d10329211 100644 --- a/test/AST/ast-dump-if-json.cpp +++ b/test/AST/ast-dump-if-json.cpp @@ -528,6 +528,7 @@ void func(int val) { // CHECK-NEXT: "qualType": "bool" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "value": "true", // CHECK-NEXT: "inner": [ // CHECK-NEXT: { // CHECK-NEXT: "id": "0x{{.*}}", diff --git a/test/AST/ast-dump-stmt-json.cpp b/test/AST/ast-dump-stmt-json.cpp index 78d29ffc39..ecdb8338f4 100644 --- a/test/AST/ast-dump-stmt-json.cpp +++ b/test/AST/ast-dump-stmt-json.cpp @@ -2951,6 +2951,7 @@ void TestIteration() { // CHECK-NEXT: "qualType": "bool" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "value": "true", // CHECK-NEXT: "inner": [ // CHECK-NEXT: { // CHECK-NEXT: "id": "0x{{.*}}", @@ -3150,6 +3151,7 @@ void TestIteration() { // CHECK-NEXT: "qualType": "bool" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "value": "true", // CHECK-NEXT: "inner": [ // CHECK-NEXT: { // CHECK-NEXT: "id": "0x{{.*}}",