ast-print: Avoid extra whitespace before function opening brace
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 15 Nov 2021 04:44:27 +0000 (20:44 -0800)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 15 Nov 2021 04:45:16 +0000 (20:45 -0800)
clang/include/clang/AST/Stmt.h
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/StmtPrinter.cpp
clang/test/AST/ast-dump-templates.cpp

index 73cbff5..a32126d 100644 (file)
@@ -1216,6 +1216,11 @@ public:
                    const PrintingPolicy &Policy, unsigned Indentation = 0,
                    StringRef NewlineSymbol = "\n",
                    const ASTContext *Context = nullptr) const;
+  void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper,
+                             const PrintingPolicy &Policy,
+                             unsigned Indentation = 0,
+                             StringRef NewlineSymbol = "\n",
+                             const ASTContext *Context = nullptr) const;
 
   /// Pretty-prints in JSON format.
   void printJson(raw_ostream &Out, PrinterHelper *Helper,
index 5c6781c..044eb8f 100644 (file)
@@ -782,11 +782,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
           Out << ";\n";
         }
         Indentation -= Policy.Indentation;
-      } else
-        Out << ' ';
+      }
 
       if (D->getBody())
-        D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation, "\n",
+        D->getBody()->printPrettyControlled(Out, nullptr, SubPolicy, Indentation, "\n",
                                   &Context);
     } else {
       if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
index 12af5bf..fc267d7 100644 (file)
@@ -2595,6 +2595,14 @@ void Stmt::printPretty(raw_ostream &Out, PrinterHelper *Helper,
   P.Visit(const_cast<Stmt *>(this));
 }
 
+void Stmt::printPrettyControlled(raw_ostream &Out, PrinterHelper *Helper,
+                                 const PrintingPolicy &Policy,
+                                 unsigned Indentation, StringRef NL,
+                                 const ASTContext *Context) const {
+  StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
+  P.PrintControlledStmt(const_cast<Stmt *>(this));
+}
+
 void Stmt::printJson(raw_ostream &Out, PrinterHelper *Helper,
                      const PrintingPolicy &Policy, bool AddQuotes) const {
   std::string Buf;
index dcecdca..b08bc76 100644 (file)
@@ -79,6 +79,8 @@ struct foo {
 // type/unsigned argument (see
 // TemplateParameterList::shouldIncludeTypeForArgument)
 // CHECK1: {{^    }}template<> struct foo<0, 0L> {
+// CHECK1: {{^    }}void test(){{ }}{
+// CHECK1: {{^        }}foo<0, 0 + 0L>::fn();
 void test() {
   foo<0, 0 + 0L>::fn();
 }