Author: David Blaikie Date: 2021-11-14T20:45:16-08:00 New Revision: b2589e326ba4407d8314938a4f7498086e2203ea
URL: https://github.com/llvm/llvm-project/commit/b2589e326ba4407d8314938a4f7498086e2203ea DIFF: https://github.com/llvm/llvm-project/commit/b2589e326ba4407d8314938a4f7498086e2203ea.diff LOG: ast-print: Avoid extra whitespace before function opening brace Added: Modified: clang/include/clang/AST/Stmt.h clang/lib/AST/DeclPrinter.cpp clang/lib/AST/StmtPrinter.cpp clang/test/AST/ast-dump-templates.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index 73cbff537847..a32126d23d31 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -1216,6 +1216,11 @@ class alignas(void *) Stmt { 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, diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 5c6781c26ed7..044eb8f8f8e5 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -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)) diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 12af5bfa2013..fc267d7006a1 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -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; diff --git a/clang/test/AST/ast-dump-templates.cpp b/clang/test/AST/ast-dump-templates.cpp index dcecdca58c75..b08bc76ed179 100644 --- a/clang/test/AST/ast-dump-templates.cpp +++ b/clang/test/AST/ast-dump-templates.cpp @@ -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(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits