[cfe-commits] r58051 - in /cfe/trunk/Driver: ASTConsumers.cpp ASTConsumers.h clang.cpp

Ted Kremenek kremenek at apple.com
Thu Oct 23 16:36:29 PDT 2008


Author: kremenek
Date: Thu Oct 23 18:36:29 2008
New Revision: 58051

URL: http://llvm.org/viewvc/llvm-project?rev=58051&view=rev
Log:
Added driver option "-cxx-inheritance-view" for viewing the C++ hierarchy of a class in GraphViz.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/clang.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=58051&r1=58050&r2=58051&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Thu Oct 23 18:36:29 2008
@@ -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 {

Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=58051&r1=58050&r2=58051&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Thu Oct 23 18:36:29 2008
@@ -70,6 +70,9 @@
                                  const std::string& OutFile,
                                  Diagnostic &Diags,
                                  const LangOptions &LangOpts);
+  
+ASTConsumer *CreateInheritanceViewer(const std::string& clsname);
+
 } // end clang namespace
 
 #include "AnalysisConsumer.h"

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=58051&r1=58050&r2=58051&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Thu Oct 23 18:36:29 2008
@@ -90,7 +90,8 @@
   DumpTokens,                   // Dump out preprocessed tokens.
   DumpRawTokens,                // Dump out raw tokens.
   RunAnalysis,                  // Run one or more source code analyses. 
-  GeneratePCH                   // Generate precompiled header.
+  GeneratePCH,                  // Generate precompiled header.
+  InheritanceView               // View C++ inheritance for a specified class.
 };
 
 static llvm::cl::opt<ProgActions> 
@@ -176,7 +177,16 @@
 
 
 //===----------------------------------------------------------------------===//
-// Analyzer Options
+// C++ Visualization.
+//===----------------------------------------------------------------------===//
+
+static llvm::cl::opt<std::string>
+InheritanceViewCls("cxx-inheritance-view",
+                   llvm::cl::value_desc("class name"),
+                   llvm::cl::desc("View C++ inhertance for a specified class"));
+
+//===----------------------------------------------------------------------===//
+// Analyzer Options.
 //===----------------------------------------------------------------------===//
 
 static llvm::cl::opt<bool>
@@ -1143,6 +1153,9 @@
     case EmitHTML:
       return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
 
+    case InheritanceView:
+      return CreateInheritanceViewer(InheritanceViewCls);
+      
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr);
       
@@ -1428,6 +1441,8 @@
   // Are we invoking one or more source analyses?
   if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly)
     ProgAction = RunAnalysis;  
+  else if (!InheritanceViewCls.empty())  // C++ visualization?
+    ProgAction = InheritanceView;
     
   llvm::OwningPtr<SourceManager> SourceMgr;
   





More information about the cfe-commits mailing list