[m-rev.] for review: --imports-graph option

Peter Wang wangp at students.csse.unimelb.edu.au
Wed Jun 13 11:01:50 AEST 2007


On 2007-06-13, Peter Ross <pro at missioncriticalit.com> wrote:
> Hi,
> 
> 
> ===================================================================
> 
> 
> Estimated hours taken: 3
> Branches: main
> 
> Add the option --imports-graph which outputs the directed graph of
> module A imports module B.

Can you explain that more clearly?

> +:- func filter_relation(pair(sym_name, sym_name),
> +    relation(sym_name)) = relation(sym_name).
> +
> +filter_relation(A - B, Relation) =
> +    (
> +        %
> +        % Don't keep the relation if it points to a builtin-module
> +        % or if the relationship is between two standard library
> +        % modules
> +        % XXX it would be better to change this to be only keep those
> +        % relations for which the left-hand side is in the current
> +        % directory.
> +        %
> +        (
> +            any_mercury_builtin_module(B)
> +        ;
> +            is_std_lib_module_name(A, _),
> +            is_std_lib_module_name(B, _)
> +        )
> +    ->
> +        Relation
> +    ;
> +        relation.add_values(Relation, A, B)
> +    ).
> +

You might want to rename filter_relation, write_relation, write_node
and write_edge to less ambiguous names.

> +
> +:- pred write_relation(io.output_stream::in, string::in,
> +    relation(sym_name)::in, io::di, io::uo) is det.
> + 
> +write_relation(Stream, Name, Relation, !IO) :-
> +    io.write_string(Stream, "digraph " ++ Name ++ " {\n", !IO),
> +    io.write_string(Stream, "label=\"" ++ Name ++ "\";\n", !IO),
> +    io.write_string(Stream, "center=true;\n", !IO),
> +    relation.traverse(Relation, write_node(Stream), write_edge(Stream), !IO),
> +    io.write_string(Stream, "}\n", !IO).
> + 
> +:- pred write_node(io.output_stream::in, sym_name::in, io::di, io::uo) is det.
> + 
> +write_node(Stream, Node, !IO) :-
> +        % Names can't contain "." so use "__"
> +    io.write_string(Stream, sym_name_to_string_sep(Node, "__"), !IO),
> +    io.write_string(Stream, ";\n", !IO).
> +
> +:- pred write_edge(io.output_stream::in, sym_name::in, sym_name::in,
> +    io::di, io::uo) is det.
> + 
> +write_edge(Stream, A, B, !IO) :-
> +        % Names can't contain "." so use "__"
> +    io.write_string(Stream, sym_name_to_string_sep(A, "__"), !IO),
> +    io.write_string(Stream, " -> ", !IO),
> +    io.write_string(Stream, sym_name_to_string_sep(B, "__"), !IO),
> +    io.write_string(Stream, ";\n", !IO).

I think dot labels can contain . if you use quotes.

> @@ -3318,6 +3321,10 @@
>          "\tuse the `--no-llds-optimize' option.)",
>          "--show-dependency-graph",
>          "\tWrite out the dependency graph to `<module>.dependency_graph'.",
> +        "--imports-graph",
> +        "\tWrite out the imports graph to `<module>.imports_graph'.",
> +        "\tThe imports graph shows the directed graph module A",
> +        "\timports module B.",

It doesn't mention that these can be processed by dot.

>  % This option is for developers only.
>  %       "--dump-trace-counts <stage number or name>",
>  %       "\tIf the compiler was compiled with debugging enabled and is being",
> Index: doc/user_guide.texi
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
> retrieving revision 1.525
> diff -u -r1.525 user_guide.texi
> --- doc/user_guide.texi	12 Jun 2007 06:39:17 -0000	1.525
> +++ doc/user_guide.texi	13 Jun 2007 00:34:15 -0000
> @@ -6678,6 +6678,13 @@
>  @findex --show-dependency-graph
>  Write out the dependency graph to @var{module}.dependency_graph.
>  
> + at sp 1
> + at item --imports-graph
> + at findex --imports-graph
> +Write out the imports graph to @var{module}.imports_graph.
> +The imports graph shows the directed graph module A
> +imports module B.
> +

Likewise.

Otherwise it looks fine.

Peter
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list