caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Esther Baruk <esther.baruk@gmail.com>
To: yoann padioleau <yoann.padioleau@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Is there a typed bin-annot cmt tree with module and type aliases resolved?
Date: Tue, 4 Dec 2012 09:18:12 +0100	[thread overview]
Message-ID: <CAFzMiE0fWcwHDxNBJ=ZFcaVT66m1q++8no23uOSuK38fJ1bkaQ@mail.gmail.com> (raw)
In-Reply-To: <CAFksq2_T4=ArqM+8EJONx4O_fHi78x5GqttxFNTdxss=b3RjQQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3363 bytes --]

Hi,

The goal of this cmt file is to reflect the AST as it is in the source file
so that explains why the aliases are not meant to be resolved.
You can perform an analysis on the tree and rewrite it while resolving
aliases. A functor will let you write just the functions you need and do
the pattern matching for you : typedtreeIter.ml. It is located in the
"typing" directory of the OCaml sources.

Esther Baruk


On Tue, Dec 4, 2012 at 2:08 AM, yoann padioleau
<yoann.padioleau@gmail.com>wrote:

> Hi,
>
> I want to use the .cmt files generated by -bin-annot for some
> dependency analysis. The
> problem is that not all names are resolved, especially module aliases
> and type aliases are not
> resolved. For instance on this file:
>
> module X = Variant
> open Nested_module
> module Y = Nested
>
> let use_variant = function
>   | X.Constructor1 -> 1
>   | _ -> 2
>
>
> I got this dump for the AST/CMT file:
> {
>  str_items=[Tstr_module("X", (), Tmod_ident("Variant", ()));
>             Tstr_open("Nested_module", ());
>             Tstr_module("Y", (), Tmod_ident("Nested_module.Nested", ()));
>             Tstr_value((),
>               [(Tpat_var("use_variant", ()),
>                 Texp_function((),
>                   [(Tpat_construct("X.Constructor1", (), (), [], false),
>                     Texp_constant(())); (Tpat_any, Texp_constant(()))],
> ()))])];
>  str_type=(); str_final_env=(); }
>
> but I would really like an AST where all names are fully resolved, so
> X.Constructor1 becomes
> Variant.Constructor1. In the example above Nested_module.Nested is
> resolved (so the open Nested_module
> is handled), but not X.Constructor1.
>
> Same for types, with this file:
> type list2 = int list
>
> type use_list2 =
>   | Constructor of list2
>
> let f = function
>   | Constructor [] -> 1
>   | _ -> 2
>
>
> I got this dump of the AST/CMT:
> {
>  str_items=[Tstr_type(
>               [("list2", (),
>                 {typ_params=[]; typ_type=(); typ_cstrs=[];
>                  typ_kind=Ttype_abstract; typ_private=();
>                  typ_manifest=Some(Ttyp_constr("list", (),
>                                      [Ttyp_constr("int", (), [])]));
>                  typ_variance=[]; typ_loc=(); })]);
>             Tstr_type(
>               [("use_list2", (),
>                 {typ_params=[]; typ_type=(); typ_cstrs=[];
>                  typ_kind=Ttype_variant(
>                             [("Constructor", (),
>                               [Ttyp_constr("list2", (), [])], ())]);
>                  typ_private=(); typ_manifest=None; typ_variance=[];
>                  typ_loc=(); })]);
>             Tstr_value((),
>               [(Tpat_var("f", ()),
>                 Texp_function((),
>                   [(Tpat_construct("Constructor", (), (),
>                       [Tpat_construct("[]", (), (), [], false)], false),
>                     Texp_constant(())); (Tpat_any, Texp_constant(()))],
> ()))])];
>  str_type=(); str_final_env=(); }
>
> and when I ask the type of [], it says list2, but I would really like
> the final type that is int list2.
>
> Should I use env.ml for resolving?
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 4470 bytes --]

      reply	other threads:[~2012-12-04  8:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-04  1:08 yoann padioleau
2012-12-04  8:18 ` Esther Baruk [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFzMiE0fWcwHDxNBJ=ZFcaVT66m1q++8no23uOSuK38fJ1bkaQ@mail.gmail.com' \
    --to=esther.baruk@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=yoann.padioleau@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).