[PATCH] D62487: [clang] Respect TerseOutput when printing lambdas

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 08:08:03 PDT 2019


kadircet created this revision.
kadircet added reviewers: ilya-biryukov, hokein, sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
kadircet added a child revision: D61497: [clangd] Introduce a structured hover response.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62487

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/unittests/AST/StmtPrinterTest.cpp


Index: clang/unittests/AST/StmtPrinterTest.cpp
===================================================================
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -231,3 +231,17 @@
   ASSERT_TRUE(PrintedStmtObjCMatches(ObjCSource, returnStmt().bind("id"),
                                      "return self->ivar;\n"));
 }
+
+TEST(StmtPrinter, TerseOutputWithLambdas) {
+  const char *CPPSource = "auto lamb = []{ return 0; };";
+
+  // body is printed when TerseOutput is off(default).
+  ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11, CPPSource,
+                                    lambdaExpr(anything()).bind("id"),
+                                    "[] {\n    return 0;\n}"));
+
+  // body not printed when TerseOutput is on.
+  ASSERT_TRUE(PrintedStmtCXXMatches(
+      StdVer::CXX11, CPPSource, lambdaExpr(anything()).bind("id"), "[] {}",
+      PolicyAdjusterType([](PrintingPolicy &PP) { PP.TerseOutput = true; })));
+}
Index: clang/lib/AST/StmtPrinter.cpp
===================================================================
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -1950,7 +1950,10 @@
 
   // Print the body.
   OS << ' ';
-  PrintRawCompoundStmt(Node->getBody());
+  if (Policy.TerseOutput)
+    OS << "{}";
+  else
+    PrintRawCompoundStmt(Node->getBody());
 }
 
 void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62487.201534.patch
Type: text/x-patch
Size: 1433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190527/3f9558d1/attachment.bin>


More information about the cfe-commits mailing list