From: Aaron Ballman Date: Mon, 27 May 2019 14:25:04 +0000 (+0000) Subject: When dumping the AST to JSON, dump the declared name of a MemberExpr operand. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b50f14e080d6ba12815e379b1ec18fbf991dfc4;p=clang When dumping the AST to JSON, dump the declared name of a MemberExpr operand. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361767 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/JSONNodeDumper.cpp b/lib/AST/JSONNodeDumper.cpp index a6600c0c84..760ea33812 100644 --- a/lib/AST/JSONNodeDumper.cpp +++ b/lib/AST/JSONNodeDumper.cpp @@ -829,9 +829,10 @@ void JSONNodeDumper::VisitCompoundAssignOperator( void JSONNodeDumper::VisitMemberExpr(const MemberExpr *ME) { // Note, we always write this Boolean field because the information it conveys // is critical to understanding the AST node. + ValueDecl *VD = ME->getMemberDecl(); + JOS.attribute("name", VD && VD->getDeclName() ? VD->getNameAsString() : ""); JOS.attribute("isArrow", ME->isArrow()); - JOS.attribute("referencedMemberDecl", - createPointerRepresentation(ME->getMemberDecl())); + JOS.attribute("referencedMemberDecl", createPointerRepresentation(VD)); } void JSONNodeDumper::VisitCXXNewExpr(const CXXNewExpr *NE) { diff --git a/test/AST/ast-dump-expr-json.c b/test/AST/ast-dump-expr-json.c index a2d6aab142..77183be2f9 100644 --- a/test/AST/ast-dump-expr-json.c +++ b/test/AST/ast-dump-expr-json.c @@ -4433,6 +4433,7 @@ void PrimaryExpressions(int a) { // CHECK-NEXT: "qualType": "int" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "lvalue", +// CHECK-NEXT: "name": "a", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -4510,6 +4511,7 @@ void PrimaryExpressions(int a) { // CHECK-NEXT: "qualType": "int" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "lvalue", +// CHECK-NEXT: "name": "a", // CHECK-NEXT: "isArrow": true, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ diff --git a/test/AST/ast-dump-expr-json.cpp b/test/AST/ast-dump-expr-json.cpp index 0c541666d2..15a93a08a8 100644 --- a/test/AST/ast-dump-expr-json.cpp +++ b/test/AST/ast-dump-expr-json.cpp @@ -2584,6 +2584,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "func", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -2679,6 +2680,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "func", // CHECK-NEXT: "isArrow": true, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -2798,6 +2800,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "foo", // CHECK-NEXT: "isArrow": true, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -2896,6 +2899,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "foo", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -2970,6 +2974,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "~S", // CHECK-NEXT: "isArrow": true, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -3067,6 +3072,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "~S", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -3141,6 +3147,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "~S", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -3215,6 +3222,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "~S", // CHECK-NEXT: "isArrow": true, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -3312,6 +3320,7 @@ void TestNonADLCall3() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "~U", // CHECK-NEXT: "isArrow": true, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ diff --git a/test/AST/ast-dump-stmt-json.cpp b/test/AST/ast-dump-stmt-json.cpp index 448857ea3e..883ac59409 100644 --- a/test/AST/ast-dump-stmt-json.cpp +++ b/test/AST/ast-dump-stmt-json.cpp @@ -4653,6 +4653,7 @@ void TestIteration() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "begin", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [ @@ -4799,6 +4800,7 @@ void TestIteration() { // CHECK-NEXT: "qualType": "" // CHECK-NEXT: }, // CHECK-NEXT: "valueCategory": "rvalue", +// CHECK-NEXT: "name": "end", // CHECK-NEXT: "isArrow": false, // CHECK-NEXT: "referencedMemberDecl": "0x{{.*}}", // CHECK-NEXT: "inner": [