On 11/10/2012 12:35 AM, Eli Friedman wrote:
On Wed, Oct 31, 2012 at 9:27 AM, Jordan Rose <[email protected]> wrote:
[...]
If you're okay with adding a PrintImplicitNodes bit to PrintingPolicy that
would be good enough for us. Otherwise we'll have to think of something
else.
This seems okay to me.  Grzegorz?
Patch attached.

Index: lib/Frontend/ASTConsumers.cpp
===================================================================
--- lib/Frontend/ASTConsumers.cpp	(revision 168260)
+++ lib/Frontend/ASTConsumers.cpp	(working copy)
@@ -48,7 +48,11 @@
         if (Dump)
           D->dump(Out);
         else
-          D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
+        {
+          PrintingPolicy Policy(D->getASTContext().getPrintingPolicy());
+          Policy.PrintImplicitNodes=false;
+          D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+        }
         return;
       }
 
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp	(revision 168260)
+++ lib/AST/StmtPrinter.cpp	(working copy)
@@ -953,7 +953,10 @@
 }
 void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
   // No need to print anything, simply forward to the sub expression.
-  PrintExpr(Node->getSubExpr());
+  if(Policy.PrintImplicitNodes)
+    PrintExpr(Node->getSubExpr());
+  else
+    PrintExpr(Node->getSubExprAsWritten());
 }
 void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) {
   PrintExpr(Node->getLHS());
Index: test/SemaCXX/ast-print.cpp
===================================================================
--- test/SemaCXX/ast-print.cpp	(revision 168260)
+++ test/SemaCXX/ast-print.cpp	(working copy)
@@ -81,3 +81,16 @@
         E a = A;
     }
 };
+
+// CHECK:  test10(*m);
+
+struct MyClass10
+{
+    operator const char *() { return "str"; }
+};
+    
+void test10(const char *str)
+{
+    MyClass10* m;
+    test10(*m);
+}
Index: include/clang/AST/PrettyPrinter.h
===================================================================
--- include/clang/AST/PrettyPrinter.h	(revision 168260)
+++ include/clang/AST/PrettyPrinter.h	(working copy)
@@ -40,7 +40,7 @@
       ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
       SuppressStrongLifetime(false), Bool(LO.Bool),
       TerseOutput(false), SuppressAttributes(false),
-      DumpSourceManager(0) { }
+      DumpSourceManager(0), PrintImplicitNodes(true) { }
 
   /// \brief What language we're printing.
   LangOptions LangOpts;
@@ -151,6 +151,11 @@
   /// involves printing the internal details of the AST and pretty-printing
   /// involves printing something similar to source code.
   SourceManager *DumpSourceManager;
+
+  /// \brief When true, do  print implicit nodes.
+  ///
+  bool PrintImplicitNodes : 1;
+
 };
 
 } // end namespace clang
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to