Skip to content

Commit 6316346

Browse files
committed
snapshot
1 parent be52429 commit 6316346

File tree

1 file changed

+131
-130
lines changed

1 file changed

+131
-130
lines changed

lib/4.06.1/whole_compiler.ml

Lines changed: 131 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -365704,6 +365704,125 @@ let write_ast (type t) ~(sourcefile : string) ~output (kind : t Ml_binary.kind)
365704365704
close_out oc
365705365705

365706365706

365707+
end
365708+
module Cmd_ast_exception
365709+
= struct
365710+
#1 "cmd_ast_exception.ml"
365711+
type error =
365712+
| CannotRun of string
365713+
| WrongMagic of string
365714+
365715+
exception Error of error
365716+
365717+
365718+
let report_error ppf = function
365719+
| CannotRun cmd ->
365720+
Format.fprintf ppf "Error while running external preprocessor@.\
365721+
Command line: %s@." cmd
365722+
| WrongMagic cmd ->
365723+
Format.fprintf ppf "External preprocessor does not produce a valid file@.\
365724+
Command line: %s@." cmd
365725+
365726+
let () =
365727+
Location.register_error_of_exn
365728+
(function
365729+
| Error err -> Some (Location.error_of_printer_file report_error err)
365730+
| _ -> None
365731+
)
365732+
365733+
let cannot_run comm =
365734+
raise (Error (CannotRun comm))
365735+
365736+
let wrong_magic magic =
365737+
raise (Error (WrongMagic magic))
365738+
end
365739+
module Cmd_ppx_apply
365740+
= struct
365741+
#1 "cmd_ppx_apply.ml"
365742+
365743+
365744+
(* Note: some of the functions here should go to Ast_mapper instead,
365745+
which would encapsulate the "binary AST" protocol. *)
365746+
365747+
let write_ast (type a) (kind : a Ml_binary.kind) fn (ast : a) =
365748+
let oc = open_out_bin fn in
365749+
output_string oc (Ml_binary.magic_of_kind kind);
365750+
output_value oc (!Location.input_name : string);
365751+
output_value oc (ast : a);
365752+
close_out oc
365753+
365754+
let apply_rewriter kind fn_in ppx =
365755+
let magic = Ml_binary.magic_of_kind kind in
365756+
let fn_out = Filename.temp_file "camlppx" "" in
365757+
let comm =
365758+
Printf.sprintf "%s %s %s" ppx (Filename.quote fn_in) (Filename.quote fn_out)
365759+
in
365760+
let ok = Ccomp.command comm = 0 in
365761+
Misc.remove_file fn_in;
365762+
if not ok then begin
365763+
Misc.remove_file fn_out;
365764+
Cmd_ast_exception.cannot_run comm
365765+
end;
365766+
if not (Sys.file_exists fn_out) then
365767+
Cmd_ast_exception.cannot_run comm;
365768+
(* check magic before passing to the next ppx *)
365769+
let ic = open_in_bin fn_out in
365770+
let buffer =
365771+
try really_input_string ic (String.length magic) with End_of_file -> "" in
365772+
close_in ic;
365773+
if buffer <> magic then begin
365774+
Misc.remove_file fn_out;
365775+
Cmd_ast_exception.wrong_magic buffer;
365776+
end;
365777+
fn_out
365778+
365779+
let read_ast (type a) (kind : a Ml_binary.kind) fn : a =
365780+
let ic = open_in_bin fn in
365781+
try
365782+
let magic = Ml_binary.magic_of_kind kind in
365783+
let buffer = really_input_string ic (String.length magic) in
365784+
assert(buffer = magic); (* already checked by apply_rewriter *)
365785+
Location.set_input_name @@ (input_value ic : string);
365786+
let ast = (input_value ic : a) in
365787+
close_in ic;
365788+
Misc.remove_file fn;
365789+
ast
365790+
with exn ->
365791+
close_in ic;
365792+
Misc.remove_file fn;
365793+
raise exn
365794+
let rewrite kind ppxs ast =
365795+
let fn = Filename.temp_file "camlppx" "" in
365796+
write_ast kind fn ast;
365797+
let fn = List.fold_left (apply_rewriter kind) fn (List.rev ppxs) in
365798+
read_ast kind fn
365799+
365800+
let apply_rewriters_str ?(restore = true) ~tool_name ast =
365801+
match !Clflags.all_ppx with
365802+
| [] -> ast
365803+
| ppxs ->
365804+
ast
365805+
|> Ast_mapper.add_ppx_context_str ~tool_name
365806+
|> rewrite Ml ppxs
365807+
|> Ast_mapper.drop_ppx_context_str ~restore
365808+
365809+
let apply_rewriters_sig ?(restore = true) ~tool_name ast =
365810+
match !Clflags.all_ppx with
365811+
| [] -> ast
365812+
| ppxs ->
365813+
ast
365814+
|> Ast_mapper.add_ppx_context_sig ~tool_name
365815+
|> rewrite Mli ppxs
365816+
|> Ast_mapper.drop_ppx_context_sig ~restore
365817+
365818+
let apply_rewriters ?restore ~tool_name
365819+
(type a) (kind : a Ml_binary.kind) (ast : a) : a =
365820+
match kind with
365821+
| Ml_binary.Ml ->
365822+
apply_rewriters_str ?restore ~tool_name ast
365823+
| Ml_binary.Mli ->
365824+
apply_rewriters_sig ?restore ~tool_name ast
365825+
365707365826
end
365708365827
module Compmisc : sig
365709365828
#1 "compmisc.mli"
@@ -403482,125 +403601,6 @@ let lambda_as_module
403482403601
However, use filename instead of {!Env.current_unit} is more honest, since node-js module system is coupled with the file name
403483403602
*)
403484403603

403485-
end
403486-
module Cmd_ast_exception
403487-
= struct
403488-
#1 "cmd_ast_exception.ml"
403489-
type error =
403490-
| CannotRun of string
403491-
| WrongMagic of string
403492-
403493-
exception Error of error
403494-
403495-
403496-
let report_error ppf = function
403497-
| CannotRun cmd ->
403498-
Format.fprintf ppf "Error while running external preprocessor@.\
403499-
Command line: %s@." cmd
403500-
| WrongMagic cmd ->
403501-
Format.fprintf ppf "External preprocessor does not produce a valid file@.\
403502-
Command line: %s@." cmd
403503-
403504-
let () =
403505-
Location.register_error_of_exn
403506-
(function
403507-
| Error err -> Some (Location.error_of_printer_file report_error err)
403508-
| _ -> None
403509-
)
403510-
403511-
let cannot_run comm =
403512-
raise (Error (CannotRun comm))
403513-
403514-
let wrong_magic magic =
403515-
raise (Error (WrongMagic magic))
403516-
end
403517-
module Cmd_ppx_apply
403518-
= struct
403519-
#1 "cmd_ppx_apply.ml"
403520-
403521-
403522-
(* Note: some of the functions here should go to Ast_mapper instead,
403523-
which would encapsulate the "binary AST" protocol. *)
403524-
403525-
let write_ast (type a) (kind : a Ml_binary.kind) fn (ast : a) =
403526-
let oc = open_out_bin fn in
403527-
output_string oc (Ml_binary.magic_of_kind kind);
403528-
output_value oc (!Location.input_name : string);
403529-
output_value oc (ast : a);
403530-
close_out oc
403531-
403532-
let apply_rewriter kind fn_in ppx =
403533-
let magic = Ml_binary.magic_of_kind kind in
403534-
let fn_out = Filename.temp_file "camlppx" "" in
403535-
let comm =
403536-
Printf.sprintf "%s %s %s" ppx (Filename.quote fn_in) (Filename.quote fn_out)
403537-
in
403538-
let ok = Ccomp.command comm = 0 in
403539-
Misc.remove_file fn_in;
403540-
if not ok then begin
403541-
Misc.remove_file fn_out;
403542-
Cmd_ast_exception.cannot_run comm
403543-
end;
403544-
if not (Sys.file_exists fn_out) then
403545-
Cmd_ast_exception.cannot_run comm;
403546-
(* check magic before passing to the next ppx *)
403547-
let ic = open_in_bin fn_out in
403548-
let buffer =
403549-
try really_input_string ic (String.length magic) with End_of_file -> "" in
403550-
close_in ic;
403551-
if buffer <> magic then begin
403552-
Misc.remove_file fn_out;
403553-
Cmd_ast_exception.wrong_magic buffer;
403554-
end;
403555-
fn_out
403556-
403557-
let read_ast (type a) (kind : a Ml_binary.kind) fn : a =
403558-
let ic = open_in_bin fn in
403559-
try
403560-
let magic = Ml_binary.magic_of_kind kind in
403561-
let buffer = really_input_string ic (String.length magic) in
403562-
assert(buffer = magic); (* already checked by apply_rewriter *)
403563-
Location.set_input_name @@ (input_value ic : string);
403564-
let ast = (input_value ic : a) in
403565-
close_in ic;
403566-
Misc.remove_file fn;
403567-
ast
403568-
with exn ->
403569-
close_in ic;
403570-
Misc.remove_file fn;
403571-
raise exn
403572-
let rewrite kind ppxs ast =
403573-
let fn = Filename.temp_file "camlppx" "" in
403574-
write_ast kind fn ast;
403575-
let fn = List.fold_left (apply_rewriter kind) fn (List.rev ppxs) in
403576-
read_ast kind fn
403577-
403578-
let apply_rewriters_str ?(restore = true) ~tool_name ast =
403579-
match !Clflags.all_ppx with
403580-
| [] -> ast
403581-
| ppxs ->
403582-
ast
403583-
|> Ast_mapper.add_ppx_context_str ~tool_name
403584-
|> rewrite Ml ppxs
403585-
|> Ast_mapper.drop_ppx_context_str ~restore
403586-
403587-
let apply_rewriters_sig ?(restore = true) ~tool_name ast =
403588-
match !Clflags.all_ppx with
403589-
| [] -> ast
403590-
| ppxs ->
403591-
ast
403592-
|> Ast_mapper.add_ppx_context_sig ~tool_name
403593-
|> rewrite Mli ppxs
403594-
|> Ast_mapper.drop_ppx_context_sig ~restore
403595-
403596-
let apply_rewriters ?restore ~tool_name
403597-
(type a) (kind : a Ml_binary.kind) (ast : a) : a =
403598-
match kind with
403599-
| Ml_binary.Ml ->
403600-
apply_rewriters_str ?restore ~tool_name ast
403601-
| Ml_binary.Mli ->
403602-
apply_rewriters_sig ?restore ~tool_name ast
403603-
403604403604
end
403605403605
module Parse : sig
403606403606
#1 "parse.mli"
@@ -403706,13 +403706,12 @@ module Pparse_driver : sig
403706403706

403707403707
val parse_implementation:
403708403708
Format.formatter ->
403709-
tool_name:string ->
403710403709
string -> Parsetree.structure
403711403710

403712403711

403713403712
val parse_interface:
403714403713
Format.formatter ->
403715-
tool_name:string ->
403714+
403716403715
string -> Parsetree.signature
403717403716

403718403717
end = struct
@@ -403792,7 +403791,7 @@ let file_aux ppf inputfile (type a) (parse_fun : _ -> a)
403792403791

403793403792

403794403793

403795-
let parse_file kind ppf sourcefile =
403794+
let parse_file (type a) (kind : a Ml_binary.kind) (ppf : Format.formatter) (sourcefile : string) : a =
403796403795
Location.set_input_name sourcefile;
403797403796
let inputfile = preprocess sourcefile in
403798403797
let ast =
@@ -403807,12 +403806,12 @@ let parse_file kind ppf sourcefile =
403807403806

403808403807

403809403808

403810-
let parse_implementation ppf ~tool_name sourcefile =
403811-
Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name Ml (parse_file
403809+
let parse_implementation ppf sourcefile =
403810+
(parse_file
403812403811
Ml ppf sourcefile)
403813-
let parse_interface ppf ~tool_name sourcefile =
403814-
Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name Mli (parse_file
403815-
Mli ppf sourcefile)
403812+
403813+
let parse_interface ppf sourcefile =
403814+
parse_file Mli ppf sourcefile
403816403815

403817403816
end
403818403817
module Pprintast : sig
@@ -416077,7 +416076,8 @@ let after_parsing_sig ppf outputprefix ast =
416077416076

416078416077
let interface ppf fname outputprefix =
416079416078
Compmisc.init_path false;
416080-
Pparse_driver.parse_interface ~tool_name:Js_config.tool_name ppf fname
416079+
Pparse_driver.parse_interface ppf fname
416080+
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli
416081416081
|> Ppx_entry.rewrite_signature
416082416082
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
416083416083
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
@@ -416174,8 +416174,9 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
416174416174
process_with_gentype (outputprefix ^ ".cmt")
416175416175
end
416176416176
let implementation ppf fname outputprefix =
416177-
Compmisc.init_path false;
416178-
Pparse_driver.parse_implementation ~tool_name:Js_config.tool_name ppf fname
416177+
Compmisc.init_path false;
416178+
Pparse_driver.parse_implementation ppf fname
416179+
|> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml
416179416180
|> Ppx_entry.rewrite_implementation
416180416181
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
416181416182
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure

0 commit comments

Comments
 (0)