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 f44e20a..40884ae 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -501,16 +501,7 @@
 // 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 cfffead..5a3508c 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -46,6 +46,19 @@
   
     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());
     }