Blame camlp4/Camlp4/Printers/DumpOCamlAst.ml

Packit 1f8b6b
(****************************************************************************)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(*                                   OCaml                                  *)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(*                            INRIA Rocquencourt                            *)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(*  Copyright  2006   Institut National de Recherche  en  Informatique et   *)
Packit 1f8b6b
(*  en Automatique.  All rights reserved.  This file is distributed under   *)
Packit 1f8b6b
(*  the terms of the GNU Library General Public License, with the special   *)
Packit 1f8b6b
(*  exception on linking described in LICENSE at the top of the Camlp4      *)
Packit 1f8b6b
(*  source tree.                                                            *)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(****************************************************************************)
Packit 1f8b6b
Packit 1f8b6b
(* Authors:
Packit 1f8b6b
 * - Daniel de Rauglaudre: initial version
Packit 1f8b6b
 * - Nicolas Pouillard: refactoring
Packit 1f8b6b
 *)
Packit 1f8b6b
Packit 1f8b6b
module Id : Sig.Id = struct
Packit 1f8b6b
  value name = "Camlp4Printers.DumpOCamlAst";
Packit 1f8b6b
  value version = Sys.ocaml_version;
Packit 1f8b6b
end;
Packit 1f8b6b
Packit 1f8b6b
module Make (Syntax : Sig.Camlp4Syntax)
Packit 1f8b6b
: (Sig.Printer Syntax.Ast).S
Packit 1f8b6b
= struct
Packit 1f8b6b
  include Syntax;
Packit 1f8b6b
  module Ast2pt = Struct.Camlp4Ast2OCamlAst.Make Ast;
Packit 1f8b6b
Packit 1f8b6b
  value with_open_out_file x f =
Packit 1f8b6b
    match x with
Packit 1f8b6b
    [ Some file -> do { let oc = open_out_bin file;
Packit 1f8b6b
                        f oc;
Packit 1f8b6b
                        flush oc;
Packit 1f8b6b
                        close_out oc }
Packit 1f8b6b
    | None -> do { set_binary_mode_out stdout True; f stdout; flush stdout } ];
Packit 1f8b6b
Packit 1f8b6b
  value dump_pt magic fname pt oc = do {
Packit 1f8b6b
    output_string oc magic;
Packit 1f8b6b
    output_value oc (if fname = "-" then "" else fname);
Packit 1f8b6b
    output_value oc pt;
Packit 1f8b6b
  };
Packit 1f8b6b
Packit 1f8b6b
  value print_interf ?(input_file = "-") ?output_file ast =
Packit 1f8b6b
    let pt = Ast2pt.sig_item ast in
Packit 1f8b6b
    with_open_out_file output_file (dump_pt Camlp4_config.ocaml_ast_intf_magic_number input_file pt);
Packit 1f8b6b
Packit 1f8b6b
  value print_implem ?(input_file = "-") ?output_file ast =
Packit 1f8b6b
    let pt = Ast2pt.str_item ast in
Packit 1f8b6b
    with_open_out_file output_file (dump_pt Camlp4_config.ocaml_ast_impl_magic_number input_file pt);
Packit 1f8b6b
Packit 1f8b6b
end;