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) { }
44 Out <<
"digraph \"" << llvm::DOT::EscapeString(
Type.getAsString())
46 WriteNode(
Type,
false);
58 raw_ostream& WriteNodeReference(
QualType Type,
bool FromVirtual);
62void InheritanceHierarchyWriter::WriteNode(
QualType Type,
bool FromVirtual) {
66 if (KnownVirtualBases.find(CanonType) != KnownVirtualBases.end())
71 KnownVirtualBases.insert(CanonType);
76 WriteNodeReference(
Type, FromVirtual);
80 Out <<
" [ shape=\"box\", label=\"" << llvm::DOT::EscapeString(TypeName);
95 for (
const auto &
Base :
Decl->bases()) {
100 if (!
Base.isVirtual())
101 ++DirectBaseCount[CanonBaseType];
104 WriteNode(
Base.getType(),
Base.isVirtual());
108 WriteNodeReference(
Type, FromVirtual);
110 WriteNodeReference(
Base.getType(),
Base.isVirtual());
113 if (
Base.isVirtual()) {
114 Out <<
" [ style=\"dashed\" ]";
124InheritanceHierarchyWriter::WriteNodeReference(
QualType Type,
130 Out <<
"_" << DirectBaseCount[CanonType];
141 if (std::error_code EC = llvm::sys::fs::createTemporaryFile(
143 llvm::errs() <<
"Error: " << EC.message() <<
"\n";
147 llvm::errs() <<
"Writing '" <<
Filename <<
"'... ";
149 llvm::raw_fd_ostream O(FD,
true);
151 InheritanceHierarchyWriter Writer(Context, O);
152 Writer.WriteGraph(
Self);
153 llvm::errs() <<
" done. \n";
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 ...
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Represents a C++ struct/union/class.
void viewInheritance(ASTContext &Context) const
Renders and displays an inheritance diagram for this C++ class and all of its base classes (transitiv...
Decl - This represents one declaration (or definition), e.g.
A (possibly-)qualified type.
void * getAsOpaquePtr() const
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
The base class of the type hierarchy.
const T * castAs() const
Member-template castAs<specific type>.
The JSON file list parser is used to communicate input to InstallAPI.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.