diff options
| author | Ted Kremenek <kremenek@apple.com> | 2007-08-31 22:26:13 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2007-08-31 22:26:13 +0000 |
| commit | f8b50e91b7b48b0b8fc8d3a9dca479c63555d249 (patch) | |
| tree | 7246821df802f58e4744a0afa7de91f757c871f2 /clang/AST/CFG.cpp | |
| parent | 04a913b9584319d3f5d68c08168c217b8ffd186f (diff) | |
| download | bcm5719-llvm-f8b50e91b7b48b0b8fc8d3a9dca479c63555d249.tar.gz bcm5719-llvm-f8b50e91b7b48b0b8fc8d3a9dca479c63555d249.zip | |
Further cleanups in CFG printing for comma expressions, statement expressions, and indirect gotos.
llvm-svn: 41657
Diffstat (limited to 'clang/AST/CFG.cpp')
| -rw-r--r-- | clang/AST/CFG.cpp | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/clang/AST/CFG.cpp b/clang/AST/CFG.cpp index 83d91ddeb6d..da06ebd9654 100644 --- a/clang/AST/CFG.cpp +++ b/clang/AST/CFG.cpp @@ -924,12 +924,15 @@ void CFGBlock::reverseStmts() { std::reverse(Stmts.begin(),Stmts.end()); } namespace { -class StmtPrinterHelper : public PrinterHelper { +class StmtPrinterHelper : public PrinterHelper { + typedef llvm::DenseMap<Stmt*,std::pair<unsigned,unsigned> > StmtMapTy; StmtMapTy StmtMap; signed CurrentBlock; unsigned CurrentStmt; + public: + StmtPrinterHelper(const CFG* cfg) : CurrentBlock(0), CurrentStmt(0) { for (CFG::const_iterator I = cfg->begin(), E = cfg->end(); I != E; ++I ) { unsigned j = 1; @@ -944,8 +947,9 @@ public: void setBlockID(signed i) { CurrentBlock = i; } void setStmtID(unsigned i) { CurrentStmt = i; } - virtual bool handledStmt(Stmt* E, std::ostream& OS) { - StmtMapTy::iterator I = StmtMap.find(E); + virtual bool handledStmt(Stmt* S, std::ostream& OS) { + + StmtMapTy::iterator I = StmtMap.find(S); if (I == StmtMap.end()) return false; @@ -954,8 +958,8 @@ public: && I->second.second == CurrentStmt) return false; - OS << "[B" << I->second.first << "." << I->second.second << "]"; - return true; + OS << "[B" << I->second.first << "." << I->second.second << "]"; + return true; } }; @@ -1010,6 +1014,12 @@ public: OS << " ? ... : ...\n"; } + void VisitIndirectGotoStmt(IndirectGotoStmt* I) { + OS << "goto *"; + I->getTarget()->printPretty(OS,Helper); + OS << '\n'; + } + void VisitBinaryOperator(BinaryOperator* B) { if (!B->isLogicalOp()) { VisitExpr(B); @@ -1037,6 +1047,37 @@ public: }; +void print_stmt(std::ostream&OS, StmtPrinterHelper* Helper, Stmt* S) { + if (Helper) { + // special printing for statement-expressions. + if (StmtExpr* SE = dyn_cast<StmtExpr>(S)) { + CompoundStmt* Sub = SE->getSubStmt(); + + if (Sub->child_begin() != Sub->child_end()) { + OS << "{ ... ; "; + Helper->handledStmt(*SE->getSubStmt()->child_rbegin(),OS); + OS << " }\n"; + return; + } + } + + // special printing for comma expressions. + if (BinaryOperator* B = dyn_cast<BinaryOperator>(S)) { + if (B->getOpcode() == BinaryOperator::Comma) { + OS << "... , "; + Helper->handledStmt(B->getRHS(),OS); + OS << '\n'; + return; + } + } + } + + S->printPretty(OS, Helper); + + // Expressions need a newline. + if (isa<Expr>(S)) OS << '\n'; +} + void print_block(std::ostream& OS, const CFG* cfg, const CFGBlock& B, StmtPrinterHelper* Helper, bool print_edges) { @@ -1092,11 +1133,8 @@ void print_block(std::ostream& OS, const CFG* cfg, const CFGBlock& B, if (Helper) Helper->setStmtID(j); - - (*I)->printPretty(OS, Helper); - - // Expressions need a newline. - if (isa<Expr>(*I)) OS << '\n'; + + print_stmt(OS,Helper,*I); } // Print the terminator of this block. |

