unsigned IndentLevel;
PrinterHelper* Helper;
PrintingPolicy Policy;
+ std::string NL;
const ASTContext *Context;
public:
StmtPrinter(raw_ostream &os, PrinterHelper *helper,
const PrintingPolicy &Policy, unsigned Indentation = 0,
+ StringRef NL = "\n",
const ASTContext *Context = nullptr)
: OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy),
- Context(Context) {}
+ NL(NL), Context(Context) {}
void PrintStmt(Stmt *S) {
PrintStmt(S, Policy.Indentation);
// If this is an expr used in a stmt context, indent and newline it.
Indent();
Visit(S);
- OS << ";\n";
+ OS << ";" << NL;
} else if (S) {
Visit(S);
} else {
- Indent() << "<<<NULL STATEMENT>>>\n";
+ Indent() << "<<<NULL STATEMENT>>>" << NL;
}
IndentLevel -= SubIndent;
}
}
void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED {
- Indent() << "<<unknown stmt type>>\n";
+ Indent() << "<<unknown stmt type>>" << NL;
}
void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED {
/// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and
/// with no newline after the }.
void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
- OS << "{\n";
+ OS << "{" << NL;
for (auto *I : Node->body())
PrintStmt(I);
}
void StmtPrinter::VisitNullStmt(NullStmt *Node) {
- Indent() << ";\n";
+ Indent() << ";" << NL;
}
void StmtPrinter::VisitDeclStmt(DeclStmt *Node) {
Indent();
PrintRawDeclStmt(Node);
- OS << ";\n";
+ OS << ";" << NL;
}
void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) {
Indent();
PrintRawCompoundStmt(Node);
- OS << "\n";
+ OS << "" << NL;
}
void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
OS << " ... ";
PrintExpr(Node->getRHS());
}
- OS << ":\n";
+ OS << ":" << NL;
PrintStmt(Node->getSubStmt(), 0);
}
void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
- Indent(-1) << "default:\n";
+ Indent(-1) << "default:" << NL;
PrintStmt(Node->getSubStmt(), 0);
}
void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
- Indent(-1) << Node->getName() << ":\n";
+ Indent(-1) << Node->getName() << ":" << NL;
PrintStmt(Node->getSubStmt(), 0);
}
if (auto *CS = dyn_cast<CompoundStmt>(If->getThen())) {
OS << ' ';
PrintRawCompoundStmt(CS);
- OS << (If->getElse() ? ' ' : '\n');
+ OS << (If->getElse() ? " " : NL);
} else {
- OS << '\n';
+ OS << NL;
PrintStmt(If->getThen());
if (If->getElse()) Indent();
}
if (auto *CS = dyn_cast<CompoundStmt>(Else)) {
OS << ' ';
PrintRawCompoundStmt(CS);
- OS << '\n';
+ OS << NL;
} else if (auto *ElseIf = dyn_cast<IfStmt>(Else)) {
OS << ' ';
PrintRawIfStmt(ElseIf);
} else {
- OS << '\n';
+ OS << NL;
PrintStmt(If->getElse());
}
}
if (auto *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
OS << " ";
PrintRawCompoundStmt(CS);
- OS << "\n";
+ OS << NL;
} else {
- OS << "\n";
+ OS << NL;
PrintStmt(Node->getBody());
}
}
PrintRawDeclStmt(DS);
else
PrintExpr(Node->getCond());
- OS << ")\n";
+ OS << ")" << NL;
PrintStmt(Node->getBody());
}
PrintRawCompoundStmt(CS);
OS << " ";
} else {
- OS << "\n";
+ OS << NL;
PrintStmt(Node->getBody());
Indent();
}
OS << "while (";
PrintExpr(Node->getCond());
- OS << ");\n";
+ OS << ");" << NL;
}
void StmtPrinter::VisitForStmt(ForStmt *Node) {
if (auto *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
PrintRawCompoundStmt(CS);
- OS << "\n";
+ OS << NL;
} else {
- OS << "\n";
+ OS << NL;
PrintStmt(Node->getBody());
}
}
if (auto *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
PrintRawCompoundStmt(CS);
- OS << "\n";
+ OS << NL;
} else {
- OS << "\n";
+ OS << NL;
PrintStmt(Node->getBody());
}
}
Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel);
OS << " : ";
PrintExpr(Node->getRangeInit());
- OS << ") {\n";
+ OS << ") {" << NL;
PrintStmt(Node->getBody());
Indent() << "}";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
Indent() << "goto " << Node->getLabel()->getName() << ";";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
Indent() << "goto *";
PrintExpr(Node->getTarget());
OS << ";";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
Indent() << "continue;";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
Indent() << "break;";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
PrintExpr(Node->getRetValue());
}
OS << ";";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
}
OS << ");";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
// FIXME: Implement MS style inline asm statement printer.
Indent() << "__asm ";
if (Node->hasBraces())
- OS << "{\n";
- OS << Node->getAsmString() << "\n";
+ OS << "{" << NL;
+ OS << Node->getAsmString() << NL;
if (Node->hasBraces())
- Indent() << "}\n";
+ Indent() << "}" << NL;
}
void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
Indent() << "@try";
if (auto *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) {
PrintRawCompoundStmt(TS);
- OS << "\n";
+ OS << NL;
}
for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) {
OS << ")";
if (auto *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) {
PrintRawCompoundStmt(CS);
- OS << "\n";
+ OS << NL;
}
}
if (auto *FS = static_cast<ObjCAtFinallyStmt *>(Node->getFinallyStmt())) {
Indent() << "@finally";
PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
- OS << "\n";
+ OS << NL;
}
}
}
void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) {
- Indent() << "@catch (...) { /* todo */ } \n";
+ Indent() << "@catch (...) { /* todo */ } " << NL;
}
void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) {
OS << " ";
PrintExpr(Node->getThrowExpr());
}
- OS << ";\n";
+ OS << ";" << NL;
}
void StmtPrinter::VisitObjCAvailabilityCheckExpr(
PrintExpr(Node->getSynchExpr());
OS << ")";
PrintRawCompoundStmt(Node->getSynchBody());
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
Indent() << "@autoreleasepool";
PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) {
void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) {
Indent();
PrintRawCXXCatchStmt(Node);
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) {
OS << " ";
PrintRawCXXCatchStmt(Node->getHandler(i));
}
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) {
assert(F && "Must have a finally block...");
PrintRawSEHFinallyStmt(F);
}
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
OS << "__finally ";
PrintRawCompoundStmt(Node->getBlock());
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
OS << "__except (";
VisitExpr(Node->getFilterExpr());
- OS << ")\n";
+ OS << ")" << NL;
PrintRawCompoundStmt(Node->getBlock());
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) {
Indent();
PrintRawSEHExceptHandler(Node);
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) {
Indent();
PrintRawSEHFinallyStmt(Node);
- OS << "\n";
+ OS << NL;
}
void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
Indent() << "__leave;";
- if (Policy.IncludeNewlines) OS << "\n";
+ if (Policy.IncludeNewlines) OS << NL;
}
//===----------------------------------------------------------------------===//
OS << ' ';
Printer.Visit(Clause);
}
- OS << "\n";
+ OS << NL;
if (!ForceNoStmt && S->hasAssociatedStmt())
PrintStmt(S->getInnermostCapturedStmt()->getCapturedStmt());
}
void Stmt::printPretty(raw_ostream &OS, PrinterHelper *Helper,
const PrintingPolicy &Policy, unsigned Indentation,
+ StringRef NL,
const ASTContext *Context) const {
- StmtPrinter P(OS, Helper, Policy, Indentation, Context);
+ StmtPrinter P(OS, Helper, Policy, Indentation, NL, Context);
P.Visit(const_cast<Stmt*>(this));
}