[cfe-commits] r41657 - /cfe/trunk/AST/CFG.cpp

Ted Kremenek kremenek at apple.com
Fri Aug 31 15:26:13 PDT 2007


Author: kremenek
Date: Fri Aug 31 17:26:13 2007
New Revision: 41657

URL: http://llvm.org/viewvc/llvm-project?rev=41657&view=rev
Log:
Further cleanups in CFG printing for comma expressions, statement expressions, and indirect gotos.

Modified:
    cfe/trunk/AST/CFG.cpp

Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=41657&r1=41656&r2=41657&view=diff

==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Fri Aug 31 17:26:13 2007
@@ -924,12 +924,15 @@
 
 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 @@
   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 @@
                           && 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 @@
     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 @@
 };
   
   
+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 @@
     
     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.





More information about the cfe-commits mailing list