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
This commit is contained in:
Ted Kremenek 2008-10-23 23:36:29 +00:00
Родитель e22d911dcf
Коммит 7cae2f64a7
3 изменённых файлов: 49 добавлений и 2 удалений

Просмотреть файл

@ -534,6 +534,35 @@ namespace {
ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); } 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 // AST Serializer

Просмотреть файл

@ -70,6 +70,9 @@ ASTConsumer *CreateBlockRewriter(const std::string& InFile,
const std::string& OutFile, const std::string& OutFile,
Diagnostic &Diags, Diagnostic &Diags,
const LangOptions &LangOpts); const LangOptions &LangOpts);
ASTConsumer *CreateInheritanceViewer(const std::string& clsname);
} // end clang namespace } // end clang namespace
#include "AnalysisConsumer.h" #include "AnalysisConsumer.h"

Просмотреть файл

@ -90,7 +90,8 @@ enum ProgActions {
DumpTokens, // Dump out preprocessed tokens. DumpTokens, // Dump out preprocessed tokens.
DumpRawTokens, // Dump out raw tokens. DumpRawTokens, // Dump out raw tokens.
RunAnalysis, // Run one or more source code analyses. 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> 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> static llvm::cl::opt<bool>
@ -1143,6 +1153,9 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
case EmitHTML: case EmitHTML:
return CreateHTMLPrinter(OutputFile, Diag, PP, PPF); return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
case InheritanceView:
return CreateInheritanceViewer(InheritanceViewCls);
case TestSerialization: case TestSerialization:
return CreateSerializationTest(Diag, FileMgr); return CreateSerializationTest(Diag, FileMgr);
@ -1428,6 +1441,8 @@ int main(int argc, char **argv) {
// Are we invoking one or more source analyses? // Are we invoking one or more source analyses?
if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly) if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly)
ProgAction = RunAnalysis; ProgAction = RunAnalysis;
else if (!InheritanceViewCls.empty()) // C++ visualization?
ProgAction = InheritanceView;
llvm::OwningPtr<SourceManager> SourceMgr; llvm::OwningPtr<SourceManager> SourceMgr;