[clang] 2107d87 - [clang] Add missing field to VisibilityAttr json AST dump

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 14 14:00:16 PDT 2023


Author: serge-sans-paille
Date: 2023-08-14T22:59:45+02:00
New Revision: 2107d87c5a9103ffc4c0f76fc00ab203603f9df1

URL: https://github.com/llvm/llvm-project/commit/2107d87c5a9103ffc4c0f76fc00ab203603f9df1
DIFF: https://github.com/llvm/llvm-project/commit/2107d87c5a9103ffc4c0f76fc00ab203603f9df1.diff

LOG: [clang] Add missing field to VisibilityAttr json AST dump

Differential Revision: https://reviews.llvm.org/D157808

Added: 
    

Modified: 
    clang/include/clang/AST/JSONNodeDumper.h
    clang/lib/AST/JSONNodeDumper.cpp
    clang/test/AST/ast-dump-attr-json.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h
index 089c0e97a90472..03c903069ad877 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -213,6 +213,7 @@ class JSONNodeDumper
   void VisitDeprecatedAttr(const DeprecatedAttr *DA);
   void VisitUnavailableAttr(const UnavailableAttr *UA);
   void VisitSectionAttr(const SectionAttr *SA);
+  void VisitVisibilityAttr(const VisibilityAttr *VA);
 
   void VisitTypedefType(const TypedefType *TT);
   void VisitUsingType(const UsingType *TT);

diff  --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index ec5661d1d6944d..134938a1ef19a0 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -554,6 +554,11 @@ void JSONNodeDumper::VisitSectionAttr(const SectionAttr *SA) {
   JOS.attribute("section_name", SA->getName());
 }
 
+void JSONNodeDumper::VisitVisibilityAttr(const VisibilityAttr *VA) {
+  JOS.attribute("visibility", VisibilityAttr::ConvertVisibilityTypeToStr(
+                                  VA->getVisibility()));
+}
+
 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
   if (!TT->typeMatchesDecl())

diff  --git a/clang/test/AST/ast-dump-attr-json.cpp b/clang/test/AST/ast-dump-attr-json.cpp
index a9679695e954f1..0eb930b851a15e 100644
--- a/clang/test/AST/ast-dump-attr-json.cpp
+++ b/clang/test/AST/ast-dump-attr-json.cpp
@@ -17,6 +17,9 @@ __attribute__((unavailable("reason"))) int unavailable_var1;
 
 __attribute__ ((section ("SECTION_NAME"))) int section_var;
 
+__attribute__ ((visibility ("hidden"))) int visibility_var;
+
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 // using --filters=VarDecl
 
@@ -429,3 +432,50 @@ __attribute__ ((section ("SECTION_NAME"))) int section_var;
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK:  "kind": "VarDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": 651,
+// CHECK-NEXT:   "line": 20,
+// CHECK-NEXT:   "col": 45,
+// CHECK-NEXT:   "tokLen": 14
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:    "offset": 607,
+// CHECK-NEXT:    "col": 1,
+// CHECK-NEXT:    "tokLen": 13
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:    "offset": 651,
+// CHECK-NEXT:    "col": 45,
+// CHECK-NEXT:    "tokLen": 14
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "visibility_var",
+// CHECK-NEXT:  "mangledName": "visibility_var",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:    "id": "0x{{.*}}",
+// CHECK-NEXT:    "kind": "VisibilityAttr",
+// CHECK-NEXT:    "range": {
+// CHECK-NEXT:     "begin": {
+// CHECK-NEXT:      "offset": 623,
+// CHECK-NEXT:      "col": 17,
+// CHECK-NEXT:      "tokLen": 10
+// CHECK-NEXT:     },
+// CHECK-NEXT:     "end": {
+// CHECK-NEXT:      "offset": 643,
+// CHECK-NEXT:      "col": 37,
+// CHECK-NEXT:      "tokLen": 1
+// CHECK-NEXT:     }
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "visibility": "hidden"
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }


        


More information about the cfe-commits mailing list