From: Chris Lattner Date: Thu, 9 Aug 2007 17:34:19 +0000 (+0000) Subject: move a switch to common code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36460eea641bf20a67b8b767b6d26373a90f0965;p=clang move a switch to common code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40967 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp index f44e20a0ab..40884ae5cf 100644 --- a/AST/StmtPrinter.cpp +++ b/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/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index cfffead2ab..5a3508c46d 100644 --- a/include/clang/AST/ExprCXX.h +++ b/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()); }