Added driver option "-cxx-inheritance-view" for viewing the C++ hierarchy of a class in GraphViz.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58051 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index 888250e..8c98ed4 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -535,6 +535,35 @@
 ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); }
 
 //===----------------------------------------------------------------------===//
+/// InheritanceViewer - C++ Inheritance Visualization
+
+namespace {
+class InheritanceViewer : public ASTConsumer {
+  const std::string clsname;
+public:
+  InheritanceViewer(const std::string& cname) : clsname(cname) {}
+  
+  void HandleTranslationUnit(TranslationUnit& TU) {
+    ASTContext& C = TU.getContext();
+    for (ASTContext::type_iterator I=C.types_begin(),E=C.types_end(); I!=E; ++I)
+      if (CXXRecordType *T = dyn_cast<CXXRecordType>(*I)) {
+        CXXRecordDecl* D = T->getDecl();
+        // FIXME: This lookup needs to be generalized to handle namespaces and
+        // (when we support them) templates.
+        if (D->getName() == clsname) {
+          QualType QT(T, 0);
+          QT.viewInheritance(C);      
+        }
+      }
+  }
+}; 
+}
+
+ASTConsumer *clang::CreateInheritanceViewer(const std::string& clsname) {
+  return new InheritanceViewer(clsname);
+}
+
+//===----------------------------------------------------------------------===//
 // AST Serializer
 
 namespace {