From 1c29bba6da40bbe59fb1f81c4cd5ab5471554ffe Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 31 Aug 2007 22:26:13 +0000 Subject: [PATCH] Further cleanups in CFG printing for comma expressions, statement expressions, and indirect gotos. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41657 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/CFG.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/AST/CFG.cpp b/AST/CFG.cpp index 83d91ddeb6..da06ebd965 100644 --- a/AST/CFG.cpp +++ b/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 > 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(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(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(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(*I)) OS << '\n'; + + print_stmt(OS,Helper,*I); } // Print the terminator of this block. -- 2.50.1