20 #include "llvm/Support/FileSystem.h" 21 #include "llvm/Support/GraphWriter.h" 22 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
34 class InheritanceHierarchyWriter {
37 std::map<QualType, int, QualTypeOrdering> DirectBaseCount;
38 std::set<QualType, QualTypeOrdering> KnownVirtualBases;
41 InheritanceHierarchyWriter(
ASTContext& Context, raw_ostream& Out)
42 : Context(Context), Out(Out) { }
45 Out <<
"digraph \"" << llvm::DOT::EscapeString(Type.
getAsString())
47 WriteNode(Type,
false);
54 void WriteNode(
QualType Type,
bool FromVirtual);
59 raw_ostream& WriteNodeReference(
QualType Type,
bool FromVirtual);
63 void InheritanceHierarchyWriter::WriteNode(
QualType Type,
bool FromVirtual) {
67 if (KnownVirtualBases.find(CanonType) != KnownVirtualBases.end())
72 KnownVirtualBases.insert(CanonType);
77 WriteNodeReference(Type, FromVirtual);
81 Out <<
" [ shape=\"box\", label=\"" << llvm::DOT::EscapeString(TypeName);
101 if (!
Base.isVirtual())
102 ++DirectBaseCount[CanonBaseType];
105 WriteNode(
Base.getType(),
Base.isVirtual());
109 WriteNodeReference(Type, FromVirtual);
111 WriteNodeReference(
Base.getType(),
Base.isVirtual());
114 if (
Base.isVirtual()) {
115 Out <<
" [ style=\"dashed\" ]";
125 InheritanceHierarchyWriter::WriteNodeReference(
QualType Type,
131 Out <<
"_" << DirectBaseCount[CanonType];
142 if (std::error_code EC = llvm::sys::fs::createTemporaryFile(
144 llvm::errs() <<
"Error: " << EC.message() <<
"\n";
148 llvm::errs() <<
"Writing '" << Filename <<
"'... ";
150 llvm::raw_fd_ostream O(FD,
true);
152 InheritanceHierarchyWriter Writer(Context, O);
153 Writer.WriteGraph(Self);
154 llvm::errs() <<
" done. \n";
159 DisplayGraph(Filename);
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
Decl - This represents one declaration (or definition), e.g.
The base class of the type hierarchy.
const T * getAs() const
Member-template getAs<specific type>'.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void * getAsOpaquePtr() const
Allows QualTypes to be sorted and hence used in maps and sets.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Dataflow Directional Tag Classes.
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...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
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...