aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/CFG.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-29 20:38:28 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-29 20:38:28 +0000
commitd249e1d1f1498b81314459ceda19d6ff25c278ad (patch)
tree64980c7c4974845750bbfefa695204a8feff0861 /lib/AST/CFG.cpp
parente540858b289b23653bcb23646f135729203635cb (diff)
Create a new PrintingPolicy class, which we pass down through the AST
printing logic to help customize the output. For now, we use this rather than a special flag to suppress the "struct" when printing "struct X" and to print the Boolean type as "bool" in C++ but "_Bool" in C. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72590 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/CFG.cpp')
-rw-r--r--lib/AST/CFG.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp
index af2a8910d8..9f2f2079a0 100644
--- a/lib/AST/CFG.cpp
+++ b/lib/AST/CFG.cpp
@@ -1525,23 +1525,26 @@ class VISIBILITY_HIDDEN CFGBlockTerminatorPrint
llvm::raw_ostream& OS;
StmtPrinterHelper* Helper;
+ PrintingPolicy Policy;
+
public:
- CFGBlockTerminatorPrint(llvm::raw_ostream& os, StmtPrinterHelper* helper)
- : OS(os), Helper(helper) {}
+ CFGBlockTerminatorPrint(llvm::raw_ostream& os, StmtPrinterHelper* helper,
+ const PrintingPolicy &Policy = PrintingPolicy())
+ : OS(os), Helper(helper), Policy(Policy) {}
void VisitIfStmt(IfStmt* I) {
OS << "if ";
- I->getCond()->printPretty(OS,Helper);
+ I->getCond()->printPretty(OS,Helper,Policy);
}
// Default case.
- void VisitStmt(Stmt* Terminator) { Terminator->printPretty(OS); }
+ void VisitStmt(Stmt* Terminator) { Terminator->printPretty(OS, Helper, Policy); }
void VisitForStmt(ForStmt* F) {
OS << "for (" ;
if (F->getInit()) OS << "...";
OS << "; ";
- if (Stmt* C = F->getCond()) C->printPretty(OS,Helper);
+ if (Stmt* C = F->getCond()) C->printPretty(OS, Helper, Policy);
OS << "; ";
if (F->getInc()) OS << "...";
OS << ")";
@@ -1549,33 +1552,33 @@ public:
void VisitWhileStmt(WhileStmt* W) {
OS << "while " ;
- if (Stmt* C = W->getCond()) C->printPretty(OS,Helper);
+ if (Stmt* C = W->getCond()) C->printPretty(OS, Helper, Policy);
}
void VisitDoStmt(DoStmt* D) {
OS << "do ... while ";
- if (Stmt* C = D->getCond()) C->printPretty(OS,Helper);
+ if (Stmt* C = D->getCond()) C->printPretty(OS, Helper, Policy);
}
void VisitSwitchStmt(SwitchStmt* Terminator) {
OS << "switch ";
- Terminator->getCond()->printPretty(OS,Helper);
+ Terminator->getCond()->printPretty(OS, Helper, Policy);
}
void VisitConditionalOperator(ConditionalOperator* C) {
- C->getCond()->printPretty(OS,Helper);
+ C->getCond()->printPretty(OS, Helper, Policy);
OS << " ? ... : ...";
}
void VisitChooseExpr(ChooseExpr* C) {
OS << "__builtin_choose_expr( ";
- C->getCond()->printPretty(OS,Helper);
+ C->getCond()->printPretty(OS, Helper, Policy);
OS << " )";
}
void VisitIndirectGotoStmt(IndirectGotoStmt* I) {
OS << "goto *";
- I->getTarget()->printPretty(OS,Helper);
+ I->getTarget()->printPretty(OS, Helper, Policy);
}
void VisitBinaryOperator(BinaryOperator* B) {
@@ -1584,7 +1587,7 @@ public:
return;
}
- B->getLHS()->printPretty(OS,Helper);
+ B->getLHS()->printPretty(OS, Helper, Policy);
switch (B->getOpcode()) {
case BinaryOperator::LOr:
@@ -1599,7 +1602,7 @@ public:
}
void VisitExpr(Expr* E) {
- E->printPretty(OS,Helper);
+ E->printPretty(OS, Helper, Policy);
}
};
@@ -1629,7 +1632,7 @@ void print_stmt(llvm::raw_ostream&OS, StmtPrinterHelper* Helper, Stmt* Terminato
}
}
- Terminator->printPretty(OS, Helper);
+ Terminator->printPretty(OS, Helper, /*FIXME:*/PrintingPolicy());
// Expressions need a newline.
if (isa<Expr>(Terminator)) OS << '\n';
@@ -1662,10 +1665,10 @@ void print_block(llvm::raw_ostream& OS, const CFG* cfg, const CFGBlock& B,
OS << L->getName();
else if (CaseStmt* C = dyn_cast<CaseStmt>(Terminator)) {
OS << "case ";
- C->getLHS()->printPretty(OS);
+ C->getLHS()->printPretty(OS, Helper, /*FIXME:*/PrintingPolicy());
if (C->getRHS()) {
OS << " ... ";
- C->getRHS()->printPretty(OS);
+ C->getRHS()->printPretty(OS, Helper, /*FIXME:*/PrintingPolicy());
}
}
else if (isa<DefaultStmt>(Terminator))
@@ -1703,7 +1706,7 @@ void print_block(llvm::raw_ostream& OS, const CFG* cfg, const CFGBlock& B,
if (Helper) Helper->setBlockID(-1);
- CFGBlockTerminatorPrint TPrinter(OS,Helper);
+ CFGBlockTerminatorPrint TPrinter(OS, Helper, /*FIXME*/PrintingPolicy());
TPrinter.Visit(const_cast<Stmt*>(B.getTerminator()));
OS << '\n';
}