ast-print: Avoid extra whitespace before function opening brace

This commit is contained in:
David Blaikie 2021-11-14 20:44:27 -08:00
parent 604446aa6b
commit b2589e326b
4 changed files with 17 additions and 3 deletions

View 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,

View 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))

View 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;

View 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();
}