[cfe-commits] r39137 - in /cfe/cfe/trunk: AST/Expr.cpp AST/StmtPrinter.cpp include/clang/AST/Expr.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:27:56 PDT 2007


Author: sabre
Date: Wed Jul 11 11:27:56 2007
New Revision: 39137

URL: http://llvm.org/viewvc/llvm-project?rev=39137&view=rev
Log:
pretty print postfix ++/-- nicer

Modified:
    cfe/cfe/trunk/AST/Expr.cpp
    cfe/cfe/trunk/AST/StmtPrinter.cpp
    cfe/cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=39137&r1=39136&r2=39137&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:27:56 2007
@@ -34,15 +34,25 @@
   delete[] StrData;
 }
 
+bool UnaryOperator::isPostfix(Opcode Op) {
+  switch (Op) {
+  case PostInc:
+  case PostDec:
+    return true;
+  default:
+    return false;
+  }
+}
+
 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
 /// corresponds to, e.g. "sizeof" or "[pre]++".
 const char *UnaryOperator::getOpcodeStr(Opcode Op) {
   switch (Op) {
   default: assert(0 && "Unknown unary operator");
-  case PostInc: return "[post]++";
-  case PostDec: return "[post]--";
-  case PreInc:  return "[pre]++";
-  case PreDec:  return "[pre]--";
+  case PostInc: return "++";
+  case PostDec: return "--";
+  case PreInc:  return "++";
+  case PreDec:  return "--";
   case AddrOf:  return "&";
   case Deref:   return "*";
   case Plus:    return "+";

Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39137&r1=39136&r2=39137&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:27:56 2007
@@ -248,8 +248,13 @@
   OS << ")'";
 }
 void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) {
-  OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
+  if (!Node->isPostfix())
+    OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
   PrintExpr(Node->getSubExpr());
+  
+  if (Node->isPostfix())
+    OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
+
 }
 void StmtPrinter::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr *Node) {
   OS << (Node->isSizeOf() ? "sizeof(" : "alignof(");

Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39137&r1=39136&r2=39137&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:27:56 2007
@@ -115,9 +115,15 @@
   /// corresponds to, e.g. "sizeof" or "[pre]++"
   static const char *getOpcodeStr(Opcode Op);
 
+  /// isPostfix - Return true if this is a postfix operation, like x++.
+  static bool isPostfix(Opcode Op);
+
+  
   Opcode getOpcode() const { return Opc; }
   Expr *getSubExpr() { return Val; }
-
+  
+  bool isPostfix() const { return isPostfix(Opc); }
+  
   virtual void visit(StmtVisitor &Visitor);
 
 private:





More information about the cfe-commits mailing list