19#include "llvm/Support/FileSystem.h"
20#include "llvm/Support/GraphWriter.h"
21#include "llvm/Support/raw_ostream.h"
33class InheritanceHierarchyWriter {
36 std::map<QualType, int, QualTypeOrdering> DirectBaseCount;
37 std::set<QualType, QualTypeOrdering> KnownVirtualBases;
40 InheritanceHierarchyWriter(ASTContext& Context, raw_ostream& Out)
41 : Context(Context), Out(Out) { }
43 void WriteGraph(QualType
Type) {
44 Out <<
"digraph \"" << llvm::DOT::EscapeString(
Type.getAsString())
46 WriteNode(
Type,
false);
53 void WriteNode(QualType
Type,
bool FromVirtual);
58 raw_ostream& WriteNodeReference(QualType
Type,
bool FromVirtual);
62void InheritanceHierarchyWriter::WriteNode(
QualType Type,
bool FromVirtual) {
66 if (!KnownVirtualBases.insert(CanonType).second)
75 WriteNodeReference(
Type, FromVirtual);
79 Out <<
" [ shape=\"box\", label=\"" << llvm::DOT::EscapeString(TypeName);
93 Type->castAsCanonical<RecordType>()->getOriginalDecl());
94 for (
const auto &Base :
Decl->bases()) {
99 if (!
Base.isVirtual())
100 ++DirectBaseCount[CanonBaseType];
103 WriteNode(
Base.getType(),
Base.isVirtual());
107 WriteNodeReference(
Type, FromVirtual);
109 WriteNodeReference(
Base.getType(),
Base.isVirtual());
112 if (
Base.isVirtual()) {
113 Out <<
" [ style=\"dashed\" ]";
123InheritanceHierarchyWriter::WriteNodeReference(QualType
Type,
129 Out <<
"_" << DirectBaseCount[CanonType];
140 if (std::error_code EC = llvm::sys::fs::createTemporaryFile(
141 Self.getAsString(),
"dot", FD, Filename)) {
142 llvm::errs() <<
"Error: " << EC.message() <<
"\n";
146 llvm::errs() <<
"Writing '" << Filename <<
"'... ";
148 llvm::raw_fd_ostream O(FD,
true);
150 InheritanceHierarchyWriter Writer(Context, O);
151 Writer.WriteGraph(
Self);
152 llvm::errs() <<
" done. \n";
157 DisplayGraph(Filename);
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Allows QualTypes to be sorted and hence used in maps and sets.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
void viewInheritance(ASTContext &Context) const
Renders and displays an inheritance diagram for this C++ class and all of its base classes (transitiv...
A (possibly-)qualified type.
void * getAsOpaquePtr() const
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
The base class of the type hierarchy.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Type
The name was classified as a type.
U cast(CodeGen::Address addr)