pretty print postfix ++/-- nicer

llvm-svn: 39137
This commit is contained in:
Chris Lattner 2006-11-05 23:54:51 +00:00
parent 33ad2cacc9
commit 1576870356
3 changed files with 27 additions and 6 deletions

View File

@ -34,15 +34,25 @@ StringExpr::~StringExpr() {
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 "+";

View File

@ -248,8 +248,13 @@ void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
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(");

View File

@ -115,9 +115,15 @@ public:
/// 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: