diff options
| author | Alain Frisch <alain@frisch.fr> | 2014-08-07 16:07:55 +0000 |
|---|---|---|
| committer | Alain Frisch <alain@frisch.fr> | 2014-08-07 16:07:55 +0000 |
| commit | 50f47df33a6061e1acd015dbb0dcffcdd51e0f2f (patch) | |
| tree | 568e704c3ff8e8e055573cc44efa4d522b0341f1 /tools | |
| parent | 9e23ded0d195e861ad9ed7d0801ed1c3a0ed34e3 (diff) | |
| parent | 047e09748c91e1d8f80b51edfc33de76fbfc57da (diff) | |
| download | ocaml-50f47df33a6061e1acd015dbb0dcffcdd51e0f2f.tar.gz | |
Sync with trunk. Rebinding of inlined extension constructors with free variables is not yet supported.
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/constructors_with_record3@15069 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/.depend | 14 | ||||
| -rw-r--r-- | tools/Makefile.shared | 8 | ||||
| -rwxr-xr-x | tools/check-typo | 19 | ||||
| -rwxr-xr-x | tools/ci-build | 159 | ||||
| -rw-r--r-- | tools/cmt2annot.ml | 8 | ||||
| -rw-r--r-- | tools/depend.ml | 58 | ||||
| -rw-r--r-- | tools/dumpobj.ml | 8 | ||||
| -rwxr-xr-x | tools/make-version-header.sh | 20 | ||||
| -rw-r--r-- | tools/objinfo.ml | 54 | ||||
| -rw-r--r-- | tools/ocamlcp.ml | 10 | ||||
| -rw-r--r-- | tools/ocamldep.ml | 38 | ||||
| -rw-r--r-- | tools/ocamlmklib.ml | 10 | ||||
| -rw-r--r-- | tools/ocamloptp.ml | 11 | ||||
| -rw-r--r-- | tools/ocamlprof.ml | 15 | ||||
| -rw-r--r-- | tools/profiling.ml | 2 | ||||
| -rw-r--r-- | tools/read_cmt.ml | 11 | ||||
| -rw-r--r-- | tools/tast_iter.ml | 54 | ||||
| -rw-r--r-- | tools/tast_iter.mli | 4 | ||||
| -rw-r--r-- | tools/untypeast.ml | 129 |
19 files changed, 470 insertions, 162 deletions
diff --git a/tools/.depend b/tools/.depend index a058ee37f3..ea66ede860 100644 --- a/tools/.depend +++ b/tools/.depend @@ -28,15 +28,13 @@ depend.cmx : ../parsing/parsetree.cmi ../utils/misc.cmx \ ../parsing/longident.cmx ../parsing/location.cmx ../parsing/asttypes.cmi \ depend.cmi dumpobj.cmo : ../utils/tbl.cmi opnames.cmo ../bytecomp/opcodes.cmo \ - ../utils/misc.cmi ../parsing/location.cmi ../bytecomp/lambda.cmi \ - ../bytecomp/instruct.cmi ../typing/ident.cmi ../utils/config.cmi \ - ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmi \ - ../parsing/asttypes.cmi + ../parsing/location.cmi ../bytecomp/lambda.cmi ../bytecomp/instruct.cmi \ + ../typing/ident.cmi ../utils/config.cmi ../bytecomp/cmo_format.cmi \ + ../bytecomp/bytesections.cmi ../parsing/asttypes.cmi dumpobj.cmx : ../utils/tbl.cmx opnames.cmx ../bytecomp/opcodes.cmx \ - ../utils/misc.cmx ../parsing/location.cmx ../bytecomp/lambda.cmx \ - ../bytecomp/instruct.cmx ../typing/ident.cmx ../utils/config.cmx \ - ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmx \ - ../parsing/asttypes.cmi + ../parsing/location.cmx ../bytecomp/lambda.cmx ../bytecomp/instruct.cmx \ + ../typing/ident.cmx ../utils/config.cmx ../bytecomp/cmo_format.cmi \ + ../bytecomp/bytesections.cmx ../parsing/asttypes.cmi eqparsetree.cmo : ../parsing/parsetree.cmi ../parsing/longident.cmi \ ../parsing/location.cmi ../parsing/asttypes.cmi eqparsetree.cmx : ../parsing/parsetree.cmi ../parsing/longident.cmx \ diff --git a/tools/Makefile.shared b/tools/Makefile.shared index 6b33a5b047..251743449f 100644 --- a/tools/Makefile.shared +++ b/tools/Makefile.shared @@ -13,12 +13,12 @@ include ../config/Makefile CAMLRUN=../boot/ocamlrun -CAMLC=$(CAMLRUN) ../boot/ocamlc -strict-sequence -nostdlib -I ../boot +CAMLC=$(CAMLRUN) ../boot/ocamlc -nostdlib -I ../boot CAMLOPT=$(CAMLRUN) ../ocamlopt -nostdlib -I ../stdlib CAMLLEX=$(CAMLRUN) ../boot/ocamllex INCLUDES=-I ../utils -I ../parsing -I ../typing -I ../bytecomp -I ../asmcomp \ -I ../driver -I ../toplevel -COMPFLAGS= -w +32..39 -warn-error A $(INCLUDES) +COMPFLAGS= -strict-sequence -w +27+32..39 -warn-error A -safe-string $(INCLUDES) LINKFLAGS=$(INCLUDES) all: ocamldep ocamlprof ocamlcp ocamloptp ocamlmktop ocamlmklib dumpobj \ @@ -39,7 +39,7 @@ CAMLDEP_OBJ=depend.cmo ocamldep.cmo CAMLDEP_IMPORTS=misc.cmo config.cmo clflags.cmo terminfo.cmo \ warnings.cmo location.cmo longident.cmo \ syntaxerr.cmo ast_helper.cmo parser.cmo lexer.cmo parse.cmo \ - ccomp.cmo pparse.cmo compenv.cmo + ccomp.cmo ast_mapper.cmo pparse.cmo compenv.cmo ocamldep: depend.cmi $(CAMLDEP_OBJ) $(CAMLC) $(LINKFLAGS) -compat-32 -o ocamldep $(CAMLDEP_IMPORTS) $(CAMLDEP_OBJ) @@ -264,7 +264,7 @@ opnames.ml: ../byterun/instruct.h sed -e '/\/\*/d' \ -e '/^#/d' \ -e 's/enum \(.*\) {/let names_of_\1 = [|/' \ - -e 's/};$$/ |]/' \ + -e 's/.*};$$/ |]/' \ -e 's/\([A-Z][A-Z_0-9a-z]*\)/"\1"/g' \ -e 's/,/;/g' \ ../byterun/instruct.h > opnames.ml diff --git a/tools/check-typo b/tools/check-typo index 93814131e5..ea7c63f775 100755 --- a/tools/check-typo +++ b/tools/check-typo @@ -23,6 +23,7 @@ # - absence of empty lines at end of file (white-at-eof) # - presence of a LF character at the end of the file (missing-lf) # - maximum line length of 80 characters (long-line) +# - maximum line length of 132 characters (very-long-line) # - presence of a copyright header (missing-header) # - absence of a leftover "$Id" string (svn-keyword) @@ -49,6 +50,9 @@ # *.mltop # *.odocl # *.clib +# - Any file whose name matches the following pattern is automatically +# exempt from the "long-line" rule (but not from "very-long-line"). +# */ocamldoc/* # ASCII characters are bytes from 0 to 127. Any other byte is # flagged as a non-ASCII character. @@ -130,14 +134,15 @@ IGNORE_DIRS=" svnrules=`svn propget ocaml:typo "$f"` fi rules="$userrules" + add_hd(){ rules="missing-header,$rules"; } case "$f" in Makefile*|*/Makefile*) rules="tab,$rules";; + */.depend*|*/.ignore) add_hd;; + *.mlpack|*.mllib|*.mltop|*.odocl|*.itarget|*.clib) add_hd;; + *.reference|*/reference) continue;; esac - h(){ rules="missing-header,$rules"; } case "$f" in - */.depend*|*/.ignore) h;; - *.mlpack|*.mllib|*.mltop|*.odocl|*.itarget|*.clib) h;; - *.reference|*/reference) continue;; + ocamldoc/*|*/ocamldoc/*) rules="long-line,$rules";; esac (cat "$f"; echo) \ @@ -182,6 +187,12 @@ IGNORE_DIRS=" err("long-line", "line is over 80 characters"); } + length($0) > 132 { + RSTART = 133; + RLENGTH = 0; + err("very-long-line", "line is over 132 characters"); + } + 3 <= NR && NR <= 5 \ && (/ OCaml / || / ocamlbuild / || / OCamldoc /) { header_ocaml = NR; diff --git a/tools/ci-build b/tools/ci-build new file mode 100755 index 0000000000..4bb2593eb6 --- /dev/null +++ b/tools/ci-build @@ -0,0 +1,159 @@ +#!/bin/sh +######################################################################### +# # +# OCaml # +# # +# Damien Doligez, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2014 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# This script is run on our continuous-integration servers to recompile +# from scratch and run the test suite. + +# arguments: +# 1. architecture: bsd, macos, linux, cygwin, mingw, mingw64, msvc, msvc64 +# 2. directory in which to build (trunk, 4.02, etc) +# for windows, this is relative to $HOME/jenkins-workspace +# for bsd, macos, linux, this is "." or an absolute directory +# 3. options: +# -conf configure-option +# -patch1 file-name apply patch with -p1 + +error () { + echo "$1" >&2 + exit 3 +} + +######################################################################### +# be verbose +set -x + +######################################################################### +# "Parse" mandatory command-line arguments. + +arch="$1" +branch="$2" +shift 2 + +######################################################################### +# If we are called from a Windows batch script, we must set up the +# Unix environment variables (e.g. PATH). + +case "$arch" in + bsd|macos|linux) ;; + cygwin|mingw|mingw64) + . /etc/profile + . "$HOME/.profile" + ;; + msvc) + . /etc/profile + . "$HOME/.profile" + . "$HOME/.msenv32" + ;; + msvc64) + . /etc/profile + . "$HOME/.profile" + . "$HOME/.msenv64" + ;; + *) error "unknown architecture: $arch";; +esac + +######################################################################### + +# be verbose and stop on error +set -ex + +######################################################################### +# set up variables + +# default values +make=make +instdir="$HOME/ocaml-tmp-install" +workdir="$branch" +docheckout=false +nt= + +case "$arch" in + bsd) + make=gmake + ;; + macos) ;; + linux) ;; + cygwin) + workdir="$HOME/jenkins-workspace/$branch" + docheckout=true + ;; + mingw) + instdir=/cygdrive/c/ocamlmgw + workdir="$HOME/jenkins-workspace/$branch" + docheckout=true + nt=.nt + ;; + mingw64) + instdir=/cygdrive/c/ocamlmgw64 + workdir="$HOME/jenkins-workspace/$branch" + docheckout=true + nt=.nt + ;; + msvc) + instdir=/cygdrive/c/ocamlms + workdir="$HOME/jenkins-workspace/$branch" + docheckout=true + nt=.nt + ;; + msvc64) + instdir=/cygdrive/c/ocamlms64 + workdir="$HOME/jenkins-workspace/$branch" + docheckout=true + nt=.nt + ;; + *) error "unknown architecture: $arch";; +esac + +######################################################################### +# Go to the right directory + +cd "$workdir" + +######################################################################### +# parse optional command-line arguments (has to be done after the "cd") +# Configure options are not allowed to have spaces or special characters +# for the moment. We'll fix that when needed. +confoptions="" +while [ $# -gt 0 ]; do + case $1 in + -conf) confoptions="$confoptions $2"; shift 2;; + -patch1) patch -f -p1 <"$2"; shift 2;; + *) error "unknown option $1";; + esac +done + +######################################################################### +# Do the work + +$make -f Makefile$nt distclean || : + +if $docheckout; then + svn update --accept theirs-full +fi + +case $nt in + "") ./configure -prefix "$instdir" $confoptions;; + .nt) + cp config/m-nt.h config/m.h + cp config/s-nt.h config/s.h + cp config/Makefile.$arch config/Makefile + ;; + *) error "internal error";; +esac + +$make -f Makefile$nt world.opt +$make -f Makefile$nt install + +rm -rf "$instdir" +cd testsuite +$make all diff --git a/tools/cmt2annot.ml b/tools/cmt2annot.ml index a7c5a005f0..eee0c79065 100644 --- a/tools/cmt2annot.ml +++ b/tools/cmt2annot.ml @@ -87,8 +87,10 @@ let iterator rebuild_env = bind_bindings exp.exp_loc bindings | Texp_let (Nonrecursive, bindings, body) -> bind_bindings body.exp_loc bindings + | Texp_match (_, f1, f2, _) -> + bind_cases f1; + bind_cases f2 | Texp_function (_, f, _) - | Texp_match (_, f, _) | Texp_try (_, f) -> bind_cases f | _ -> () @@ -154,7 +156,7 @@ let gen_annot target_filename filename match target_filename with | None -> Some (filename ^ ".annot") | Some "-" -> None - | Some filename -> target_filename + | Some _ -> target_filename in let iterator = iterator cmt_use_summaries in match cmt_annots with @@ -187,7 +189,7 @@ let gen_ml target_filename filename cmt = let target_filename = match target_filename with None -> Some (filename ^ ext) | Some "-" -> None - | Some filename -> target_filename + | Some _ -> target_filename in let oc = match target_filename with None -> None diff --git a/tools/depend.ml b/tools/depend.ml index 01d3349c30..b6556c5c93 100644 --- a/tools/depend.ml +++ b/tools/depend.ml @@ -26,12 +26,12 @@ let rec addmodule bv lid = Lident s -> if not (StringSet.mem s bv) then free_structure_names := StringSet.add s !free_structure_names - | Ldot(l, s) -> addmodule bv l + | Ldot(l, _s) -> addmodule bv l | Lapply(l1, l2) -> addmodule bv l1; addmodule bv l2 let add bv lid = match lid.txt with - Ldot(l, s) -> addmodule bv l + Ldot(l, _s) -> addmodule bv l | _ -> () let addmodule bv lid = addmodule bv lid.txt @@ -39,16 +39,16 @@ let addmodule bv lid = addmodule bv lid.txt let rec add_type bv ty = match ty.ptyp_desc with Ptyp_any -> () - | Ptyp_var v -> () + | Ptyp_var _ -> () | Ptyp_arrow(_, t1, t2) -> add_type bv t1; add_type bv t2 | Ptyp_tuple tl -> List.iter (add_type bv) tl | Ptyp_constr(c, tl) -> add bv c; List.iter (add_type bv) tl - | Ptyp_object (fl, _) -> List.iter (fun (_, t) -> add_type bv t) fl + | Ptyp_object (fl, _) -> List.iter (fun (_, _, t) -> add_type bv t) fl | Ptyp_class(c, tl) -> add bv c; List.iter (add_type bv) tl - | Ptyp_alias(t, s) -> add_type bv t + | Ptyp_alias(t, _) -> add_type bv t | Ptyp_variant(fl, _, _) -> List.iter - (function Rtag(_,_,stl) -> List.iter (add_type bv) stl + (function Rtag(_,_,_,stl) -> List.iter (add_type bv) stl | Rinherit sty -> add_type bv sty) fl | Ptyp_poly(_, t) -> add_type bv t @@ -63,11 +63,12 @@ let add_opt add_fn bv = function None -> () | Some x -> add_fn bv x -let add_constructor_decl bv pcd = - begin match pcd.pcd_args with +let add_constructor_arguments bv = function | Pcstr_tuple l -> List.iter (add_type bv) l | Pcstr_record l -> List.iter (fun l -> add_type bv l.pld_type) l - end; + +let add_constructor_decl bv pcd = + add_constructor_arguments bv pcd.pcd_args; Misc.may (add_type bv) pcd.pcd_res let add_type_declaration bv td = @@ -80,9 +81,21 @@ let add_type_declaration bv td = | Ptype_variant cstrs -> List.iter (add_constructor_decl bv) cstrs | Ptype_record lbls -> - List.iter (fun pld -> add_type bv pld.pld_type) lbls in + List.iter (fun pld -> add_type bv pld.pld_type) lbls + | Ptype_open -> () in add_tkind td.ptype_kind +let add_extension_constructor bv ext = + match ext.pext_kind with + Pext_decl(args, rty) -> + add_constructor_arguments bv args; + Misc.may (add_type bv) rty + | Pext_rebind lid -> add bv lid + +let add_type_extension bv te = + add bv te.ptyext_path; + List.iter (add_extension_constructor bv) te.ptyext_constructors + let rec add_class_type bv cty = match cty.pcty_desc with Pcty_constr(l, tyl) -> @@ -100,6 +113,7 @@ and add_class_type_field bv pctf = | Pctf_val(_, _, _, ty) -> add_type bv ty | Pctf_method(_, _, _, ty) -> add_type bv ty | Pctf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2 + | Pctf_attribute _ -> () | Pctf_extension _ -> () let add_class_description bv infos = @@ -127,6 +141,7 @@ let rec add_pattern bv pat = | Ppat_type li -> add bv li | Ppat_lazy p -> add_pattern bv p | Ppat_unpack id -> pattern_bv := StringSet.add id.txt !pattern_bv + | Ppat_exception p -> add_pattern bv p | Ppat_extension _ -> () let add_pattern bv pat = @@ -170,10 +185,10 @@ let rec add_expr bv exp = | Pexp_constraint(e1, ty2) -> add_expr bv e1; add_type bv ty2 - | Pexp_send(e, m) -> add_expr bv e + | Pexp_send(e, _m) -> add_expr bv e | Pexp_new li -> add bv li - | Pexp_setinstvar(v, e) -> add_expr bv e - | Pexp_override sel -> List.iter (fun (s, e) -> add_expr bv e) sel + | Pexp_setinstvar(_v, e) -> add_expr bv e + | Pexp_override sel -> List.iter (fun (_s, e) -> add_expr bv e) sel | Pexp_letmodule(id, m, e) -> add_module bv m; add_expr (StringSet.add id.txt bv) e | Pexp_assert (e) -> add_expr bv e @@ -231,8 +246,10 @@ and add_sig_item bv item = add_type bv vd.pval_type; bv | Psig_type dcls -> List.iter (add_type_declaration bv) dcls; bv - | Psig_exception pcd -> - add_constructor_decl bv pcd; bv + | Psig_typext te -> + add_type_extension bv te; bv + | Psig_exception pext -> + add_extension_constructor bv pext; bv | Psig_module pmd -> add_modtype bv pmd.pmd_type; StringSet.add pmd.pmd_name.txt bv | Psig_recmodule decls -> @@ -288,10 +305,11 @@ and add_struct_item bv item = add_type bv vd.pval_type; bv | Pstr_type dcls -> List.iter (add_type_declaration bv) dcls; bv - | Pstr_exception pcd -> - add_constructor_decl bv pcd; bv - | Pstr_exn_rebind er -> - add bv er.pexrb_lid; bv + | Pstr_typext te -> + add_type_extension bv te; + bv + | Pstr_exception pext -> + add_extension_constructor bv pext; bv | Pstr_module x -> add_module bv x.pmb_expr; StringSet.add x.pmb_name.txt bv | Pstr_recmodule bindings -> @@ -355,7 +373,7 @@ and add_class_field bv pcf = | Pcf_method(_, _, Cfk_virtual ty) -> add_type bv ty | Pcf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2 | Pcf_initializer e -> add_expr bv e - | Pcf_extension _ -> () + | Pcf_attribute _ | Pcf_extension _ -> () and add_class_declaration bv decl = add_class_expr bv decl.pci_expr diff --git a/tools/dumpobj.ml b/tools/dumpobj.ml index f1255e9cd2..d95c210da4 100644 --- a/tools/dumpobj.ml +++ b/tools/dumpobj.ml @@ -481,8 +481,8 @@ let print_reloc (info, pos) = (* Print a .cmo file *) -let dump_obj filename ic = - let buffer = Misc.input_bytes ic (String.length cmo_magic_number) in +let dump_obj ic = + let buffer = really_input_string ic (String.length cmo_magic_number) in if buffer <> cmo_magic_number then begin prerr_endline "Not an object file"; exit 2 end; @@ -502,7 +502,7 @@ let dump_obj filename ic = (* Read the primitive table from an executable *) let read_primitive_table ic len = - let p = Misc.input_bytes ic len in + let p = really_input_string ic len in let rec split beg cur = if cur >= len then [] else if p.[cur] = '\000' then @@ -557,7 +557,7 @@ let arg_fun filename = begin try objfile := false; dump_exe ic with Bytesections.Bad_magic_number -> - objfile := true; seek_in ic 0; dump_obj filename ic + objfile := true; seek_in ic 0; dump_obj ic end; close_in ic; printf "## end of ocaml dump of %S\n%!" filename diff --git a/tools/make-version-header.sh b/tools/make-version-header.sh index b5e69be956..26c5c14280 100755 --- a/tools/make-version-header.sh +++ b/tools/make-version-header.sh @@ -13,9 +13,6 @@ # # ######################################################################### -# For maximal compatibility with older versions, we Use "ocamlc -v" -# instead of "ocamlc -vnum" or the VERSION file in .../lib/ocaml/. - # This script extracts the components from an OCaml version number # and provides them as C defines: # OCAML_VERSION_MAJOR: the major version number @@ -26,7 +23,18 @@ # Note that additional-info is always absent in officially-released # versions of OCaml. -version="`ocamlc -v | sed -n -e 's/.*version //p'`" +# usage: +# make-version-header.sh [version-file] +# The argument is the VERSION file from the OCaml sources. +# If the argument is not given, the version number from "ocamlc -v" will +# be used. + +case $# in + 0) version="`ocamlc -v | sed -n -e 's/.*version //p'`";; + 1) version="`sed -e 1q $1`";; + *) echo "usage: make-version-header.sh [version-file]" >&2 + exit 2;; +esac major="`echo "$version" | sed -n -e '1s/^\([0-9]*\)\..*/\1/p'`" minor="`echo "$version" | sed -n -e '1s/^[0-9]*\.\([0-9]*\).*/\1/p'`" @@ -34,10 +42,12 @@ patchlvl="`echo "$version" | sed -n -e '1s/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/p'`" suffix="`echo "$version" | sed -n -e '1s/^[^+]*+\(.*\)/\1/p'`" echo "#define OCAML_VERSION_MAJOR $major" -echo "#define OCAML_VERSION_MINOR $minor" +printf "#define OCAML_VERSION_MINOR %d\n" $minor case $patchlvl in "") patchlvl=0;; esac echo "#define OCAML_VERSION_PATCHLEVEL $patchlvl" case "$suffix" in "") echo "#undef OCAML_VERSION_ADDITIONAL";; *) echo "#define OCAML_VERSION_ADDITIONAL \"$suffix\"";; esac +printf "#define OCAML_VERSION %d%02d%02d\n" $major $minor $patchlvl +echo "#define OCAML_VERSION_STRING \"$version\"" diff --git a/tools/objinfo.ml b/tools/objinfo.ml index 6f3ec75665..37a03b3427 100644 --- a/tools/objinfo.ml +++ b/tools/objinfo.ml @@ -31,11 +31,18 @@ let input_stringlist ic len = else acc in fold 0 0 [] in - let sect = Misc.input_bytes ic len in + let sect = really_input_string ic len in get_string_list sect len -let print_name_crc (name, crc) = - printf "\t%s\t%s\n" (Digest.to_hex crc) name +let dummy_crc = String.make 32 '-' + +let print_name_crc (name, crco) = + let crc = + match crco with + None -> dummy_crc + | Some crc -> Digest.to_hex crc + in + printf "\t%s\t%s\n" crc name let print_line name = printf "\t%s\n" name @@ -69,11 +76,28 @@ let print_cma_infos (lib : Cmo_format.library) = printf "\n"; List.iter print_cmo_infos lib.lib_units -let print_cmi_infos name sign crcs = +let print_cmi_infos name crcs = printf "Unit name: %s\n" name; printf "Interfaces imported:\n"; List.iter print_name_crc crcs +let print_cmt_infos cmt = + let open Cmt_format in + printf "Cmt unit name: %s\n" cmt.cmt_modname; + print_string "Cmt interfaces imported:\n"; + List.iter print_name_crc cmt.cmt_imports; + printf "Source file: %s\n" + (match cmt.cmt_sourcefile with None -> "(none)" | Some f -> f); + printf "Compilation flags:"; + Array.iter print_spaced_string cmt.cmt_args; + printf "\nLoad path:"; + List.iter print_spaced_string cmt.cmt_loadpath; + printf "\n"; + printf "cmt interface digest: %s\n" + (match cmt.cmt_interface_digest with + | None -> "" + | Some crc -> Digest.to_hex crc) + let print_general_infos name crc defines cmi cmx = printf "Name: %s\n" name; printf "CRC of implementation: %s\n" (Digest.to_hex crc); @@ -143,7 +167,7 @@ let dump_byte ic = | "CRCS" -> p_section "Imported units" - (input_value ic : (string * Digest.t) list) + (input_value ic : (string * Digest.t option) list) | "DLLS" -> p_list "Used DLLs" @@ -189,7 +213,7 @@ let dump_obj filename = printf "File %s\n" filename; let ic = open_in_bin filename in let len_magic_number = String.length cmo_magic_number in - let magic_number = Misc.input_bytes ic len_magic_number in + let magic_number = really_input_string ic len_magic_number in if magic_number = cmo_magic_number then begin let cu_pos = input_binary_int ic in seek_in ic cu_pos; @@ -202,11 +226,19 @@ let dump_obj filename = let toc = (input_value ic : library) in close_in ic; print_cma_infos toc - end else if magic_number = cmi_magic_number then begin - let cmi = Cmi_format.input_cmi ic in + end else if magic_number = cmi_magic_number || + magic_number = cmt_magic_number then begin close_in ic; - print_cmi_infos cmi.Cmi_format.cmi_name cmi.Cmi_format.cmi_sign - cmi.Cmi_format.cmi_crcs + let cmi, cmt = Cmt_format.read filename in + begin match cmi with + | None -> () + | Some cmi -> + print_cmi_infos cmi.Cmi_format.cmi_name cmi.Cmi_format.cmi_crcs + end; + begin match cmt with + | None -> () + | Some cmt -> print_cmt_infos cmt + end end else if magic_number = cmx_magic_number then begin let ui = (input_value ic : unit_infos) in let crc = Digest.input ic in @@ -219,7 +251,7 @@ let dump_obj filename = end else begin let pos_trailer = in_channel_length ic - len_magic_number in let _ = seek_in ic pos_trailer in - let _ = really_input ic magic_number 0 len_magic_number in + let magic_number = really_input_string ic len_magic_number in if magic_number = Config.exec_magic_number then begin dump_byte ic; close_in ic diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml index bca5ae63c5..75adcb82ef 100644 --- a/tools/ocamlcp.ml +++ b/tools/ocamlcp.ml @@ -54,6 +54,7 @@ module Options = Main_args.Make_bytecomp_options (struct let _dllib = option_with_arg "-dllib" let _dllpath = option_with_arg "-dllpath" let _dtypes = option "-dtypes" + let _for_pack = option_with_arg "-for-pack" let _g = option "-g" let _i = option "-i" let _I s = option_with_arg "-I" s @@ -64,25 +65,28 @@ module Options = Main_args.Make_bytecomp_options (struct let _labels = option "-labels" let _linkall = option "-linkall" let _make_runtime = option "-make-runtime" + let _no_alias_deps = option "-no-alias-deps" let _no_app_funct = option "-no-app-funct" let _noassert = option "-noassert" let _nolabels = option "-nolabels" let _noautolink = option "-noautolink" let _nostdlib = option "-nostdlib" let _o s = option_with_arg "-o" s + let _open s = option_with_arg "-open" s let _output_obj = option "-output-obj" let _pack = option "-pack" - let _pp s = incompatible "-pp" - let _ppx s = incompatible "-ppx" + let _pp _s = incompatible "-pp" + let _ppx _s = incompatible "-ppx" let _principal = option "-principal" let _rectypes = option "-rectypes" let _runtime_variant s = option_with_arg "-runtime-variant" s + let _safe_string = option "-safe-string" let _short_paths = option "-short-paths" let _strict_sequence = option "-strict-sequence" - let _trans_mod = option "-trans-mod" let _thread () = option "-thread" () let _vmthread () = option "-vmthread" () let _unsafe = option "-unsafe" + let _unsafe_string = option "-unsafe-string" let _use_prims s = option_with_arg "-use-prims" s let _use_runtime s = option_with_arg "-use-runtime" s let _v = option "-v" diff --git a/tools/ocamldep.ml b/tools/ocamldep.ml index 735a5f97b5..59fecc412c 100644 --- a/tools/ocamldep.ml +++ b/tools/ocamldep.ml @@ -18,7 +18,6 @@ let ppf = Format.err_formatter type file_kind = ML | MLI;; -let include_dirs = ref [] let load_path = ref ([] : (string * string array) list) let ml_synonyms = ref [".ml"] let mli_synonyms = ref [".mli"] @@ -35,11 +34,7 @@ let files = ref [] let fix_slash s = if Sys.os_type = "Unix" then s else begin - let r = String.copy s in - for i = 0 to String.length r - 1 do - if r.[i] = '\\' then r.[i] <- '/' - done; - r + String.map (function '\\' -> '/' | c -> c) s end (* Since we reinitialize load_path after reading OCAMLCOMP, @@ -160,20 +155,20 @@ let print_filename s = else count n (i+1) in let spaces = count 0 0 in - let result = String.create (String.length s + spaces) in + let result = Bytes.create (String.length s + spaces) in let rec loop i j = if i >= String.length s then () else if s.[i] = ' ' then begin - result.[j] <- '\\'; - result.[j+1] <- ' '; + Bytes.set result j '\\'; + Bytes.set result (j+1) ' '; loop (i+1) (j+2); end else begin - result.[j] <- s.[i]; + Bytes.set result j s.[i]; loop (i+1) (j+1); end in loop 0 0; - print_string result; + print_bytes result; end ;; @@ -205,7 +200,7 @@ let print_raw_dependencies source_file deps = (* Process one file *) -let report_err source_file exn = +let report_err exn = error_occurred := true; match exn with | Sys_error msg -> @@ -217,13 +212,15 @@ let report_err source_file exn = Location.report_error err | None -> raise x +let tool_name = "ocamldep" + let read_parse_and_extract parse_function extract_function magic source_file = Depend.free_structure_names := Depend.StringSet.empty; try let input_file = Pparse.preprocess source_file in begin try let ast = - Pparse.file Format.err_formatter input_file parse_function magic in + Pparse.file ~tool_name Format.err_formatter input_file parse_function magic in extract_function Depend.StringSet.empty ast; Pparse.remove_preprocessed input_file; !Depend.free_structure_names @@ -232,7 +229,7 @@ let read_parse_and_extract parse_function extract_function magic source_file = raise x end with x -> - report_err source_file x; + report_err x; Depend.StringSet.empty let ml_file_dependencies source_file = @@ -288,7 +285,7 @@ let mli_file_dependencies source_file = print_raw_dependencies source_file extracted_deps end else begin let basename = Filename.chop_extension source_file in - let (byt_deps, opt_deps) = + let (byt_deps, _opt_deps) = Depend.StringSet.fold (find_dependency MLI) extracted_deps ([], []) in print_dependencies [basename ^ ".cmi"] byt_deps @@ -299,7 +296,7 @@ let file_dependencies_as kind source_file = load_path := []; List.iter add_to_load_path ( (!Compenv.last_include_dirs @ - !include_dirs @ + !Clflags.include_dirs @ !Compenv.first_include_dirs )); Location.input_name := source_file; @@ -309,7 +306,7 @@ let file_dependencies_as kind source_file = | ML -> ml_file_dependencies source_file | MLI -> mli_file_dependencies source_file end - with x -> report_err source_file x + with x -> report_err x let file_dependencies source_file = if List.exists (Filename.check_suffix source_file) !ml_synonyms then @@ -324,8 +321,9 @@ let sort_files_by_dependencies files = (* Init Hashtbl with all defined modules *) let files = List.map (fun (file, file_kind, deps) -> - let modname = Filename.chop_extension (Filename.basename file) in - modname.[0] <- Char.uppercase modname.[0]; + let modname = + String.capitalize (Filename.chop_extension (Filename.basename file)) + in let key = (modname, file_kind) in let new_deps = ref [] in Hashtbl.add h key (file, new_deps); @@ -414,7 +412,7 @@ let _ = " Show absolute filenames in error messages"; "-all", Arg.Set all_dependencies, " Generate dependencies on all files"; - "-I", Arg.String (fun s -> include_dirs := s :: !include_dirs), + "-I", Arg.String (fun s -> Clflags.include_dirs := s :: !Clflags.include_dirs), "<dir> Add <dir> to the list of include directories"; "-impl", Arg.String (file_dependencies_as ML), "<f> Process <f> as a .ml file"; diff --git a/tools/ocamlmklib.ml b/tools/ocamlmklib.ml index 0ef86979b9..77ae57becb 100644 --- a/tools/ocamlmklib.ml +++ b/tools/ocamlmklib.ml @@ -215,10 +215,14 @@ let prepostfix pre name post = let transl_path s = match Sys.os_type with | "Win32" -> + let s = Bytes.of_string s in let rec aux i = - if i = String.length s || s.[i] = ' ' then s - else (if s.[i] = '/' then s.[i] <- '\\'; aux (i + 1)) - in aux 0 + if i = Bytes.length s || Bytes.get s i = ' ' then s + else begin + if Bytes.get s i = '/' then Bytes.set s i '\\'; + aux (i + 1) + end + in Bytes.to_string (aux 0) | _ -> s let build_libs () = diff --git a/tools/ocamloptp.ml b/tools/ocamloptp.ml index 6d730f2c3c..178f7c2d25 100644 --- a/tools/ocamloptp.ml +++ b/tools/ocamloptp.ml @@ -64,28 +64,32 @@ module Options = Main_args.Make_optcomp_options (struct let _keep_locs = option "-keep-locs" let _labels = option "-labels" let _linkall = option "-linkall" + let _no_alias_deps = option "-no-alias-deps" let _no_app_funct = option "-no-app-funct" + let _no_float_const_prop = option "-no-float-const-prop" let _noassert = option "-noassert" let _noautolink = option "-noautolink" let _nodynlink = option "-nodynlink" let _nolabels = option "-nolabels" let _nostdlib = option "-nostdlib" let _o s = option_with_arg "-o" s + let _open s = option_with_arg "-open" s let _output_obj = option "-output-obj" let _p = option "-p" let _pack = option "-pack" - let _pp s = incompatible "-pp" - let _ppx s = incompatible "-ppx" + let _pp _s = incompatible "-pp" + let _ppx _s = incompatible "-ppx" let _principal = option "-principal" let _rectypes = option "-rectypes" let _runtime_variant s = option_with_arg "-runtime-variant" s let _S = option "-S" + let _safe_string = option "-safe-string" let _short_paths = option "-short-paths" let _strict_sequence = option "-strict-sequence" let _shared = option "-shared" let _thread = option "-thread" - let _trans_mod = option "-trans-mod" let _unsafe = option "-unsafe" + let _unsafe_string = option "-unsafe-string" let _v = option "-v" let _version = option "-version" let _vnum = option "-vnum" @@ -105,6 +109,7 @@ module Options = Main_args.Make_optcomp_options (struct let _dcmm = option "-dcmm" let _dsel = option "-dsel" let _dcombine = option "-dcombine" + let _dcse = option "-dcse" let _dlive = option "-dlive" let _dspill = option "-dspill" let _dsplit = option "-dsplit" diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml index 1fde3fe495..9c2bb489dd 100644 --- a/tools/ocamlprof.ml +++ b/tools/ocamlprof.ml @@ -35,7 +35,7 @@ and inchan = ref stdin and outchan = ref stdout (* To copy source fragments *) -let copy_buffer = String.create 256 +let copy_buffer = Bytes.create 256 let copy_chars_unix nchars = let n = ref nchars in @@ -173,8 +173,8 @@ and rewrite_exp iflag sexp = and rw_exp iflag sexp = match sexp.pexp_desc with - Pexp_ident lid -> () - | Pexp_constant cst -> () + Pexp_ident _lid -> () + | Pexp_constant _cst -> () | Pexp_let(_, spat_sexp_list, sbody) -> rewrite_patexp_list iflag spat_sexp_list; @@ -314,7 +314,7 @@ and rewrite_annotate_exp_list l = l and rewrite_function iflag = function - | [{pc_lhs=spat; pc_guard=None; + | [{pc_lhs=_; pc_guard=None; pc_rhs={pexp_desc = (Pexp_function _|Pexp_fun _)} as sexp}] -> rewrite_exp iflag sexp | l -> rewrite_funmatching l @@ -344,6 +344,7 @@ and rewrite_class_field iflag cf = | Pcf_method (_, _, Cfk_virtual _) | Pcf_val (_, _, Cfk_virtual _) | Pcf_constraint _ -> () + | Pcf_attribute _ -> () | Pcf_extension _ -> () and rewrite_class_expr iflag cexpr = @@ -370,11 +371,11 @@ and rewrite_class_declaration iflag cl = and rewrite_mod iflag smod = match smod.pmod_desc with - Pmod_ident lid -> () + Pmod_ident _ -> () | Pmod_structure sstr -> List.iter (rewrite_str_item iflag) sstr - | Pmod_functor(param, smty, sbody) -> rewrite_mod iflag sbody + | Pmod_functor(_param, _smty, sbody) -> rewrite_mod iflag sbody | Pmod_apply(smod1, smod2) -> rewrite_mod iflag smod1; rewrite_mod iflag smod2 - | Pmod_constraint(smod, smty) -> rewrite_mod iflag smod + | Pmod_constraint(smod, _smty) -> rewrite_mod iflag smod | Pmod_unpack(sexp) -> rewrite_exp iflag sexp | Pmod_extension _ -> () diff --git a/tools/profiling.ml b/tools/profiling.ml index 5dae8e4614..49a84108ec 100644 --- a/tools/profiling.ml +++ b/tools/profiling.ml @@ -37,7 +37,7 @@ let dump_counters () = then raise Bad_profile) !counters prevl; List.iter2 - (fun (curname, (_,curcount)) (prevname, (_,prevcount)) -> + (fun (_curname, (_,curcount)) (_prevname, (_,prevcount)) -> for i = 0 to Array.length curcount - 1 do curcount.(i) <- curcount.(i) + prevcount.(i) done) diff --git a/tools/read_cmt.ml b/tools/read_cmt.ml index 0ff9f3df77..eacba02a50 100644 --- a/tools/read_cmt.ml +++ b/tools/read_cmt.ml @@ -27,6 +27,8 @@ let arg_list = [ let arg_usage = "read_cmt [OPTIONS] FILE.cmt : read FILE.cmt and print related information" +let dummy_crc = String.make 32 '-' + let print_info cmt = let open Cmt_format in Printf.printf "module name: %s\n" cmt.cmt_modname; @@ -60,8 +62,13 @@ let print_info cmt = | Some digest -> Printf.printf "interface digest: %s\n" (Digest.to_hex digest); end; - List.iter (fun (name, digest) -> - Printf.printf "import: %s %s\n" name (Digest.to_hex digest); + List.iter (fun (name, crco) -> + let crc = + match crco with + None -> dummy_crc + | Some crc -> Digest.to_hex crc + in + Printf.printf "import: %s %s\n" name crc; ) (List.sort compare cmt.cmt_imports); Printf.printf "%!"; () diff --git a/tools/tast_iter.ml b/tools/tast_iter.ml index f640ccaf79..be5b854419 100644 --- a/tools/tast_iter.ml +++ b/tools/tast_iter.ml @@ -17,21 +17,14 @@ let opt f = function None -> () | Some x -> f x let structure sub str = List.iter (sub # structure_item) str.str_items -let constructor_decl sub cd = - begin match cd.cd_args with - | Cstr_tuple l -> List.iter (sub # core_type) l - | Cstr_record l -> List.iter (fun ld -> sub # core_type ld.ld_type) l - end; - opt (sub # core_type) cd.cd_res - let structure_item sub x = match x.str_desc with | Tstr_eval (exp, _attrs) -> sub # expression exp | Tstr_value (rec_flag, list) -> sub # bindings (rec_flag, list) | Tstr_primitive v -> sub # value_description v | Tstr_type list -> List.iter (sub # type_declaration) list - | Tstr_exception decl -> constructor_decl sub decl - | Tstr_exn_rebind _ -> () + | Tstr_typext te -> sub # type_extension te + | Tstr_exception ext -> sub # extension_constructor ext | Tstr_module mb -> sub # module_binding mb | Tstr_recmodule list -> List.iter (sub # module_binding) list | Tstr_modtype mtd -> opt (sub # module_type) mtd.mtd_type @@ -46,6 +39,17 @@ let structure_item sub x = let value_description sub x = sub # core_type x.val_desc +let constructor_args sub = function + | Cstr_tuple l -> List.iter (sub # core_type) l + | Cstr_record l -> List.iter (fun ld -> sub # core_type ld.ld_type) l + +let constructor_decl sub cd = + constructor_args sub cd.cd_args; + opt (sub # core_type) cd.cd_res + +let label_decl sub ld = + sub # core_type ld.ld_type + let type_declaration sub decl = List.iter (fun (ct1, ct2, _loc) -> sub # core_type ct1; sub # core_type ct2) @@ -55,10 +59,21 @@ let type_declaration sub decl = | Ttype_variant list -> List.iter (constructor_decl sub) list | Ttype_record list -> - List.iter (fun ld -> sub # core_type ld.ld_type) list + List.iter (label_decl sub) list + | Ttype_open -> () end; opt (sub # core_type) decl.typ_manifest +let type_extension sub te = + List.iter (sub # extension_constructor) te.tyext_constructors + +let extension_constructor sub ext = + match ext.ext_kind with + Text_decl(ctl, cto) -> + constructor_args sub ctl; + opt (sub # core_type) cto + | Text_rebind _ -> () + let pattern sub pat = let extra = function | Tpat_type _ @@ -101,9 +116,10 @@ let expression sub exp = | Texp_apply (exp, list) -> sub # expression exp; List.iter (fun (_, expo, _) -> opt (sub # expression) expo) list - | Texp_match (exp, cases, _) -> + | Texp_match (exp, cases, exn_cases, _) -> sub # expression exp; - sub # cases cases + sub # cases cases; + sub # cases exn_cases | Texp_try (exp, cases) -> sub # expression exp; sub # cases cases @@ -169,8 +185,10 @@ let signature_item sub item = sub # value_description v | Tsig_type list -> List.iter (sub # type_declaration) list - | Tsig_exception decl -> - constructor_decl sub decl + | Tsig_typext te -> + sub # type_extension te + | Tsig_exception ext -> + sub # extension_constructor ext | Tsig_module md -> sub # module_type md.md_type | Tsig_recmodule list -> @@ -277,6 +295,7 @@ let class_type_field sub ctf = | Tctf_constraint (ct1, ct2) -> sub # core_type ct1; sub # core_type ct2 + | Tctf_attribute _ -> () let core_type sub ct = match ct.ctyp_desc with @@ -289,7 +308,7 @@ let core_type sub ct = | Ttyp_constr (_path, _, list) -> List.iter (sub # core_type) list | Ttyp_object (list, _o) -> - List.iter (fun (_, t) -> sub # core_type t) list + List.iter (fun (_, _, t) -> sub # core_type t) list | Ttyp_class (_path, _, list) -> List.iter (sub # core_type) list | Ttyp_alias (ct, _s) -> @@ -305,7 +324,7 @@ let class_structure sub cs = let row_field sub rf = match rf with - | Ttag (_label, _bool, list) -> List.iter (sub # core_type) list + | Ttag (_label, _attrs, _bool, list) -> List.iter (sub # core_type) list | Tinherit ct -> sub # core_type ct let class_field sub cf = @@ -325,6 +344,7 @@ let class_field sub cf = sub # expression exp | Tcf_initializer exp -> sub # expression exp + | Tcf_attribute _ -> () let bindings sub (_rec_flag, list) = List.iter (sub # binding) list @@ -356,6 +376,7 @@ class iter = object(this) method class_type_field = class_type_field this method core_type = core_type this method expression = expression this + method extension_constructor = extension_constructor this method module_binding = module_binding this method module_expr = module_expr this method module_type = module_type this @@ -367,6 +388,7 @@ class iter = object(this) method structure = structure this method structure_item = structure_item this method type_declaration = type_declaration this + method type_extension = type_extension this method value_description = value_description this method with_constraint = with_constraint this end diff --git a/tools/tast_iter.mli b/tools/tast_iter.mli index f80609566b..1d81afa568 100644 --- a/tools/tast_iter.mli +++ b/tools/tast_iter.mli @@ -28,6 +28,7 @@ class iter: object method class_type_field: class_type_field -> unit method core_type: core_type -> unit method expression: expression -> unit + method extension_constructor: extension_constructor -> unit method module_binding: module_binding -> unit method module_expr: module_expr -> unit method module_type: module_type -> unit @@ -39,6 +40,7 @@ class iter: object method structure: structure -> unit method structure_item: structure_item -> unit method type_declaration: type_declaration -> unit + method type_extension: type_extension -> unit method value_description: value_description -> unit method with_constraint: with_constraint -> unit end @@ -63,6 +65,7 @@ val class_type_declaration: iter -> class_type_declaration -> unit val class_type_field: iter -> class_type_field -> unit val core_type: iter -> core_type -> unit val expression: iter -> expression -> unit +val extension_constructor: iter -> extension_constructor -> unit val module_binding: iter -> module_binding -> unit val module_expr: iter -> module_expr -> unit val module_type: iter -> module_type -> unit @@ -74,5 +77,6 @@ val signature_item: iter -> signature_item -> unit val structure: iter -> structure -> unit val structure_item: iter -> structure_item -> unit val type_declaration: iter -> type_declaration -> unit +val type_extension: iter -> type_extension -> unit val value_description: iter -> value_description -> unit val with_constraint: iter -> with_constraint -> unit diff --git a/tools/untypeast.ml b/tools/untypeast.ml index c6c7b3bc9e..b59443c595 100644 --- a/tools/untypeast.ml +++ b/tools/untypeast.ml @@ -53,10 +53,10 @@ and untype_structure_item item = Pstr_primitive (untype_value_description vd) | Tstr_type list -> Pstr_type (List.map untype_type_declaration list) - | Tstr_exception decl -> - Pstr_exception (untype_constructor_declaration decl) - | Tstr_exn_rebind er -> - Pstr_exn_rebind (untype_exception_rebind er) + | Tstr_typext tyext -> + Pstr_typext (untype_type_extension tyext) + | Tstr_exception ext -> + Pstr_exception (untype_extension_constructor ext) | Tstr_module mb -> Pstr_module (untype_module_binding mb) | Tstr_recmodule list -> @@ -71,26 +71,15 @@ and untype_structure_item item = popen_loc = od.open_loc; } | Tstr_class list -> - Pstr_class (List.map (fun (ci, _, _) -> - { pci_virt = ci.ci_virt; - pci_params = ci.ci_params; - pci_name = ci.ci_id_name; - pci_expr = untype_class_expr ci.ci_expr; - pci_loc = ci.ci_loc; - pci_attributes = ci.ci_attributes; - } - ) list) + Pstr_class + (List.map + (fun (ci, _, _) -> untype_class_declaration ci) + list) | Tstr_class_type list -> - Pstr_class_type (List.map (fun (_id, _name, ct) -> - { - pci_virt = ct.ci_virt; - pci_params = ct.ci_params; - pci_name = ct.ci_id_name; - pci_expr = untype_class_type ct.ci_expr; - pci_loc = ct.ci_loc; - pci_attributes = ct.ci_attributes; - } - ) list) + Pstr_class_type + (List.map + (fun (_id, _name, ct) -> untype_class_type_declaration ct) + list) | Tstr_include incl -> Pstr_include {pincl_mod = untype_module_expr incl.incl_mod; pincl_attributes = incl.incl_attributes; @@ -121,7 +110,7 @@ and untype_module_binding mb = and untype_type_declaration decl = { ptype_name = decl.typ_name; - ptype_params = decl.typ_params; + ptype_params = List.map untype_type_parameter decl.typ_params; ptype_cstrs = List.map (fun (ct1, ct2, loc) -> (untype_core_type ct1, untype_core_type ct2, loc) @@ -132,6 +121,7 @@ and untype_type_declaration decl = Ptype_variant (List.map untype_constructor_declaration list) | Ttype_record list -> Ptype_record (List.map untype_label_declaration list) + | Ttype_open -> Ptype_open ); ptype_private = decl.typ_private; ptype_manifest = option untype_core_type decl.typ_manifest; @@ -139,33 +129,51 @@ and untype_type_declaration decl = ptype_loc = decl.typ_loc; } +and untype_type_parameter (ct, v) = (untype_core_type ct, v) + +and untype_constructor_arguments = function + | Cstr_tuple l -> Pcstr_tuple (List.map untype_core_type l) + | Cstr_record l -> Pcstr_record (List.map untype_label_declaration l) + +and untype_constructor_declaration cd = + { + pcd_name = cd.cd_name; + pcd_args = untype_constructor_arguments cd.cd_args; + pcd_res = option untype_core_type cd.cd_res; + pcd_loc = cd.cd_loc; + pcd_attributes = cd.cd_attributes; + } + and untype_label_declaration ld = { pld_name=ld.ld_name; pld_mutable=ld.ld_mutable; pld_type=untype_core_type ld.ld_type; pld_loc=ld.ld_loc; - pld_attributes=ld.ld_attributes; + pld_attributes=ld.ld_attributes } -and untype_constructor_declaration cd = +and untype_type_extension tyext = { - pcd_name = cd.cd_name; - pcd_args = begin match cd.cd_args with - | Cstr_tuple l -> Pcstr_tuple (List.map untype_core_type l) - | Cstr_record l -> Pcstr_record (List.map untype_label_declaration l) - end; - pcd_res = option untype_core_type cd.cd_res; - pcd_loc = cd.cd_loc; - pcd_attributes = cd.cd_attributes; + ptyext_path = tyext.tyext_txt; + ptyext_params = List.map untype_type_parameter tyext.tyext_params; + ptyext_constructors = + List.map untype_extension_constructor tyext.tyext_constructors; + ptyext_private = tyext.tyext_private; + ptyext_attributes = tyext.tyext_attributes; } -and untype_exception_rebind er = +and untype_extension_constructor ext = { - pexrb_name = er.exrb_name; - pexrb_lid = er.exrb_txt; - pexrb_attributes = er.exrb_attributes; - pexrb_loc = er.exrb_loc; + pext_name = ext.ext_name; + pext_kind = (match ext.ext_kind with + Text_decl (args, ret) -> + Pext_decl (untype_constructor_arguments args, + option untype_core_type ret) + | Text_rebind (_p, lid) -> Pext_rebind lid + ); + pext_loc = ext.ext_loc; + pext_attributes = ext.ext_attributes; } and untype_pattern pat = @@ -270,8 +278,18 @@ and untype_expression exp = None -> list | Some exp -> (label, untype_expression exp) :: list ) list []) - | Texp_match (exp, cases, _) -> - Pexp_match (untype_expression exp, untype_cases cases) + | Texp_match (exp, cases, exn_cases, _) -> + let merged_cases = untype_cases cases + @ List.map + (fun c -> + let uc = untype_case c in + let pat = { uc.pc_lhs + with ppat_desc = Ppat_exception uc.pc_lhs } + in + { uc with pc_lhs = pat }) + exn_cases + in + Pexp_match (untype_expression exp, merged_cases) | Texp_try (exp, cases) -> Pexp_try (untype_expression exp, untype_cases cases) | Texp_tuple list -> @@ -352,8 +370,10 @@ and untype_signature_item item = Psig_value (untype_value_description v) | Tsig_type list -> Psig_type (List.map untype_type_declaration list) - | Tsig_exception decl -> - Psig_exception (untype_constructor_declaration decl) + | Tsig_typext tyext -> + Psig_typext (untype_type_extension tyext) + | Tsig_exception ext -> + Psig_exception (untype_extension_constructor ext) | Tsig_module md -> Psig_module {pmd_name = md.md_name; pmd_type = untype_module_type md.md_type; @@ -389,10 +409,20 @@ and untype_signature_item item = psig_loc = item.sig_loc; } +and untype_class_declaration cd = + { + pci_virt = cd.ci_virt; + pci_params = List.map untype_type_parameter cd.ci_params; + pci_name = cd.ci_id_name; + pci_expr = untype_class_expr cd.ci_expr; + pci_loc = cd.ci_loc; + pci_attributes = cd.ci_attributes; + } + and untype_class_description cd = { pci_virt = cd.ci_virt; - pci_params = cd.ci_params; + pci_params = List.map untype_type_parameter cd.ci_params; pci_name = cd.ci_id_name; pci_expr = untype_class_type cd.ci_expr; pci_loc = cd.ci_loc; @@ -402,7 +432,7 @@ and untype_class_description cd = and untype_class_type_declaration cd = { pci_virt = cd.ci_virt; - pci_params = cd.ci_params; + pci_params = List.map untype_type_parameter cd.ci_params; pci_name = cd.ci_id_name; pci_expr = untype_class_type cd.ci_expr; pci_loc = cd.ci_loc; @@ -523,6 +553,7 @@ and untype_class_type_field ctf = Pctf_method (s, priv, virt, untype_core_type ct) | Tctf_constraint (ct1, ct2) -> Pctf_constraint (untype_core_type ct1, untype_core_type ct2) + | Tctf_attribute x -> Pctf_attribute x in { pctf_desc = desc; @@ -541,7 +572,8 @@ and untype_core_type ct = Ptyp_constr (lid, List.map untype_core_type list) | Ttyp_object (list, o) -> - Ptyp_object (List.map (fun (s, t) -> (s, untype_core_type t)) list, o) + Ptyp_object + (List.map (fun (s, a, t) -> (s, a, untype_core_type t)) list, o) | Ttyp_class (_path, lid, list) -> Ptyp_class (lid, List.map untype_core_type list) | Ttyp_alias (ct, s) -> @@ -560,8 +592,8 @@ and untype_class_structure cs = and untype_row_field rf = match rf with - Ttag (label, bool, list) -> - Rtag (label, bool, List.map untype_core_type list) + Ttag (label, attrs, bool, list) -> + Rtag (label, attrs, bool, List.map untype_core_type list) | Tinherit ct -> Rinherit (untype_core_type ct) and untype_class_field cf = @@ -579,5 +611,6 @@ and untype_class_field cf = | Tcf_method (lab, priv, Tcfk_concrete (o, exp)) -> Pcf_method (lab, priv, Cfk_concrete (o, untype_expression exp)) | Tcf_initializer exp -> Pcf_initializer (untype_expression exp) + | Tcf_attribute x -> Pcf_attribute x in { pcf_desc = desc; pcf_loc = cf.cf_loc; pcf_attributes = cf.cf_attributes } |
