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

llvm-svn: 58051
This commit is contained in:
Ted Kremenek 2008-10-23 23:36:29 +00:00
parent f000308467
commit 45e2b90d3d
3 changed files with 49 additions and 2 deletions

View 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

View 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"

View 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;