]> granicus.if.org Git - clang/commitdiff
Added driver option "-cxx-inheritance-view" for viewing the C++ hierarchy of a class...
authorTed Kremenek <kremenek@apple.com>
Thu, 23 Oct 2008 23:36:29 +0000 (23:36 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 23 Oct 2008 23:36:29 +0000 (23:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58051 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Driver/ASTConsumers.h
Driver/clang.cpp

index 888250e59912cd5faceea0d4c64a43b612d0aaad..8c98ed4ea610b0e3fea80c9d337f42b46377225d 100644 (file)
@@ -534,6 +534,35 @@ namespace {
 
 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
 
index bc76df5f531fe0eb95537564eff3774e2bf8b8eb..97adfb30c829f34d87f7a76e444916449874f821 100644 (file)
@@ -70,6 +70,9 @@ ASTConsumer *CreateBlockRewriter(const std::string& InFile,
                                  const std::string& OutFile,
                                  Diagnostic &Diags,
                                  const LangOptions &LangOpts);
+  
+ASTConsumer *CreateInheritanceViewer(const std::string& clsname);
+
 } // end clang namespace
 
 #include "AnalysisConsumer.h"
index 6d3f0b38435780aebf2be511742003d3d7e84fba..47d422dcbcc75337dcbf5b76122b55c0a993dc16 100644 (file)
@@ -90,7 +90,8 @@ enum ProgActions {
   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 @@ NoCaretDiagnostics("fno-caret-diagnostics",
 
 
 //===----------------------------------------------------------------------===//
-// 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 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
     case EmitHTML:
       return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
 
+    case InheritanceView:
+      return CreateInheritanceViewer(InheritanceViewCls);
+      
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr);
       
@@ -1428,6 +1441,8 @@ int main(int argc, char **argv) {
   // 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;