Browse Source

Print information about various type nodes when dumping the AST to JSON.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364043 91177308-0d34-0410-b5e6-96231b3b80d8
Aaron Ballman 6 years ago
parent
commit
058e59f64a

+ 14 - 0
include/clang/AST/JSONNodeDumper.h

@@ -197,6 +197,20 @@ public:
   void VisitTypedefType(const TypedefType *TT);
   void VisitFunctionType(const FunctionType *T);
   void VisitFunctionProtoType(const FunctionProtoType *T);
+  void VisitRValueReferenceType(const ReferenceType *RT);
+  void VisitArrayType(const ArrayType *AT);
+  void VisitConstantArrayType(const ConstantArrayType *CAT);
+  void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *VT);
+  void VisitVectorType(const VectorType *VT);
+  void VisitUnresolvedUsingType(const UnresolvedUsingType *UUT);
+  void VisitUnaryTransformType(const UnaryTransformType *UTT);
+  void VisitTagType(const TagType *TT);
+  void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT);
+  void VisitAutoType(const AutoType *AT);
+  void VisitTemplateSpecializationType(const TemplateSpecializationType *TST);
+  void VisitInjectedClassNameType(const InjectedClassNameType *ICNT);
+  void VisitObjCInterfaceType(const ObjCInterfaceType *OIT);
+  void VisitPackExpansionType(const PackExpansionType *PET);
 
   void VisitNamedDecl(const NamedDecl *ND);
   void VisitTypedefDecl(const TypedefDecl *TD);

+ 119 - 0
lib/AST/JSONNodeDumper.cpp

@@ -492,6 +492,125 @@ void JSONNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
   VisitFunctionType(T);
 }
 
+void JSONNodeDumper::VisitRValueReferenceType(const ReferenceType *RT) {
+  attributeOnlyIfTrue("spelledAsLValue", RT->isSpelledAsLValue());
+}
+
+void JSONNodeDumper::VisitArrayType(const ArrayType *AT) {
+  switch (AT->getSizeModifier()) {
+  case ArrayType::Star:
+    JOS.attribute("sizeModifier", "*");
+    break;
+  case ArrayType::Static:
+    JOS.attribute("sizeModifier", "static");
+    break;
+  case ArrayType::Normal:
+    break;
+  }
+
+  std::string Str = AT->getIndexTypeQualifiers().getAsString();
+  if (!Str.empty())
+    JOS.attribute("indexTypeQualifiers", Str);
+}
+
+void JSONNodeDumper::VisitConstantArrayType(const ConstantArrayType *CAT) {
+  // FIXME: this should use ZExt instead of SExt, but JSON doesn't allow a
+  // narrowing conversion to int64_t so it cannot be expressed.
+  JOS.attribute("size", CAT->getSize().getSExtValue());
+  VisitArrayType(CAT);
+}
+
+void JSONNodeDumper::VisitDependentSizedExtVectorType(
+    const DependentSizedExtVectorType *VT) {
+  JOS.attribute("attrLoc", createSourceLocation(VT->getAttributeLoc()));
+}
+
+void JSONNodeDumper::VisitVectorType(const VectorType *VT) {
+  JOS.attribute("numElements", VT->getNumElements());
+  switch (VT->getVectorKind()) {
+  case VectorType::GenericVector:
+    break;
+  case VectorType::AltiVecVector:
+    JOS.attribute("vectorKind", "altivec");
+    break;
+  case VectorType::AltiVecPixel:
+    JOS.attribute("vectorKind", "altivec pixel");
+    break;
+  case VectorType::AltiVecBool:
+    JOS.attribute("vectorKind", "altivec bool");
+    break;
+  case VectorType::NeonVector:
+    JOS.attribute("vectorKind", "neon");
+    break;
+  case VectorType::NeonPolyVector:
+    JOS.attribute("vectorKind", "neon poly");
+    break;
+  }
+}
+
+void JSONNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *UUT) {
+  JOS.attribute("decl", createBareDeclRef(UUT->getDecl()));
+}
+
+void JSONNodeDumper::VisitUnaryTransformType(const UnaryTransformType *UTT) {
+  switch (UTT->getUTTKind()) {
+  case UnaryTransformType::EnumUnderlyingType:
+    JOS.attribute("transformKind", "underlying_type");
+    break;
+  }
+}
+
+void JSONNodeDumper::VisitTagType(const TagType *TT) {
+  JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
+}
+
+void JSONNodeDumper::VisitTemplateTypeParmType(
+    const TemplateTypeParmType *TTPT) {
+  JOS.attribute("depth", TTPT->getDepth());
+  JOS.attribute("index", TTPT->getIndex());
+  attributeOnlyIfTrue("isPack", TTPT->isParameterPack());
+  JOS.attribute("decl", createBareDeclRef(TTPT->getDecl()));
+}
+
+void JSONNodeDumper::VisitAutoType(const AutoType *AT) {
+  JOS.attribute("undeduced", !AT->isDeduced());
+  switch (AT->getKeyword()) {
+  case AutoTypeKeyword::Auto:
+    JOS.attribute("typeKeyword", "auto");
+    break;
+  case AutoTypeKeyword::DecltypeAuto:
+    JOS.attribute("typeKeyword", "decltype(auto)");
+    break;
+  case AutoTypeKeyword::GNUAutoType:
+    JOS.attribute("typeKeyword", "__auto_type");
+    break;
+  }
+}
+
+void JSONNodeDumper::VisitTemplateSpecializationType(
+    const TemplateSpecializationType *TST) {
+  attributeOnlyIfTrue("isAlias", TST->isTypeAlias());
+
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  TST->getTemplateName().print(OS, PrintPolicy);
+  JOS.attribute("templateName", OS.str());
+}
+
+void JSONNodeDumper::VisitInjectedClassNameType(
+    const InjectedClassNameType *ICNT) {
+  JOS.attribute("decl", createBareDeclRef(ICNT->getDecl()));
+}
+
+void JSONNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
+  JOS.attribute("decl", createBareDeclRef(OIT->getDecl()));
+}
+
+void JSONNodeDumper::VisitPackExpansionType(const PackExpansionType *PET) {
+  if (llvm::Optional<unsigned> N = PET->getNumExpansions())
+    JOS.attribute("numExpansions", *N);
+}
+
 void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
   if (ND && ND->getDeclName())
     JOS.attribute("name", ND->getNameAsString());

+ 10 - 1
test/AST/ast-dump-record-definition-data-json.cpp

@@ -125,6 +125,16 @@ struct DoesNotAllowConstDefaultInit {
 };
 
 
+// CHECK:  "kind": "CXXRecordDecl",
+// CHECK-NEXT:  "name": "__NSConstantString_tag"
+// CHECK-NEXT: }
+
+
+// CHECK:  "kind": "CXXRecordDecl",
+// CHECK-NEXT:  "name": "__va_list_tag"
+// CHECK-NEXT: }
+
+
 // CHECK:  "kind": "CXXRecordDecl",
 // CHECK-NEXT:  "loc": {
 // CHECK-NEXT:   "col": 29,
@@ -5193,4 +5203,3 @@ struct DoesNotAllowConstDefaultInit {
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
-

File diff suppressed because it is too large
+ 691 - 681
test/AST/ast-dump-records-json.cpp


+ 16 - 2
test/AST/ast-dump-stmt-json.cpp

@@ -6565,7 +6565,14 @@ void TestDependentGenericSelectionExpr(Ty T) {
 // CHECK-NEXT:           "qualType": "Ty"
 // CHECK-NEXT:          },
 // CHECK-NEXT:          "isDependent": true,
-// CHECK-NEXT:          "isInstantiationDependent": true
+// CHECK-NEXT:          "isInstantiationDependent": true,
+// CHECK-NEXT:          "depth": 0,
+// CHECK-NEXT:          "index": 0,
+// CHECK-NEXT:          "decl": {
+// CHECK-NEXT:           "id": "0x{{.*}}",
+// CHECK-NEXT:           "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:           "name": "Ty"
+// CHECK-NEXT:          }
 // CHECK-NEXT:         },
 // CHECK-NEXT:         {
 // CHECK-NEXT:          "associationKind": "case",
@@ -6685,7 +6692,14 @@ void TestDependentGenericSelectionExpr(Ty T) {
 // CHECK-NEXT:           "qualType": "Ty"
 // CHECK-NEXT:          },
 // CHECK-NEXT:          "isDependent": true,
-// CHECK-NEXT:          "isInstantiationDependent": true
+// CHECK-NEXT:          "isInstantiationDependent": true,
+// CHECK-NEXT:          "depth": 0,
+// CHECK-NEXT:          "index": 0,
+// CHECK-NEXT:          "decl": {
+// CHECK-NEXT:           "id": "0x{{.*}}",
+// CHECK-NEXT:           "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:           "name": "Ty"
+// CHECK-NEXT:          }
 // CHECK-NEXT:         },
 // CHECK-NEXT:         {
 // CHECK-NEXT:          "associationKind": "default",

+ 11 - 2
test/AST/ast-dump-template-decls-json.cpp

@@ -56,7 +56,6 @@ template <typename Uy>
 void V<Ty>::f() {}
 
 
-
 // CHECK:  "kind": "TranslationUnitDecl",
 // CHECK-NEXT:  "loc": {},
 // CHECK-NEXT:  "range": {
@@ -129,6 +128,11 @@ void V<Ty>::f() {}
 // CHECK-NEXT:      "kind": "RecordType",
 // CHECK-NEXT:      "type": {
 // CHECK-NEXT:       "qualType": "__NSConstantString_tag"
+// CHECK-NEXT:      },
+// CHECK-NEXT:      "decl": {
+// CHECK-NEXT:       "id": "0x{{.*}}",
+// CHECK-NEXT:       "kind": "CXXRecordDecl",
+// CHECK-NEXT:       "name": "__NSConstantString_tag"
 // CHECK-NEXT:      }
 // CHECK-NEXT:     }
 // CHECK-NEXT:    ]
@@ -185,12 +189,18 @@ void V<Ty>::f() {}
 // CHECK-NEXT:      "type": {
 // CHECK-NEXT:       "qualType": "__va_list_tag [1]"
 // CHECK-NEXT:      },
+// CHECK-NEXT:      "size": 1,
 // CHECK-NEXT:      "inner": [
 // CHECK-NEXT:       {
 // CHECK-NEXT:        "id": "0x{{.*}}",
 // CHECK-NEXT:        "kind": "RecordType",
 // CHECK-NEXT:        "type": {
 // CHECK-NEXT:         "qualType": "__va_list_tag"
+// CHECK-NEXT:        },
+// CHECK-NEXT:        "decl": {
+// CHECK-NEXT:         "id": "0x{{.*}}",
+// CHECK-NEXT:         "kind": "CXXRecordDecl",
+// CHECK-NEXT:         "name": "__va_list_tag"
 // CHECK-NEXT:        }
 // CHECK-NEXT:       }
 // CHECK-NEXT:      ]
@@ -2399,4 +2409,3 @@ void V<Ty>::f() {}
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
-

Some files were not shown because too many files changed in this diff