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.insert(CanonType).second)
75 WriteNodeReference(
Type, FromVirtual);
79 Out <<
" [ shape=\"box\", label=\"" << llvm::DOT::EscapeString(TypeName);
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(
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";
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'.