Create dot files for various hierarchies of a model.

See graphviz http://www.graphviz.org/

Introduced classes

Redefined classes

redef class Sys

nitc :: generate_hierarchies $ Sys

The main class of the program.
redef class ToolContext

nitc :: generate_hierarchies $ ToolContext

Global context for tools

All class definitions

redef class Sys

nitc :: generate_hierarchies $ Sys

The main class of the program.
redef class ToolContext

nitc :: generate_hierarchies $ ToolContext

Global context for tools
package_diagram nitc::generate_hierarchies generate_hierarchies nitc::metrics_base metrics_base nitc::generate_hierarchies->nitc::metrics_base nitc::model_viz model_viz nitc::generate_hierarchies->nitc::model_viz nitc::modelbuilder modelbuilder nitc::metrics_base->nitc::modelbuilder csv csv nitc::metrics_base->csv counter counter nitc::metrics_base->counter nitc\>model\> model nitc::model_viz->nitc\>model\> ...nitc::modelbuilder ... ...nitc::modelbuilder->nitc::modelbuilder ...csv ... ...csv->csv ...counter ... ...counter->counter ...nitc\>model\> ... ...nitc\>model\>->nitc\>model\> nitc::metrics metrics nitc::metrics->nitc::generate_hierarchies nitc::nitmetrics nitmetrics nitc::nitmetrics->nitc::metrics nitc::api_metrics api_metrics nitc::api_metrics->nitc::metrics nitc::nitmetrics... ... nitc::nitmetrics...->nitc::nitmetrics nitc::api_metrics... ... nitc::api_metrics...->nitc::api_metrics

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module counter

counter :: counter

Simple numerical statistical analysis and presentation
module csv

csv :: csv

CSV document handling.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module loader

nitc :: loader

Loading of Nit source files
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module metrics_base

nitc :: metrics_base

Helpers for various statistics tools.
module model_viz

nitc :: model_viz

Visualisation of Nit models

Children

module metrics

nitc :: metrics

Various statistics about Nit models and programs

Descendants

module a_star-m

a_star-m

module api

nitc :: api

Components required to build a web server about the nit model.
module nitmetrics

nitc :: nitmetrics

A program that collects various metrics on nit programs and libraries
module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
# Create dot files for various hierarchies of a model.
# See graphviz http://www.graphviz.org/
module generate_hierarchies

import metrics_base
import model::model_viz

redef class ToolContext
	var generate_hierarchies_phase: Phase = new GenerateHierarchyPhase(self, null)
end

private class GenerateHierarchyPhase
	super Phase

	redef fun process_mainmodule(mainmodule, given_mmodules)
	do
		if not toolcontext.opt_generate_hyperdoc.value and not toolcontext.opt_all.value then return
		var model = toolcontext.modelbuilder.model
		generate_module_hierarchy(toolcontext, given_mmodules)
		generate_classdef_hierarchy(toolcontext, model)
		generate_class_hierarchy(toolcontext, mainmodule)
	end
end

# Create a dot file representing the module hierarchy of a model.
# Importation relation is represented with arrow
# Nesting relation is represented with nested boxes
fun generate_module_hierarchy(toolcontext: ToolContext, given_mmodules: Collection[MModule])
do
	var model = given_mmodules.first.model
	var dot = new MPackageDot(model)

	# Collect requested packages
	for m in given_mmodules do
		var g = m.mgroup
		if g == null then continue
		dot.mpackages.add(g.mpackage)
	end
	var packagepath = toolcontext.output_dir.join_path("package_hierarchy.dot")
	print "generating package_hierarchy.dot"
	dot.write_to_file(packagepath)

	var modulepath = toolcontext.output_dir.join_path("module_hierarchy.dot")
	dot.mpackages.add_all(model.mpackages)
	print "generating module_hierarchy.dot"
	dot.write_to_file(modulepath)
end

# Create a dot file representing the class hierarchy of a model.
fun generate_class_hierarchy(toolcontext: ToolContext, mmodule: MModule)
do
	var buf = new FlatBuffer
	buf.append("digraph \{\n")
	buf.append("node [shape=box];\n")
	buf.append("rankdir=BT;\n")
	var hierarchy = mmodule.flatten_mclass_hierarchy
	for mclass in hierarchy do
		buf.append("\"{mclass}\" [label=\"{mclass}\"];\n")
		for s in hierarchy[mclass].direct_greaters do
			buf.append("\"{mclass}\" -> \"{s}\";\n")
		end
	end
	buf.append("\}\n")
	var f = new FileWriter.open(toolcontext.output_dir.join_path("class_hierarchy.dot"))
	f.write(buf.to_s)
	f.close
end

# Create a dot file representing the classdef hierarchy of a model.
# For a simple user of the model, the classdef hierarchy is not really usefull, it is more an internal thing.
fun generate_classdef_hierarchy(toolcontext: ToolContext, model: Model)
do
	var buf = new FlatBuffer
	buf.append("digraph \{\n")
	buf.append("node [shape=box];\n")
	buf.append("rankdir=BT;\n")
	for mmodule in model.mmodules do
		for mclassdef in mmodule.mclassdefs do
			buf.append("\"{mclassdef} {mclassdef.bound_mtype}\" [label=\"{mclassdef.mmodule}\\n{mclassdef.bound_mtype}\"];\n")
			for s in mclassdef.in_hierarchy.direct_greaters do
				buf.append("\"{mclassdef} {mclassdef.bound_mtype}\" -> \"{s} {s.bound_mtype}\";\n")
			end
		end
	end
	buf.append("\}\n")
	var f = new FileWriter.open(toolcontext.output_dir.join_path("classdef_hierarchy.dot"))
	f.write(buf.to_s)
	f.close
end
src/metrics/generate_hierarchies.nit:17,1--105,3