diff options
-rw-r--r-- | clang/AST/StmtPrinter.cpp | 11 | ||||
-rw-r--r-- | clang/include/clang/AST/ExprCXX.h | 13 |
2 files changed, 14 insertions, 10 deletions
diff --git a/clang/AST/StmtPrinter.cpp b/clang/AST/StmtPrinter.cpp index f44e20a0ab5..40884ae5cf3 100644 --- a/clang/AST/StmtPrinter.cpp +++ b/clang/AST/StmtPrinter.cpp @@ -501,16 +501,7 @@ void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) { // C++ void StmtPrinter::VisitCXXCastExpr(CXXCastExpr *Node) { - switch (Node->getOpcode()) { - default: - assert(0 && "Not a C++ cast expression"); - abort(); - case CXXCastExpr::ConstCast: OS << "const_cast<"; break; - case CXXCastExpr::DynamicCast: OS << "dynamic_cast<"; break; - case CXXCastExpr::ReinterpretCast: OS << "reinterpret_cast<"; break; - case CXXCastExpr::StaticCast: OS << "static_cast<"; break; - } - + OS << CXXCastExpr::getOpcodeStr(Node->getOpcode()) << '<'; OS << Node->getDestType().getAsString() << ">("; PrintExpr(Node->getSubExpr()); OS << ")"; diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index cfffead2abd..5a3508c46d0 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -46,6 +46,19 @@ namespace clang { Opcode getOpcode() const { return Opc; } + /// getOpcodeStr - Turn an Opcode enum value into the string it represents, + /// e.g. "reinterpret_cast". + static const char *getOpcodeStr(Opcode Op) { + // FIXME: move out of line. + switch (Op) { + default: assert(0 && "Not a C++ cast expression"); + case CXXCastExpr::ConstCast: return "const_cast"; + case CXXCastExpr::DynamicCast: return "dynamic_cast"; + case CXXCastExpr::ReinterpretCast: return "reinterpret_cast"; + case CXXCastExpr::StaticCast: return "static_cast"; + } + } + virtual SourceRange getSourceRange() const { return SourceRange(Loc, getSubExpr()->getSourceRange().End()); } |