r361769 - When dumping the AST to JSON, dump the type information from a typeid expression with a type operand.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 07:34:32 PDT 2019


Author: aaronballman
Date: Mon May 27 07:34:31 2019
New Revision: 361769

URL: http://llvm.org/viewvc/llvm-project?rev=361769&view=rev
Log:
When dumping the AST to JSON, dump the type information from a typeid expression with a type operand.

Modified:
    cfe/trunk/include/clang/AST/JSONNodeDumper.h
    cfe/trunk/lib/AST/ASTDumper.cpp
    cfe/trunk/lib/AST/JSONNodeDumper.cpp
    cfe/trunk/test/AST/ast-dump-expr-json.cpp

Modified: cfe/trunk/include/clang/AST/JSONNodeDumper.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/JSONNodeDumper.h?rev=361769&r1=361768&r2=361769&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/JSONNodeDumper.h (original)
+++ cfe/trunk/include/clang/AST/JSONNodeDumper.h Mon May 27 07:34:31 2019
@@ -121,6 +121,7 @@ class JSONNodeDumper
   friend class JSONDumper;
 
   const SourceManager &SM;
+  ASTContext& Ctx;
   PrintingPolicy PrintPolicy;
   const comments::CommandTraits *Traits;
 
@@ -172,11 +173,11 @@ class JSONNodeDumper
   StringRef getCommentCommandName(unsigned CommandID) const;
 
 public:
-  JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr,
+  JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
                  const PrintingPolicy &PrintPolicy,
                  const comments::CommandTraits *Traits)
-      : NodeStreamer(OS), SM(SrcMgr), PrintPolicy(PrintPolicy), Traits(Traits) {
-  }
+      : NodeStreamer(OS), SM(SrcMgr), Ctx(Ctx), PrintPolicy(PrintPolicy),
+        Traits(Traits) {}
 
   void Visit(const Attr *A);
   void Visit(const Stmt *Node);
@@ -247,6 +248,7 @@ public:
   void VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE);
   void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE);
   void VisitAddrLabelExpr(const AddrLabelExpr *ALE);
+  void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
 
   void VisitIntegerLiteral(const IntegerLiteral *IL);
   void VisitCharacterLiteral(const CharacterLiteral *CL);
@@ -360,10 +362,10 @@ class JSONDumper : public ASTNodeTravers
   }
 
 public:
-  JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr,
+  JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
              const PrintingPolicy &PrintPolicy,
              const comments::CommandTraits *Traits)
-      : NodeDumper(OS, SrcMgr, PrintPolicy, Traits) {}
+      : NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {}
 
   JSONNodeDumper &doGetNodeDelegate() { return NodeDumper; }
 

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=361769&r1=361768&r2=361769&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon May 27 07:34:31 2019
@@ -180,11 +180,11 @@ LLVM_DUMP_METHOD void Decl::dump() const
 
 LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize,
                                  ASTDumpOutputFormat Format) const {
-  const ASTContext &Ctx = getASTContext();
+  ASTContext &Ctx = getASTContext();
   const SourceManager &SM = Ctx.getSourceManager();
 
   if (ADOF_JSON == Format) {
-    JSONDumper P(OS, SM, Ctx.getPrintingPolicy(),
+    JSONDumper P(OS, SM, Ctx, Ctx.getPrintingPolicy(),
                  &Ctx.getCommentCommandTraits());
     (void)Deserialize; // FIXME?
     P.Visit(this);

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=361769&r1=361768&r2=361769&view=diff
==============================================================================
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Mon May 27 07:34:31 2019
@@ -917,6 +917,16 @@ void JSONNodeDumper::VisitAddrLabelExpr(
   JOS.attribute("labelDeclId", createPointerRepresentation(ALE->getLabel()));
 }
 
+void JSONNodeDumper::VisitCXXTypeidExpr(const CXXTypeidExpr *CTE) {
+  if (CTE->isTypeOperand()) {
+    QualType Adjusted = CTE->getTypeOperand(Ctx);
+    QualType Unadjusted = CTE->getTypeOperandSourceInfo()->getType();
+    JOS.attribute("typeArg", createQualType(Unadjusted));
+    if (Adjusted != Unadjusted)
+      JOS.attribute("adjustedTypeArg", createQualType(Adjusted));
+  }
+}
+
 void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
   JOS.attribute("value",
                 IL->getValue().toString(

Modified: cfe/trunk/test/AST/ast-dump-expr-json.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-expr-json.cpp?rev=361769&r1=361768&r2=361769&view=diff
==============================================================================
--- cfe/trunk/test/AST/ast-dump-expr-json.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-expr-json.cpp Mon May 27 07:34:31 2019
@@ -3447,7 +3447,10 @@ void TestNonADLCall3() {
 // CHECK-NEXT:      "type": {
 // CHECK-NEXT:       "qualType": "const std::type_info"
 // CHECK-NEXT:      },
-// CHECK-NEXT:      "valueCategory": "lvalue"
+// CHECK-NEXT:      "valueCategory": "lvalue",
+// CHECK-NEXT:      "typeArg": {
+// CHECK-NEXT:       "qualType": "S"
+// CHECK-NEXT:      }
 // CHECK-NEXT:     },
 // CHECK-NEXT:     {
 // CHECK-NEXT:      "id": "0x{{.*}}",
@@ -3467,7 +3470,13 @@ void TestNonADLCall3() {
 // CHECK-NEXT:      "type": {
 // CHECK-NEXT:       "qualType": "const std::type_info"
 // CHECK-NEXT:      },
-// CHECK-NEXT:      "valueCategory": "lvalue"
+// CHECK-NEXT:      "valueCategory": "lvalue",
+// CHECK-NEXT:      "typeArg": {
+// CHECK-NEXT:       "qualType": "const volatile S"
+// CHECK-NEXT:      },
+// CHECK-NEXT:      "adjustedTypeArg": {
+// CHECK-NEXT:       "qualType": "S"
+// CHECK-NEXT:      }
 // CHECK-NEXT:     }
 // CHECK-NEXT:    ]
 // CHECK-NEXT:   }




More information about the cfe-commits mailing list