Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: parsing/printast.mli
- ===================================================================
- --- parsing/printast.mli (revision 13953)
- +++ parsing/printast.mli (working copy)
- @@ -16,3 +16,4 @@
- val interface : formatter -> signature_item list -> unit;;
- val implementation : formatter -> structure_item list -> unit;;
- val top_phrase : formatter -> toplevel_phrase -> unit;;
- +val string_of_kind : ident_kind -> string;;
- Index: parsing/pprintast.ml
- ===================================================================
- --- parsing/pprintast.ml (revision 13953)
- +++ parsing/pprintast.ml (working copy)
- @@ -1192,8 +1192,10 @@
- | Pdir_none -> ()
- | Pdir_string (s) -> pp f "@ %S" s
- | Pdir_int (i) -> pp f "@ %d" i
- - | Pdir_ident (li) -> pp f "@ %a" self#longident li
- - | Pdir_bool (b) -> pp f "@ %s" (string_of_bool b))
- + | Pdir_ident {txt=li} -> pp f "@ %a" self#longident li
- + | Pdir_bool (b) -> pp f "@ %s" (string_of_bool b)
- + | Pdir_show (k, {txt=li}) ->
- + pp f "@ %s %a" (Printast.string_of_kind k) self#longident li)
- method toplevel_phrase f x =
- match x with
- Index: parsing/parser.mly
- ===================================================================
- --- parsing/parser.mly (revision 13953)
- +++ parsing/parser.mly (working copy)
- @@ -516,9 +516,9 @@
- | SEMISEMI EOF { [] }
- | SEMISEMI seq_expr use_file_tail { Ptop_def[mkstrexp $2] :: $3 }
- | SEMISEMI structure_item use_file_tail { Ptop_def[$2] :: $3 }
- - | SEMISEMI toplevel_directive use_file_tail { $2 :: $3 }
- | structure_item use_file_tail { Ptop_def[$1] :: $2 }
- - | toplevel_directive use_file_tail { $1 :: $2 }
- + | SEMISEMI toplevel_directive SEMISEMI use_file_tail { $2 :: $4 }
- + | toplevel_directive SEMISEMI use_file_tail { $1 :: $3 }
- ;
- /* Module expressions */
- @@ -1779,16 +1779,26 @@
- | FALSE { Lident "false" }
- | TRUE { Lident "true" }
- ;
- +ident_kind:
- + VAL { Pkind_val }
- + | TYPE { Pkind_type }
- + | EXCEPTION { Pkind_exception }
- + | MODULE { Pkind_module }
- + | MODULE TYPE { Pkind_modtype }
- + | CLASS { Pkind_class }
- + | CLASS TYPE { Pkind_cltype }
- +;
- /* Toplevel directives */
- toplevel_directive:
- - SHARP ident { Ptop_dir($2, Pdir_none) }
- - | SHARP ident STRING { Ptop_dir($2, Pdir_string $3) }
- - | SHARP ident INT { Ptop_dir($2, Pdir_int $3) }
- - | SHARP ident val_longident { Ptop_dir($2, Pdir_ident $3) }
- - | SHARP ident FALSE { Ptop_dir($2, Pdir_bool false) }
- - | SHARP ident TRUE { Ptop_dir($2, Pdir_bool true) }
- + SHARP ident { Ptop_dir($2, Pdir_none) }
- + | SHARP ident STRING { Ptop_dir($2, Pdir_string $3) }
- + | SHARP ident INT { Ptop_dir($2, Pdir_int $3) }
- + | SHARP ident val_longident { Ptop_dir($2, Pdir_ident (mkrhs $3 3)) }
- + | SHARP ident ident_kind any_longident { Ptop_dir($2, Pdir_show ($3, mkrhs $4 4)) }
- + | SHARP ident FALSE { Ptop_dir($2, Pdir_bool false) }
- + | SHARP ident TRUE { Ptop_dir($2, Pdir_bool true) }
- ;
- /* Miscellaneous */
- Index: parsing/parsetree.mli
- ===================================================================
- --- parsing/parsetree.mli (revision 13953)
- +++ parsing/parsetree.mli (working copy)
- @@ -294,6 +294,15 @@
- (* Toplevel phrases *)
- +type ident_kind =
- + Pkind_val
- + | Pkind_type
- + | Pkind_exception
- + | Pkind_module
- + | Pkind_modtype
- + | Pkind_class
- + | Pkind_cltype
- +
- type toplevel_phrase =
- Ptop_def of structure
- | Ptop_dir of string * directive_argument
- @@ -302,5 +311,6 @@
- Pdir_none
- | Pdir_string of string
- | Pdir_int of int
- - | Pdir_ident of Longident.t
- + | Pdir_ident of Longident.t Location.loc
- + | Pdir_show of ident_kind * Longident.t Location.loc
- | Pdir_bool of bool
- Index: parsing/printast.ml
- ===================================================================
- --- parsing/printast.ml (revision 13953)
- +++ parsing/printast.ml (working copy)
- @@ -737,6 +737,16 @@
- core_type (i+1) ppf ct
- ;;
- +let string_of_kind = function
- + Pkind_val -> "val"
- + | Pkind_type -> "type"
- + | Pkind_exception -> "exception"
- + | Pkind_module -> "module"
- + | Pkind_modtype -> "module type"
- + | Pkind_class -> "class"
- + | Pkind_cltype -> "class type"
- +;;
- +
- let rec toplevel_phrase i ppf x =
- match x with
- | Ptop_def (s) ->
- @@ -751,7 +761,9 @@
- | Pdir_none -> line i ppf "Pdir_none\n"
- | Pdir_string (s) -> line i ppf "Pdir_string \"%s\"\n" s;
- | Pdir_int (i) -> line i ppf "Pdir_int %d\n" i;
- - | Pdir_ident (li) -> line i ppf "Pdir_ident %a\n" fmt_longident li;
- + | Pdir_ident {txt=li} -> line i ppf "Pdir_ident %a\n" fmt_longident li;
- + | Pdir_show (kind,{txt=li}) ->
- + line i ppf "Pdir_show %s %a\n" (string_of_kind kind) fmt_longident li;
- | Pdir_bool (b) -> line i ppf "Pdir_bool %s\n" (string_of_bool b);
- ;;
- Index: toplevel/opttoploop.ml
- ===================================================================
- --- toplevel/opttoploop.ml (revision 13953)
- +++ toplevel/opttoploop.ml (working copy)
- @@ -53,6 +53,7 @@
- | Directive_string of (string -> unit)
- | Directive_int of (int -> unit)
- | Directive_ident of (Longident.t -> unit)
- + | Directive_show of (ident_kind -> Longident.t -> unit)
- | Directive_bool of (bool -> unit)
- @@ -270,6 +271,7 @@
- | (Directive_string f, Pdir_string s) -> f s; true
- | (Directive_int f, Pdir_int n) -> f n; true
- | (Directive_ident f, Pdir_ident lid) -> f lid; true
- + | (Directive_show f, Pdir_show (kind,lid)) -> f kind lid; true
- | (Directive_bool f, Pdir_bool b) -> f b; true
- | (_, _) ->
- fprintf ppf "Wrong type of argument for directive `%s'.@." dir_name;
- Index: toplevel/topdirs.ml
- ===================================================================
- --- toplevel/topdirs.ml (revision 13953)
- +++ toplevel/topdirs.ml (working copy)
- @@ -15,6 +15,7 @@
- open Format
- open Misc
- open Longident
- +open Parsetree
- open Types
- open Cmo_format
- open Trace
- @@ -191,9 +192,9 @@
- Ctype.generalize ty_arg;
- ty_arg
- -let find_printer_type ppf lid =
- +let find_printer_type ppf {Location.loc; txt=lid} =
- try
- - let (path, desc) = Env.lookup_value lid !toplevel_env in
- + let (path, desc) = Typetexp.find_value !toplevel_env loc lid in
- let (ty_arg, is_old_style) =
- try
- (match_printer_type ppf desc "printer_type_new", false)
- @@ -201,12 +202,12 @@
- (match_printer_type ppf desc "printer_type_old", true) in
- (ty_arg, path, is_old_style)
- with
- - | Not_found ->
- - fprintf ppf "Unbound value %a.@." Printtyp.longident lid;
- + Typetexp.Error _ as exn ->
- + Errors.report_error ppf exn;
- raise Exit
- | Ctype.Unify _ ->
- fprintf ppf "%a has a wrong type for a printing function.@."
- - Printtyp.longident lid;
- + Printtyp.longident lid;
- raise Exit
- let dir_install_printer ppf lid =
- @@ -227,7 +228,7 @@
- begin try
- remove_printer path
- with Not_found ->
- - fprintf ppf "No printer named %a.@." Printtyp.longident lid
- + fprintf ppf "No printer named %a.@." Printtyp.longident lid.Location.txt
- end
- with Exit -> ()
- @@ -244,9 +245,9 @@
- get_code_pointer
- (Obj.repr (fun arg -> Trace.print_trace (current_environment()) arg))
- -let dir_trace ppf lid =
- +let dir_trace ppf {Location.loc; txt=lid} =
- try
- - let (path, desc) = Env.lookup_value lid !toplevel_env in
- + let (path, desc) = Typetexp.find_value !toplevel_env loc lid in
- (* Check if this is a primitive *)
- match desc.val_kind with
- | Val_prim p ->
- @@ -278,11 +279,11 @@
- fprintf ppf "%a is now traced.@." Printtyp.longident lid
- end else fprintf ppf "%a is not a function.@." Printtyp.longident lid
- with
- - | Not_found -> fprintf ppf "Unbound value %a.@." Printtyp.longident lid
- + Typetexp.Error _ as exn -> Errors.report_error ppf exn
- -let dir_untrace ppf lid =
- +let dir_untrace ppf {Location.loc; txt=lid} =
- try
- - let (path, desc) = Env.lookup_value lid !toplevel_env in
- + let (path, desc) = Typetexp.find_value !toplevel_env loc lid in
- let rec remove = function
- | [] ->
- fprintf ppf "%a was not traced.@." Printtyp.longident lid;
- @@ -295,7 +296,7 @@
- end else f :: remove rem in
- traced_functions := remove !traced_functions
- with
- - | Not_found -> fprintf ppf "Unbound value %a.@." Printtyp.longident lid
- + Typetexp.Error _ as exn -> Errors.report_error ppf exn
- let dir_untrace_all ppf () =
- List.iter
- @@ -305,10 +306,74 @@
- !traced_functions;
- traced_functions := []
- +(* Warnings *)
- +
- let parse_warnings ppf iserr s =
- try Warnings.parse_options iserr s
- with Arg.Bad err -> fprintf ppf "%s.@." err
- +(* Typing information *)
- +
- +let rec trim_modtype = function
- + Mty_signature _ -> Mty_signature []
- + | Mty_functor (id, mty, mty') ->
- + Mty_functor (id, mty, trim_modtype mty')
- + | Mty_ident _ as mty -> mty
- +
- +let trim_signature = function
- + Mty_signature sg ->
- + Mty_signature
- + (List.map
- + (function
- + Sig_module (id, mty, rs) ->
- + Sig_module (id, trim_modtype mty, rs)
- + (*| Sig_modtype (id, Modtype_manifest mty) ->
- + Sig_modtype (id, Modtype_manifest (trim_modtype mty))*)
- + | item -> item)
- + sg)
- + | mty -> mty
- +
- +let dir_show ppf kind {Location.loc; txt=lid} =
- + let env = !Toploop.toplevel_env in
- + try
- + let id =
- + let s = match lid with
- + Longident.Lident s -> s
- + | Longident.Ldot (_,s) -> s
- + | Longident.Lapply _ -> failwith "invalid"
- + in Ident.create_persistent s
- + in
- + let item =
- + match kind with
- + Pkind_val ->
- + let path, desc = Typetexp.find_value env loc lid in
- + Sig_value (id, desc)
- + | Pkind_type ->
- + let path, desc = Typetexp.find_type env loc lid in
- + Sig_type (id, desc, Trec_not)
- + | Pkind_exception ->
- + let desc = Typetexp.find_constructor env loc lid in
- + Sig_exception (id, {exn_args=desc.cstr_args; exn_loc=Location.none})
- + | Pkind_module ->
- + let path, desc = Typetexp.find_module env loc lid in
- + Sig_module (id, trim_signature desc, Trec_not)
- + | Pkind_modtype ->
- + let path, desc = Typetexp.find_modtype env loc lid in
- + Sig_modtype (id, desc)
- + | Pkind_class ->
- + let path, desc = Typetexp.find_class env loc lid in
- + Sig_class (id, desc, Trec_not)
- + | Pkind_cltype ->
- + let path, desc = Typetexp.find_class_type env loc lid in
- + Sig_class_type (id, desc, Trec_not)
- + in
- + fprintf ppf "%a@." Printtyp.signature [item]
- + with
- + Not_found ->
- + fprintf ppf "Unknown %s.@." (Printast.string_of_kind kind)
- + | Failure "invalid" ->
- + fprintf ppf "Invalid path %a@." Printtyp.longident lid
- +
- let _ =
- Hashtbl.add directive_table "trace" (Directive_ident (dir_trace std_out));
- Hashtbl.add directive_table "untrace" (Directive_ident (dir_untrace std_out));
- @@ -337,4 +402,7 @@
- (Directive_string (parse_warnings std_out false));
- Hashtbl.add directive_table "warn_error"
- - (Directive_string (parse_warnings std_out true))
- + (Directive_string (parse_warnings std_out true));
- +
- + Hashtbl.add directive_table "show"
- + (Directive_show (dir_show std_out))
- Index: toplevel/toploop.ml
- ===================================================================
- --- toplevel/toploop.ml (revision 13953)
- +++ toplevel/toploop.ml (working copy)
- @@ -25,7 +25,8 @@
- | Directive_none of (unit -> unit)
- | Directive_string of (string -> unit)
- | Directive_int of (int -> unit)
- - | Directive_ident of (Longident.t -> unit)
- + | Directive_ident of (Longident.t Location.loc -> unit)
- + | Directive_show of (ident_kind -> Longident.t Location.loc -> unit)
- | Directive_bool of (bool -> unit)
- (* The table of toplevel value bindings and its accessors *)
- @@ -280,6 +281,7 @@
- | (Directive_string f, Pdir_string s) -> f s; true
- | (Directive_int f, Pdir_int n) -> f n; true
- | (Directive_ident f, Pdir_ident lid) -> f lid; true
- + | (Directive_show f, Pdir_show (kind,lid)) -> f kind lid; true
- | (Directive_bool f, Pdir_bool b) -> f b; true
- | (_, _) ->
- fprintf ppf "Wrong type of argument for directive `%s'.@." dir_name;
- Index: toplevel/topdirs.mli
- ===================================================================
- --- toplevel/topdirs.mli (revision 13953)
- +++ toplevel/topdirs.mli (working copy)
- @@ -20,11 +20,12 @@
- val dir_cd : string -> unit
- val dir_load : formatter -> string -> unit
- val dir_use : formatter -> string -> unit
- -val dir_install_printer : formatter -> Longident.t -> unit
- -val dir_remove_printer : formatter -> Longident.t -> unit
- -val dir_trace : formatter -> Longident.t -> unit
- -val dir_untrace : formatter -> Longident.t -> unit
- +val dir_install_printer : formatter -> Longident.t Location.loc -> unit
- +val dir_remove_printer : formatter -> Longident.t Location.loc -> unit
- +val dir_trace : formatter -> Longident.t Location.loc -> unit
- +val dir_untrace : formatter -> Longident.t Location.loc -> unit
- val dir_untrace_all : formatter -> unit -> unit
- +val dir_show : formatter -> Parsetree.ident_kind -> Longident.t Location.loc -> unit
- type 'a printer_type_new = Format.formatter -> 'a -> unit
- type 'a printer_type_old = 'a -> unit
- Index: toplevel/toploop.mli
- ===================================================================
- --- toplevel/toploop.mli (revision 13953)
- +++ toplevel/toploop.mli (working copy)
- @@ -37,7 +37,8 @@
- | Directive_none of (unit -> unit)
- | Directive_string of (string -> unit)
- | Directive_int of (int -> unit)
- - | Directive_ident of (Longident.t -> unit)
- + | Directive_ident of (Longident.t Location.loc -> unit)
- + | Directive_show of (Parsetree.ident_kind -> Longident.t Location.loc -> unit)
- | Directive_bool of (bool -> unit)
- val directive_table : (string, directive_fun) Hashtbl.t
Add Comment
Please, Sign In to add comment