mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-29 03:26:06 +00:00
pretty print postfix ++/-- nicer
llvm-svn: 39137
This commit is contained in:
parent
33ad2cacc9
commit
1576870356
@ -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 "+";
|
||||
|
@ -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(");
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user