summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.depend157
-rw-r--r--Makefile6
-rw-r--r--Makefile.nt7
-rw-r--r--VERSION2
-rwxr-xr-xboot/myocamlbuild.bootbin423220 -> 426590 bytes
-rwxr-xr-xboot/ocamlcbin1183851 -> 1213059 bytes
-rwxr-xr-xboot/ocamldepbin321773 -> 327728 bytes
-rwxr-xr-xboot/ocamllexbin175330 -> 175616 bytes
-rw-r--r--build/camlp4-bootstrap-recipe.txt3
-rw-r--r--bytecomp/matching.ml84
-rw-r--r--bytecomp/translclass.ml122
-rw-r--r--bytecomp/translclass.mli2
-rw-r--r--bytecomp/translcore.ml88
-rw-r--r--bytecomp/translcore.mli3
-rw-r--r--bytecomp/translmod.ml186
-rw-r--r--camlp4/Camlp4/Printers/OCaml.ml8
-rw-r--r--camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml276
-rw-r--r--camlp4/Camlp4/Struct/Token.ml2
-rw-r--r--camlp4/boot/Camlp4.ml452
-rw-r--r--camlp4/boot/Camlp4Ast.ml7
-rw-r--r--camlp4/boot/camlp4boot.ml271
-rw-r--r--debugger/.depend6
-rw-r--r--debugger/Makefile.shared6
-rw-r--r--debugger/command_line.ml4
-rw-r--r--debugger/envaux.ml2
-rw-r--r--debugger/eval.ml2
-rw-r--r--debugger/main.ml5
-rw-r--r--debugger/program_management.ml4
-rw-r--r--debugger/source.ml17
-rw-r--r--debugger/unix_tools.ml1
-rw-r--r--driver/compile.ml22
-rw-r--r--driver/errors.ml3
-rw-r--r--driver/main.ml1
-rw-r--r--driver/main_args.ml8
-rw-r--r--driver/main_args.mli2
-rw-r--r--driver/optcompile.ml21
-rw-r--r--driver/opterrors.ml3
-rw-r--r--driver/optmain.ml1
-rw-r--r--myocamlbuild_config.mli1
-rw-r--r--ocamldoc/Makefile2
-rw-r--r--ocamldoc/Makefile.nt1
-rw-r--r--ocamldoc/odoc_analyse.ml12
-rw-r--r--ocamldoc/odoc_ast.ml301
-rw-r--r--ocamldoc/odoc_ast.mli10
-rw-r--r--ocamldoc/odoc_env.ml42
-rw-r--r--ocamldoc/odoc_module.ml2
-rw-r--r--ocamldoc/odoc_print.ml20
-rw-r--r--ocamldoc/odoc_sig.ml189
-rw-r--r--ocamldoc/odoc_sig.mli2
-rw-r--r--ocamldoc/odoc_str.ml6
-rw-r--r--ocamldoc/odoc_text_parser.mly13
-rw-r--r--otherlibs/dynlink/Makefile2
-rw-r--r--otherlibs/dynlink/dynlink.ml8
-rw-r--r--otherlibs/dynlink/dynlinkaux.mlpack4
-rw-r--r--otherlibs/labltk/browser/.depend334
-rw-r--r--otherlibs/labltk/browser/Makefile.shared2
-rw-r--r--otherlibs/labltk/browser/editor.ml2
-rw-r--r--otherlibs/labltk/browser/mytypes.mli2
-rw-r--r--otherlibs/labltk/browser/searchid.ml79
-rw-r--r--otherlibs/labltk/browser/searchpos.ml187
-rw-r--r--otherlibs/labltk/browser/typecheck.ml7
-rw-r--r--otherlibs/labltk/browser/viewer.ml32
-rw-r--r--parsing/asttypes.mli5
-rw-r--r--parsing/lexer.mli11
-rw-r--r--parsing/lexer.mll109
-rw-r--r--parsing/location.ml8
-rw-r--r--parsing/location.mli12
-rw-r--r--parsing/parse.ml9
-rw-r--r--parsing/parser.mly340
-rw-r--r--parsing/parsetree.mli150
-rw-r--r--parsing/printast.ml118
-rw-r--r--testsuite/tests/asmcomp/Makefile2
-rw-r--r--testsuite/tests/typing-gadts/Makefile5
-rw-r--r--testsuite/tests/typing-objects/Tests.ml.principal.reference8
-rw-r--r--testsuite/tests/typing-objects/Tests.ml.reference8
-rw-r--r--tools/.depend131
-rw-r--r--tools/.ignore1
-rw-r--r--tools/Makefile.shared50
-rw-r--r--tools/addlabels.ml54
-rw-r--r--tools/depend.ml65
-rw-r--r--tools/dumpobj.ml49
-rw-r--r--tools/objinfo.ml15
-rw-r--r--tools/ocamlcp.ml1
-rw-r--r--tools/ocamlprof.ml21
-rw-r--r--toplevel/genprintval.ml16
-rw-r--r--toplevel/toplevellib.mllib8
-rw-r--r--toplevel/toploop.ml20
-rw-r--r--typing/btype.ml6
-rw-r--r--typing/ctype.ml173
-rw-r--r--typing/ctype.mli2
-rw-r--r--typing/datarepr.ml2
-rw-r--r--typing/datarepr.mli12
-rw-r--r--typing/env.ml359
-rw-r--r--typing/env.mli75
-rw-r--r--typing/ident.mli2
-rw-r--r--typing/includeclass.mli2
-rw-r--r--typing/includecore.ml38
-rw-r--r--typing/includecore.mli12
-rw-r--r--typing/includemod.ml82
-rw-r--r--typing/includemod.mli4
-rw-r--r--typing/mtype.ml126
-rw-r--r--typing/parmatch.ml434
-rw-r--r--typing/parmatch.mli13
-rw-r--r--typing/predef.ml82
-rw-r--r--typing/predef.mli1
-rw-r--r--typing/printtyp.ml47
-rw-r--r--typing/printtyp.mli6
-rw-r--r--typing/stypes.ml5
-rw-r--r--typing/stypes.mli2
-rw-r--r--typing/subst.ml76
-rw-r--r--typing/subst.mli2
-rw-r--r--typing/typeclass.ml481
-rw-r--r--typing/typeclass.mli53
-rw-r--r--typing/typecore.ml636
-rw-r--r--typing/typecore.mli12
-rw-r--r--typing/typedecl.ml350
-rw-r--r--typing/typedecl.mli22
-rw-r--r--typing/typedtree.ml365
-rw-r--r--typing/typedtree.mli324
-rw-r--r--typing/typemod.ml692
-rw-r--r--typing/typemod.mli15
-rw-r--r--typing/types.ml36
-rw-r--r--typing/types.mli36
-rw-r--r--typing/typetexp.ml186
-rw-r--r--typing/typetexp.mli18
-rw-r--r--utils/clflags.ml1
-rw-r--r--utils/clflags.mli2
-rw-r--r--utils/config.mlbuild7
-rw-r--r--utils/config.mli2
-rw-r--r--utils/config.mlp7
-rw-r--r--utils/misc.ml20
-rw-r--r--utils/misc.mli13
132 files changed, 5465 insertions, 3636 deletions
diff --git a/.depend b/.depend
index 5bc0cc325..ecb0f90e2 100644
--- a/.depend
+++ b/.depend
@@ -24,12 +24,13 @@ utils/terminfo.cmo : utils/terminfo.cmi
utils/terminfo.cmx : utils/terminfo.cmi
utils/warnings.cmo : utils/warnings.cmi
utils/warnings.cmx : utils/warnings.cmi
-parsing/asttypes.cmi :
+parsing/asttypes.cmi : parsing/location.cmi
parsing/lexer.cmi : parsing/parser.cmi parsing/location.cmi
parsing/location.cmi : utils/warnings.cmi
parsing/longident.cmi :
parsing/parse.cmi : parsing/parsetree.cmi
-parsing/parser.cmi : parsing/parsetree.cmi
+parsing/parser.cmi : parsing/parsetree.cmi parsing/longident.cmi \
+ parsing/location.cmi
parsing/parsetree.cmi : parsing/longident.cmi parsing/location.cmi \
parsing/asttypes.cmi
parsing/printast.cmi : parsing/parsetree.cmi
@@ -64,15 +65,20 @@ parsing/syntaxerr.cmo : parsing/location.cmi parsing/syntaxerr.cmi
parsing/syntaxerr.cmx : parsing/location.cmx parsing/syntaxerr.cmi
typing/annot.cmi : parsing/location.cmi
typing/btype.cmi : typing/types.cmi typing/path.cmi parsing/asttypes.cmi
+typing/cmi_format.cmi : typing/types.cmi
+typing/cmt_format.cmi : typing/types.cmi typing/typedtree.cmi \
+ parsing/location.cmi typing/env.cmi typing/cmi_format.cmi
typing/ctype.cmi : typing/types.cmi typing/path.cmi parsing/longident.cmi \
typing/ident.cmi typing/env.cmi parsing/asttypes.cmi
-typing/datarepr.cmi : typing/types.cmi typing/path.cmi parsing/asttypes.cmi
-typing/env.cmi : utils/warnings.cmi typing/types.cmi typing/path.cmi \
- parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
- utils/consistbl.cmi typing/annot.cmi
+typing/datarepr.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi \
+ parsing/asttypes.cmi
+typing/env.cmi : utils/warnings.cmi typing/types.cmi utils/tbl.cmi \
+ typing/subst.cmi typing/path.cmi parsing/longident.cmi \
+ parsing/location.cmi typing/ident.cmi utils/consistbl.cmi \
+ typing/btype.cmi typing/annot.cmi
+typing/ident.cmti.cmi :
typing/ident.cmi :
-typing/includeclass.cmi : typing/types.cmi typing/typedtree.cmi \
- typing/env.cmi typing/ctype.cmi
+typing/includeclass.cmi : typing/types.cmi typing/env.cmi typing/ctype.cmi
typing/includecore.cmi : typing/types.cmi typing/typedtree.cmi \
typing/ident.cmi typing/env.cmi
typing/includemod.cmi : typing/types.cmi typing/typedtree.cmi \
@@ -82,13 +88,15 @@ typing/mtype.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi \
typing/env.cmi
typing/oprint.cmi : typing/outcometree.cmi
typing/outcometree.cmi : parsing/asttypes.cmi
-typing/parmatch.cmi : typing/types.cmi typing/typedtree.cmi \
- parsing/parsetree.cmi parsing/location.cmi typing/env.cmi
+typing/parmatch.cmi : typing/types.cmi typing/typedtree.cmi typing/path.cmi \
+ parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
+ typing/env.cmi parsing/asttypes.cmi
typing/path.cmi : typing/ident.cmi
typing/predef.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi
typing/primitive.cmi :
typing/printtyp.cmi : typing/types.cmi typing/path.cmi \
typing/outcometree.cmi parsing/longident.cmi typing/ident.cmi
+typing/printtyped.cmi : typing/typedtree.cmi
typing/stypes.cmi : typing/typedtree.cmi parsing/location.cmi \
typing/annot.cmi
typing/subst.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi
@@ -98,23 +106,36 @@ typing/typeclass.cmi : typing/types.cmi typing/typedtree.cmi \
typing/typecore.cmi : typing/types.cmi typing/typedtree.cmi typing/path.cmi \
parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
typing/ident.cmi typing/env.cmi parsing/asttypes.cmi typing/annot.cmi
-typing/typedecl.cmi : typing/types.cmi typing/path.cmi parsing/parsetree.cmi \
- parsing/longident.cmi parsing/location.cmi typing/includecore.cmi \
- typing/ident.cmi typing/env.cmi
+typing/typedecl.cmi : typing/types.cmi typing/typedtree.cmi typing/path.cmi \
+ parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
+ typing/includecore.cmi typing/ident.cmi typing/env.cmi \
+ parsing/asttypes.cmi
typing/typedtree.cmi : typing/types.cmi typing/primitive.cmi typing/path.cmi \
- parsing/location.cmi typing/ident.cmi typing/env.cmi parsing/asttypes.cmi
+ parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
+ typing/env.cmi parsing/asttypes.cmi
typing/typemod.cmi : typing/types.cmi typing/typedtree.cmi \
parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
typing/includemod.cmi typing/ident.cmi typing/env.cmi
typing/types.cmi : typing/primitive.cmi typing/path.cmi \
parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
parsing/asttypes.cmi
-typing/typetexp.cmi : typing/types.cmi typing/path.cmi parsing/parsetree.cmi \
- parsing/longident.cmi parsing/location.cmi typing/env.cmi
+typing/typetexp.cmi : typing/types.cmi typing/typedtree.cmi typing/path.cmi \
+ parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
+ typing/env.cmi parsing/asttypes.cmi
typing/btype.cmo : typing/types.cmi typing/path.cmi utils/misc.cmi \
typing/btype.cmi
typing/btype.cmx : typing/types.cmx typing/path.cmx utils/misc.cmx \
typing/btype.cmi
+typing/cmi_format.cmo : typing/types.cmi utils/misc.cmi parsing/location.cmi \
+ utils/config.cmi typing/cmi_format.cmi
+typing/cmi_format.cmx : typing/types.cmx utils/misc.cmx parsing/location.cmx \
+ utils/config.cmx typing/cmi_format.cmi
+typing/cmt_format.cmo : typing/types.cmi typing/typedtree.cmi utils/misc.cmi \
+ parsing/location.cmi parsing/lexer.cmi typing/env.cmi utils/config.cmi \
+ typing/cmi_format.cmi utils/clflags.cmi typing/cmt_format.cmi
+typing/cmt_format.cmx : typing/types.cmx typing/typedtree.cmx utils/misc.cmx \
+ parsing/location.cmx parsing/lexer.cmx typing/env.cmx utils/config.cmx \
+ typing/cmi_format.cmx utils/clflags.cmx typing/cmt_format.cmi
typing/ctype.cmo : typing/types.cmi typing/subst.cmi typing/path.cmi \
utils/misc.cmi parsing/longident.cmi parsing/location.cmi \
typing/ident.cmi typing/env.cmi utils/clflags.cmi typing/btype.cmi \
@@ -124,21 +145,25 @@ typing/ctype.cmx : typing/types.cmx typing/subst.cmx typing/path.cmx \
typing/ident.cmx typing/env.cmx utils/clflags.cmx typing/btype.cmx \
parsing/asttypes.cmi typing/ctype.cmi
typing/datarepr.cmo : typing/types.cmi typing/predef.cmi utils/misc.cmi \
- typing/btype.cmi parsing/asttypes.cmi typing/datarepr.cmi
+ typing/ident.cmi typing/btype.cmi parsing/asttypes.cmi \
+ typing/datarepr.cmi
typing/datarepr.cmx : typing/types.cmx typing/predef.cmx utils/misc.cmx \
- typing/btype.cmx parsing/asttypes.cmi typing/datarepr.cmi
+ typing/ident.cmx typing/btype.cmx parsing/asttypes.cmi \
+ typing/datarepr.cmi
typing/env.cmo : utils/warnings.cmi typing/types.cmi utils/tbl.cmi \
typing/subst.cmi typing/predef.cmi typing/path.cmi utils/misc.cmi \
parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
typing/datarepr.cmi utils/consistbl.cmi utils/config.cmi \
- utils/clflags.cmi typing/btype.cmi parsing/asttypes.cmi typing/annot.cmi \
- typing/env.cmi
+ typing/cmi_format.cmi utils/clflags.cmi typing/btype.cmi \
+ parsing/asttypes.cmi typing/annot.cmi typing/env.cmi
typing/env.cmx : utils/warnings.cmx typing/types.cmx utils/tbl.cmx \
typing/subst.cmx typing/predef.cmx typing/path.cmx utils/misc.cmx \
parsing/longident.cmx parsing/location.cmx typing/ident.cmx \
typing/datarepr.cmx utils/consistbl.cmx utils/config.cmx \
- utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi typing/annot.cmi \
- typing/env.cmi
+ typing/cmi_format.cmx utils/clflags.cmx typing/btype.cmx \
+ parsing/asttypes.cmi typing/annot.cmi typing/env.cmi
+typing/ident.cmt.cmo :
+typing/ident.cmt.cmx :
typing/ident.cmo : typing/ident.cmi
typing/ident.cmx : typing/ident.cmi
typing/includeclass.cmo : typing/types.cmi typing/printtyp.cmi \
@@ -203,6 +228,12 @@ typing/printtyp.cmx : typing/types.cmx typing/primitive.cmx \
typing/oprint.cmx utils/misc.cmx parsing/longident.cmx typing/ident.cmx \
typing/env.cmx typing/ctype.cmx utils/clflags.cmx typing/btype.cmx \
parsing/asttypes.cmi typing/printtyp.cmi
+typing/printtyped.cmo : typing/typedtree.cmi typing/path.cmi \
+ parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
+ parsing/asttypes.cmi typing/printtyped.cmi
+typing/printtyped.cmx : typing/typedtree.cmx typing/path.cmx \
+ parsing/longident.cmx parsing/location.cmx typing/ident.cmx \
+ parsing/asttypes.cmi typing/printtyped.cmi
typing/stypes.cmo : typing/typedtree.cmi typing/printtyp.cmi \
parsing/location.cmi utils/clflags.cmi typing/annot.cmi typing/stypes.cmi
typing/stypes.cmx : typing/typedtree.cmx typing/printtyp.cmx \
@@ -219,32 +250,34 @@ typing/typeclass.cmo : utils/warnings.cmi typing/typetexp.cmi \
typing/printtyp.cmi typing/predef.cmi typing/path.cmi \
parsing/parsetree.cmi typing/parmatch.cmi utils/misc.cmi \
parsing/longident.cmi parsing/location.cmi typing/includeclass.cmi \
- typing/ident.cmi typing/env.cmi typing/ctype.cmi utils/clflags.cmi \
- typing/btype.cmi parsing/asttypes.cmi typing/typeclass.cmi
+ typing/ident.cmi typing/env.cmi typing/ctype.cmi typing/cmt_format.cmi \
+ utils/clflags.cmi typing/btype.cmi parsing/asttypes.cmi \
+ typing/typeclass.cmi
typing/typeclass.cmx : utils/warnings.cmx typing/typetexp.cmx \
typing/types.cmx typing/typedtree.cmx typing/typedecl.cmx \
typing/typecore.cmx typing/subst.cmx typing/stypes.cmx \
typing/printtyp.cmx typing/predef.cmx typing/path.cmx \
parsing/parsetree.cmi typing/parmatch.cmx utils/misc.cmx \
parsing/longident.cmx parsing/location.cmx typing/includeclass.cmx \
- typing/ident.cmx typing/env.cmx typing/ctype.cmx utils/clflags.cmx \
- typing/btype.cmx parsing/asttypes.cmi typing/typeclass.cmi
+ typing/ident.cmx typing/env.cmx typing/ctype.cmx typing/cmt_format.cmx \
+ utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi \
+ typing/typeclass.cmi
typing/typecore.cmo : utils/warnings.cmi typing/typetexp.cmi \
typing/types.cmi typing/typedtree.cmi typing/subst.cmi typing/stypes.cmi \
typing/printtyp.cmi typing/primitive.cmi typing/predef.cmi \
typing/path.cmi parsing/parsetree.cmi typing/parmatch.cmi \
typing/oprint.cmi utils/misc.cmi parsing/longident.cmi \
parsing/location.cmi typing/ident.cmi typing/env.cmi typing/ctype.cmi \
- utils/clflags.cmi typing/btype.cmi parsing/asttypes.cmi typing/annot.cmi \
- typing/typecore.cmi
+ typing/cmt_format.cmi utils/clflags.cmi typing/btype.cmi \
+ parsing/asttypes.cmi typing/annot.cmi typing/typecore.cmi
typing/typecore.cmx : utils/warnings.cmx typing/typetexp.cmx \
typing/types.cmx typing/typedtree.cmx typing/subst.cmx typing/stypes.cmx \
typing/printtyp.cmx typing/primitive.cmx typing/predef.cmx \
typing/path.cmx parsing/parsetree.cmi typing/parmatch.cmx \
typing/oprint.cmx utils/misc.cmx parsing/longident.cmx \
parsing/location.cmx typing/ident.cmx typing/env.cmx typing/ctype.cmx \
- utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi typing/annot.cmi \
- typing/typecore.cmi
+ typing/cmt_format.cmx utils/clflags.cmx typing/btype.cmx \
+ parsing/asttypes.cmi typing/annot.cmi typing/typecore.cmi
typing/typedecl.cmo : utils/warnings.cmi typing/typetexp.cmi \
typing/types.cmi typing/typedtree.cmi typing/subst.cmi \
typing/printtyp.cmi typing/primitive.cmi typing/predef.cmi \
@@ -262,43 +295,45 @@ typing/typedecl.cmx : utils/warnings.cmx typing/typetexp.cmx \
utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi \
typing/typedecl.cmi
typing/typedtree.cmo : typing/types.cmi typing/primitive.cmi typing/path.cmi \
- utils/misc.cmi parsing/location.cmi typing/ident.cmi typing/env.cmi \
- parsing/asttypes.cmi typing/typedtree.cmi
+ utils/misc.cmi parsing/longident.cmi parsing/location.cmi \
+ typing/ident.cmi typing/env.cmi parsing/asttypes.cmi typing/typedtree.cmi
typing/typedtree.cmx : typing/types.cmx typing/primitive.cmx typing/path.cmx \
- utils/misc.cmx parsing/location.cmx typing/ident.cmx typing/env.cmx \
- parsing/asttypes.cmi typing/typedtree.cmi
+ utils/misc.cmx parsing/longident.cmx parsing/location.cmx \
+ typing/ident.cmx typing/env.cmx parsing/asttypes.cmi typing/typedtree.cmi
typing/typemod.cmo : utils/warnings.cmi typing/typetexp.cmi typing/types.cmi \
typing/typedtree.cmi typing/typedecl.cmi typing/typecore.cmi \
typing/typeclass.cmi typing/subst.cmi typing/stypes.cmi \
typing/printtyp.cmi typing/path.cmi parsing/parsetree.cmi \
typing/mtype.cmi utils/misc.cmi parsing/longident.cmi \
parsing/location.cmi typing/includemod.cmi typing/ident.cmi \
- typing/env.cmi typing/ctype.cmi utils/config.cmi utils/clflags.cmi \
- typing/btype.cmi parsing/asttypes.cmi typing/annot.cmi typing/typemod.cmi
+ typing/env.cmi typing/ctype.cmi utils/config.cmi typing/cmt_format.cmi \
+ utils/clflags.cmi typing/btype.cmi parsing/asttypes.cmi typing/annot.cmi \
+ typing/typemod.cmi
typing/typemod.cmx : utils/warnings.cmx typing/typetexp.cmx typing/types.cmx \
typing/typedtree.cmx typing/typedecl.cmx typing/typecore.cmx \
typing/typeclass.cmx typing/subst.cmx typing/stypes.cmx \
typing/printtyp.cmx typing/path.cmx parsing/parsetree.cmi \
typing/mtype.cmx utils/misc.cmx parsing/longident.cmx \
parsing/location.cmx typing/includemod.cmx typing/ident.cmx \
- typing/env.cmx typing/ctype.cmx utils/config.cmx utils/clflags.cmx \
- typing/btype.cmx parsing/asttypes.cmi typing/annot.cmi typing/typemod.cmi
+ typing/env.cmx typing/ctype.cmx utils/config.cmx typing/cmt_format.cmx \
+ utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi typing/annot.cmi \
+ typing/typemod.cmi
typing/types.cmo : typing/primitive.cmi typing/path.cmi utils/misc.cmi \
parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
parsing/asttypes.cmi typing/types.cmi
typing/types.cmx : typing/primitive.cmx typing/path.cmx utils/misc.cmx \
parsing/longident.cmx parsing/location.cmx typing/ident.cmx \
parsing/asttypes.cmi typing/types.cmi
-typing/typetexp.cmo : utils/warnings.cmi typing/types.cmi utils/tbl.cmi \
- typing/printtyp.cmi typing/path.cmi parsing/parsetree.cmi utils/misc.cmi \
- parsing/longident.cmi parsing/location.cmi typing/env.cmi \
- typing/ctype.cmi utils/clflags.cmi typing/btype.cmi parsing/asttypes.cmi \
- typing/typetexp.cmi
-typing/typetexp.cmx : utils/warnings.cmx typing/types.cmx utils/tbl.cmx \
- typing/printtyp.cmx typing/path.cmx parsing/parsetree.cmi utils/misc.cmx \
- parsing/longident.cmx parsing/location.cmx typing/env.cmx \
- typing/ctype.cmx utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi \
- typing/typetexp.cmi
+typing/typetexp.cmo : utils/warnings.cmi typing/types.cmi \
+ typing/typedtree.cmi utils/tbl.cmi typing/printtyp.cmi typing/path.cmi \
+ parsing/parsetree.cmi utils/misc.cmi parsing/longident.cmi \
+ parsing/location.cmi typing/env.cmi typing/ctype.cmi utils/clflags.cmi \
+ typing/btype.cmi parsing/asttypes.cmi typing/typetexp.cmi
+typing/typetexp.cmx : utils/warnings.cmx typing/types.cmx \
+ typing/typedtree.cmx utils/tbl.cmx typing/printtyp.cmx typing/path.cmx \
+ parsing/parsetree.cmi utils/misc.cmx parsing/longident.cmx \
+ parsing/location.cmx typing/env.cmx typing/ctype.cmx utils/clflags.cmx \
+ typing/btype.cmx parsing/asttypes.cmi typing/typetexp.cmi
bytecomp/bytegen.cmi : bytecomp/lambda.cmi bytecomp/instruct.cmi
bytecomp/bytelibrarian.cmi :
bytecomp/bytelink.cmi : bytecomp/symtable.cmi bytecomp/cmo_format.cmi
@@ -457,15 +492,17 @@ bytecomp/translclass.cmx : typing/types.cmx bytecomp/typeopt.cmx \
bytecomp/translcore.cmo : typing/types.cmi bytecomp/typeopt.cmi \
typing/typedtree.cmi bytecomp/translobj.cmi typing/primitive.cmi \
typing/predef.cmi typing/path.cmi typing/parmatch.cmi utils/misc.cmi \
- bytecomp/matching.cmi parsing/location.cmi bytecomp/lambda.cmi \
- typing/ident.cmi typing/env.cmi utils/config.cmi utils/clflags.cmi \
- typing/btype.cmi parsing/asttypes.cmi bytecomp/translcore.cmi
+ bytecomp/matching.cmi parsing/longident.cmi parsing/location.cmi \
+ bytecomp/lambda.cmi typing/ident.cmi typing/env.cmi utils/config.cmi \
+ utils/clflags.cmi typing/btype.cmi parsing/asttypes.cmi \
+ bytecomp/translcore.cmi
bytecomp/translcore.cmx : typing/types.cmx bytecomp/typeopt.cmx \
typing/typedtree.cmx bytecomp/translobj.cmx typing/primitive.cmx \
typing/predef.cmx typing/path.cmx typing/parmatch.cmx utils/misc.cmx \
- bytecomp/matching.cmx parsing/location.cmx bytecomp/lambda.cmx \
- typing/ident.cmx typing/env.cmx utils/config.cmx utils/clflags.cmx \
- typing/btype.cmx parsing/asttypes.cmi bytecomp/translcore.cmi
+ bytecomp/matching.cmx parsing/longident.cmx parsing/location.cmx \
+ bytecomp/lambda.cmx typing/ident.cmx typing/env.cmx utils/config.cmx \
+ utils/clflags.cmx typing/btype.cmx parsing/asttypes.cmi \
+ bytecomp/translcore.cmi
bytecomp/translmod.cmo : typing/types.cmi typing/typedtree.cmi \
bytecomp/translobj.cmi bytecomp/translcore.cmi bytecomp/translclass.cmi \
typing/printtyp.cmi typing/primitive.cmi typing/predef.cmi \
@@ -766,7 +803,7 @@ driver/errors.cmo : utils/warnings.cmi typing/typetexp.cmi \
bytecomp/translclass.cmi parsing/syntaxerr.cmi bytecomp/symtable.cmi \
driver/pparse.cmi parsing/location.cmi parsing/lexer.cmi \
typing/includemod.cmi typing/env.cmi typing/ctype.cmi \
- bytecomp/bytepackager.cmi bytecomp/bytelink.cmi \
+ typing/cmi_format.cmi bytecomp/bytepackager.cmi bytecomp/bytelink.cmi \
bytecomp/bytelibrarian.cmi driver/errors.cmi
driver/errors.cmx : utils/warnings.cmx typing/typetexp.cmx \
typing/typemod.cmx typing/typedecl.cmx typing/typecore.cmx \
@@ -774,7 +811,7 @@ driver/errors.cmx : utils/warnings.cmx typing/typetexp.cmx \
bytecomp/translclass.cmx parsing/syntaxerr.cmx bytecomp/symtable.cmx \
driver/pparse.cmx parsing/location.cmx parsing/lexer.cmx \
typing/includemod.cmx typing/env.cmx typing/ctype.cmx \
- bytecomp/bytepackager.cmx bytecomp/bytelink.cmx \
+ typing/cmi_format.cmx bytecomp/bytepackager.cmx bytecomp/bytelink.cmx \
bytecomp/bytelibrarian.cmx driver/errors.cmi
driver/main.cmo : utils/warnings.cmi utils/misc.cmi driver/main_args.cmi \
parsing/location.cmi driver/errors.cmi utils/config.cmi \
@@ -806,16 +843,16 @@ driver/opterrors.cmo : utils/warnings.cmi typing/typetexp.cmi \
bytecomp/translclass.cmi parsing/syntaxerr.cmi driver/pparse.cmi \
parsing/location.cmi parsing/lexer.cmi typing/includemod.cmi \
typing/env.cmi typing/ctype.cmi asmcomp/compilenv.cmi \
- asmcomp/asmpackager.cmi asmcomp/asmlink.cmi asmcomp/asmlibrarian.cmi \
- asmcomp/asmgen.cmi driver/opterrors.cmi
+ typing/cmi_format.cmi asmcomp/asmpackager.cmi asmcomp/asmlink.cmi \
+ asmcomp/asmlibrarian.cmi asmcomp/asmgen.cmi driver/opterrors.cmi
driver/opterrors.cmx : utils/warnings.cmx typing/typetexp.cmx \
typing/typemod.cmx typing/typedecl.cmx typing/typecore.cmx \
typing/typeclass.cmx bytecomp/translmod.cmx bytecomp/translcore.cmx \
bytecomp/translclass.cmx parsing/syntaxerr.cmx driver/pparse.cmx \
parsing/location.cmx parsing/lexer.cmx typing/includemod.cmx \
typing/env.cmx typing/ctype.cmx asmcomp/compilenv.cmx \
- asmcomp/asmpackager.cmx asmcomp/asmlink.cmx asmcomp/asmlibrarian.cmx \
- asmcomp/asmgen.cmx driver/opterrors.cmi
+ typing/cmi_format.cmx asmcomp/asmpackager.cmx asmcomp/asmlink.cmx \
+ asmcomp/asmlibrarian.cmx asmcomp/asmgen.cmx driver/opterrors.cmi
driver/optmain.cmo : utils/warnings.cmi asmcomp/printmach.cmi \
driver/opterrors.cmi driver/optcompile.cmi utils/misc.cmi \
driver/main_args.cmi parsing/location.cmi utils/config.cmi \
diff --git a/Makefile b/Makefile
index 62942552e..b6d9fcd4f 100644
--- a/Makefile
+++ b/Makefile
@@ -49,12 +49,12 @@ TYPING=typing/ident.cmo typing/path.cmo \
typing/primitive.cmo typing/types.cmo \
typing/btype.cmo typing/oprint.cmo \
typing/subst.cmo typing/predef.cmo \
- typing/datarepr.cmo typing/env.cmo \
- typing/typedtree.cmo typing/ctype.cmo \
+ typing/datarepr.cmo typing/cmi_format.cmo typing/env.cmo \
+ typing/typedtree.cmo typing/printtyped.cmo typing/ctype.cmo \
typing/printtyp.cmo typing/includeclass.cmo \
typing/mtype.cmo typing/includecore.cmo \
typing/includemod.cmo typing/typetexp.cmo typing/parmatch.cmo \
- typing/stypes.cmo typing/typecore.cmo \
+ typing/cmt_format.cmo typing/stypes.cmo typing/typecore.cmo \
typing/typedecl.cmo typing/typeclass.cmo \
typing/typemod.cmo
diff --git a/Makefile.nt b/Makefile.nt
index 91ac026e0..0582377c1 100644
--- a/Makefile.nt
+++ b/Makefile.nt
@@ -46,12 +46,13 @@ TYPING=typing/ident.cmo typing/path.cmo \
typing/primitive.cmo typing/types.cmo \
typing/btype.cmo typing/oprint.cmo \
typing/subst.cmo typing/predef.cmo \
- typing/datarepr.cmo typing/env.cmo \
+ typing/datarepr.cmo typing/cmi_format.cmo typing/env.cmo \
typing/typedtree.cmo typing/ctype.cmo \
typing/printtyp.cmo typing/includeclass.cmo \
typing/mtype.cmo typing/includecore.cmo \
typing/includemod.cmo typing/parmatch.cmo \
- typing/typetexp.cmo typing/stypes.cmo typing/typecore.cmo \
+ typing/typetexp.cmo \
+ typing/cmt_format.cmo typing/stypes.cmo typing/typecore.cmo \
typing/typedecl.cmo typing/typeclass.cmo \
typing/typemod.cmo
@@ -103,7 +104,7 @@ defaultentry:
# Recompile the system using the bootstrap compiler
all: runtime ocamlc ocamllex ocamlyacc ocamltools library ocaml \
- otherlibraries ocamldoc.byte ocamlbuild.byte $(CAMLP4OUT) $(DEBUGGER)
+ otherlibraries ocamldoc.byte ocamlbuild.byte $(CAMLP4OUT) $(DEBUGGER)
# The compilation of ocaml will fail if the runtime has changed.
# Never mind, just do make bootstrap to reach fixpoint again.
diff --git a/VERSION b/VERSION
index 5662682c6..c02c194aa 100644
--- a/VERSION
+++ b/VERSION
@@ -1,4 +1,4 @@
-4.01.0+dev2_2012-04-17
+4.01.0+dev3_2012-05-30
# The version string is the first line of this file.
# It must be in the format described in stdlib/sys.mli
diff --git a/boot/myocamlbuild.boot b/boot/myocamlbuild.boot
index 0db6ddb84..cbb279dd1 100755
--- a/boot/myocamlbuild.boot
+++ b/boot/myocamlbuild.boot
Binary files differ
diff --git a/boot/ocamlc b/boot/ocamlc
index f68e2517d..682253fc4 100755
--- a/boot/ocamlc
+++ b/boot/ocamlc
Binary files differ
diff --git a/boot/ocamldep b/boot/ocamldep
index 1b9608c72..25c5166fc 100755
--- a/boot/ocamldep
+++ b/boot/ocamldep
Binary files differ
diff --git a/boot/ocamllex b/boot/ocamllex
index 136e15870..6ea82a22f 100755
--- a/boot/ocamllex
+++ b/boot/ocamllex
Binary files differ
diff --git a/build/camlp4-bootstrap-recipe.txt b/build/camlp4-bootstrap-recipe.txt
index 264d63551..120603801 100644
--- a/build/camlp4-bootstrap-recipe.txt
+++ b/build/camlp4-bootstrap-recipe.txt
@@ -2,6 +2,7 @@
make clean
./build/distclean.sh
./configure -prefix `pwd`/_install
+ (cd otherlibs/labltk/browser; make help.ml)
./build/fastworld.sh
# Go to "Bootstrap camlp4"
@@ -121,7 +122,7 @@
In Camlp4/Printers/OCaml.ml:
| <:expr< let open $i$ in $e$ >> ->
- pp f "@[<2>let open %a@]@ @[<2>in@ %a@]"
+ pp f "@[<2>let open %a@]@ @[<2>in@ %a@]"
o#ident i o#reset_semi#expr e
And at the end of #simple_expr:
<:expr< let open $_$ in $_$ >>
diff --git a/bytecomp/matching.ml b/bytecomp/matching.ml
index 81a1525d6..fb3622632 100644
--- a/bytecomp/matching.ml
+++ b/bytecomp/matching.ml
@@ -124,7 +124,7 @@ let filter_matrix matcher pss =
let rec filter_rec = function
| (p::ps)::rem ->
begin match p.pat_desc with
- | Tpat_alias (p,_) ->
+ | Tpat_alias (p,_,_) ->
filter_rec ((p::ps)::rem)
| Tpat_var _ ->
filter_rec ((omega::ps)::rem)
@@ -162,9 +162,9 @@ let make_default matcher env =
let ctx_matcher p =
let p = normalize_pat p in
match p.pat_desc with
- | Tpat_construct (cstr,omegas) ->
+ | Tpat_construct (_, _, cstr,omegas,_) ->
(fun q rem -> match q.pat_desc with
- | Tpat_construct (cstr',args) when cstr.cstr_tag=cstr'.cstr_tag ->
+ | Tpat_construct (_, _, cstr',args,_) when cstr.cstr_tag=cstr'.cstr_tag ->
p,args @ rem
| Tpat_any -> p,omegas @ rem
| _ -> raise NoMatch)
@@ -197,12 +197,12 @@ let ctx_matcher p =
(fun q rem -> match q.pat_desc with
| Tpat_tuple args -> p,args @ rem
| _ -> p, omegas @ rem)
- | Tpat_record l -> (* Records are normalized *)
+ | Tpat_record (l,_) -> (* Records are normalized *)
(fun q rem -> match q.pat_desc with
- | Tpat_record l' ->
+ | Tpat_record (l',_) ->
let l' = all_record_args l' in
- p, List.fold_right (fun (_,p) r -> p::r) l' rem
- | _ -> p,List.fold_right (fun (_,p) r -> p::r) l rem)
+ p, List.fold_right (fun (_, _, _,p) r -> p::r) l' rem
+ | _ -> p,List.fold_right (fun (_, _, _,p) r -> p::r) l rem)
| Tpat_lazy omega ->
(fun q rem -> match q.pat_desc with
| Tpat_lazy arg -> p, (arg::rem)
@@ -221,7 +221,7 @@ let filter_ctx q ctx =
begin match p.pat_desc with
| Tpat_or (p1,p2,_) ->
filter_rec ({l with right=p1::ps}::{l with right=p2::ps}::rem)
- | Tpat_alias (p,_) ->
+ | Tpat_alias (p,_,_) ->
filter_rec ({l with right=p::ps}::rem)
| Tpat_var _ ->
filter_rec ({l with right=omega::ps}::rem)
@@ -507,11 +507,11 @@ exception Var of pattern
let simplify_or p =
let rec simpl_rec p = match p with
| {pat_desc = Tpat_any|Tpat_var _} -> raise (Var p)
- | {pat_desc = Tpat_alias (q,id)} ->
+ | {pat_desc = Tpat_alias (q,id,s)} ->
begin try
- {p with pat_desc = Tpat_alias (simpl_rec q,id)}
+ {p with pat_desc = Tpat_alias (simpl_rec q,id,s)}
with
- | Var q -> raise (Var {p with pat_desc = Tpat_alias (q,id)})
+ | Var q -> raise (Var {p with pat_desc = Tpat_alias (q,id,s)})
end
| {pat_desc = Tpat_or (p1,p2,o)} ->
let q1 = simpl_rec p1 in
@@ -521,9 +521,9 @@ let simplify_or p =
with
| Var q2 -> raise (Var {p with pat_desc = Tpat_or (q1, q2, o)})
end
- | {pat_desc = Tpat_record lbls} ->
+ | {pat_desc = Tpat_record (lbls,closed)} ->
let all_lbls = all_record_args lbls in
- {p with pat_desc=Tpat_record all_lbls}
+ {p with pat_desc=Tpat_record (all_lbls, closed)}
| _ -> p in
try
simpl_rec p
@@ -537,19 +537,19 @@ let simplify_cases args cls = match args with
| [] -> []
| ((pat :: patl, action) as cl) :: rem ->
begin match pat.pat_desc with
- | Tpat_var id ->
+ | Tpat_var (id, _) ->
(omega :: patl, bind Alias id arg action) ::
simplify rem
| Tpat_any ->
cl :: simplify rem
- | Tpat_alias(p, id) ->
+ | Tpat_alias(p, id,_) ->
simplify ((p :: patl, bind Alias id arg action) :: rem)
- | Tpat_record [] ->
+ | Tpat_record ([],_) ->
(omega :: patl, action)::
simplify rem
- | Tpat_record lbls ->
+ | Tpat_record (lbls, closed) ->
let all_lbls = all_record_args lbls in
- let full_pat = {pat with pat_desc=Tpat_record all_lbls} in
+ let full_pat = {pat with pat_desc=Tpat_record (all_lbls, closed)} in
(full_pat::patl,action)::
simplify rem
| Tpat_or _ ->
@@ -574,7 +574,7 @@ let simplify_cases args cls = match args with
let rec what_is_cases cases = match cases with
| ({pat_desc=Tpat_any} :: _, _) :: rem -> what_is_cases rem
-| (({pat_desc=(Tpat_var _|Tpat_or (_,_,_)|Tpat_alias (_,_))}::_),_)::_
+| (({pat_desc=(Tpat_var _|Tpat_or (_,_,_)|Tpat_alias (_,_,_))}::_),_)::_
-> assert false (* applies to simplified matchings only *)
| (p::_,_)::_ -> p
| [] -> omega
@@ -606,16 +606,16 @@ let default_compat p def =
(* Or-pattern expansion, variables are a complication w.r.t. the article *)
let rec extract_vars r p = match p.pat_desc with
-| Tpat_var id -> IdentSet.add id r
-| Tpat_alias (p, id) ->
+| Tpat_var (id, _) -> IdentSet.add id r
+| Tpat_alias (p, id,_ ) ->
extract_vars (IdentSet.add id r) p
| Tpat_tuple pats ->
List.fold_left extract_vars r pats
-| Tpat_record lpats ->
+| Tpat_record (lpats,_) ->
List.fold_left
- (fun r (_,p) -> extract_vars r p)
+ (fun r (_, _, _, p) -> extract_vars r p)
r lpats
-| Tpat_construct (_,pats) ->
+| Tpat_construct (_, _, _, pats,_) ->
List.fold_left extract_vars r pats
| Tpat_array pats ->
List.fold_left extract_vars r pats
@@ -643,9 +643,9 @@ let rec explode_or_pat arg patl mk_action rem vars aliases = function
arg patl mk_action
(explode_or_pat arg patl mk_action rem vars aliases p2)
vars aliases p1
- | {pat_desc = Tpat_alias (p,id)} ->
+ | {pat_desc = Tpat_alias (p,id, _)} ->
explode_or_pat arg patl mk_action rem vars (id::aliases) p
- | {pat_desc = Tpat_var x} ->
+ | {pat_desc = Tpat_var (x, _)} ->
let env = mk_alpha_env arg (x::aliases) vars in
(omega::patl,mk_action (List.map snd env))::rem
| p ->
@@ -665,7 +665,7 @@ let group_constant = function
| _ -> false
and group_constructor = function
- | {pat_desc = Tpat_construct (_, _)} -> true
+ | {pat_desc = Tpat_construct (_, _, _, _,_)} -> true
| _ -> false
and group_variant = function
@@ -695,7 +695,7 @@ and group_lazy = function
let get_group p = match p.pat_desc with
| Tpat_any -> group_var
| Tpat_constant _ -> group_constant
-| Tpat_construct (_, _) -> group_constructor
+| Tpat_construct (_, _, _, _, _) -> group_constructor
| Tpat_tuple _ -> group_tuple
| Tpat_record _ -> group_record
| Tpat_array _ -> group_array
@@ -1129,15 +1129,15 @@ let make_field_args binding_kind arg first_pos last_pos argl =
in make_args first_pos
let get_key_constr = function
- | {pat_desc=Tpat_construct (cstr,_)} -> cstr.cstr_tag
+ | {pat_desc=Tpat_construct (_, _, cstr,_,_)} -> cstr.cstr_tag
| _ -> assert false
let get_args_constr p rem = match p with
-| {pat_desc=Tpat_construct (_,args)} -> args @ rem
+| {pat_desc=Tpat_construct (_, _, _, args, _)} -> args @ rem
| _ -> assert false
let pat_as_constr = function
- | {pat_desc=Tpat_construct (cstr,_)} -> cstr
+ | {pat_desc=Tpat_construct (_, _, cstr,_,_)} -> cstr
| _ -> fatal_error "Matching.pat_as_constr"
@@ -1151,7 +1151,7 @@ let matcher_constr cstr = match cstr.cstr_arity with
with
| NoMatch -> matcher_rec p2 rem
end
- | Tpat_construct (cstr1, []) when cstr.cstr_tag = cstr1.cstr_tag ->
+ | Tpat_construct (_, _, cstr1, [],_) when cstr.cstr_tag = cstr1.cstr_tag ->
rem
| Tpat_any -> rem
| _ -> raise NoMatch in
@@ -1172,7 +1172,7 @@ pat_desc = Tpat_or (a1, a2, None)}::
rem
| _, _ -> assert false
end
- | Tpat_construct (cstr1, [arg]) when cstr.cstr_tag = cstr1.cstr_tag ->
+ | Tpat_construct (_, _, cstr1, [arg],_) when cstr.cstr_tag = cstr1.cstr_tag ->
arg::rem
| Tpat_any -> omega::rem
| _ -> raise NoMatch in
@@ -1180,7 +1180,7 @@ pat_desc = Tpat_or (a1, a2, None)}::
| _ ->
fun q rem -> match q.pat_desc with
| Tpat_or (_,_,_) -> raise OrPat
- | Tpat_construct (cstr1, args)
+ | Tpat_construct (_, _, cstr1, args,_)
when cstr.cstr_tag = cstr1.cstr_tag -> args @ rem
| Tpat_any -> Parmatch.omegas cstr.cstr_arity @ rem
| _ -> raise NoMatch
@@ -1446,13 +1446,13 @@ let divide_tuple arity p ctx pm =
let record_matching_line num_fields lbl_pat_list =
let patv = Array.create num_fields omega in
- List.iter (fun (lbl, pat) -> patv.(lbl.lbl_pos) <- pat) lbl_pat_list;
+ List.iter (fun (_, _, lbl, pat) -> patv.(lbl.lbl_pos) <- pat) lbl_pat_list;
Array.to_list patv
let get_args_record num_fields p rem = match p with
| {pat_desc=Tpat_any} ->
record_matching_line num_fields [] @ rem
-| {pat_desc=Tpat_record lbl_pat_list} ->
+| {pat_desc=Tpat_record (lbl_pat_list,_)} ->
record_matching_line num_fields lbl_pat_list @ rem
| _ -> assert false
@@ -1846,7 +1846,7 @@ let rec extract_pat seen k p = match p.pat_desc with
| Tpat_or (p1,p2,_) ->
let k1,seen1 = extract_pat seen k p1 in
extract_pat seen1 k1 p2
-| Tpat_alias (p,_) ->
+| Tpat_alias (p,_,_) ->
extract_pat seen k p
| Tpat_var _|Tpat_any ->
raise All
@@ -2367,8 +2367,8 @@ let rec comp_match_handlers comp_fun partial ctx arg first_match next_matchs = m
let rec name_pattern default = function
(pat :: patl, action) :: rem ->
begin match pat.pat_desc with
- Tpat_var id -> id
- | Tpat_alias(p, id) -> id
+ Tpat_var (id, _) -> id
+ | Tpat_alias(p, id, _) -> id
| _ -> name_pattern default rem
end
| _ -> Ident.create default
@@ -2438,7 +2438,7 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
compile_no_test
(divide_tuple (List.length patl) (normalize_pat pat)) ctx_combine
repr partial ctx pm
- | Tpat_record ((lbl,_)::_) ->
+ | Tpat_record ((_, _, lbl,_)::_,_) ->
compile_no_test
(divide_record lbl.lbl_all (normalize_pat pat))
ctx_combine repr partial ctx pm
@@ -2448,7 +2448,7 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
divide_constant
(combine_constant arg cst partial)
ctx pm
- | Tpat_construct (cstr, _) ->
+ | Tpat_construct (_, _, cstr, _, _) ->
compile_test
(compile_match repr partial) partial
divide_constructor (combine_constructor arg pat cstr partial)
@@ -2591,7 +2591,7 @@ let rec flatten_pat_line size p k = match p.pat_desc with
| Tpat_any -> omegas size::k
| Tpat_tuple args -> args::k
| Tpat_or (p1,p2,_) -> flatten_pat_line size p1 (flatten_pat_line size p2 k)
-| Tpat_alias (p,_) -> (* Note: if this 'as' pat is here, then this is a useless
+| Tpat_alias (p,_,_) -> (* Note: if this 'as' pat is here, then this is a useless
binding, solves PR #3780 *)
flatten_pat_line size p k
| _ -> fatal_error "Matching.flatten_pat_line"
diff --git a/bytecomp/translclass.ml b/bytecomp/translclass.ml
index e9dbed58e..e4b415376 100644
--- a/bytecomp/translclass.ml
+++ b/bytecomp/translclass.ml
@@ -113,7 +113,7 @@ let create_object cl obj init =
let rec build_object_init cl_table obj params inh_init obj_init cl =
match cl.cl_desc with
- Tclass_ident path ->
+ Tcl_ident ( path, _, _) ->
let obj_init = Ident.create "obj_init" in
let envs, inh_init = inh_init in
let env =
@@ -122,27 +122,27 @@ let rec build_object_init cl_table obj params inh_init obj_init cl =
in
((envs, (obj_init, path)::inh_init),
mkappl(Lvar obj_init, env @ [obj]))
- | Tclass_structure str ->
+ | Tcl_structure str ->
create_object cl_table obj (fun obj ->
let (inh_init, obj_init, has_init) =
List.fold_right
(fun field (inh_init, obj_init, has_init) ->
- match field with
- Cf_inher (cl, _, _) ->
+ match field.cf_desc with
+ Tcf_inher (_, cl, _, _, _) ->
let (inh_init, obj_init') =
build_object_init cl_table (Lvar obj) [] inh_init
(fun _ -> lambda_unit) cl
in
(inh_init, lsequence obj_init' obj_init, true)
- | Cf_val (_, id, Some exp, _) ->
+ | Tcf_val (_, _, _, id, Tcfk_concrete exp, _) ->
(inh_init, lsequence (set_inst_var obj id exp) obj_init,
has_init)
- | Cf_meth _ | Cf_val _ ->
+ | Tcf_meth _ | Tcf_val _ | Tcf_constr _ ->
(inh_init, obj_init, has_init)
- | Cf_init _ ->
+ | Tcf_init _ ->
(inh_init, obj_init, true)
)
- str.cl_field
+ str.cstr_fields
(inh_init, obj_init obj, false)
in
(inh_init,
@@ -151,7 +151,8 @@ let rec build_object_init cl_table obj params inh_init obj_init cl =
lsequence (Lifused (id, set_inst_var obj id expr)) rem)
params obj_init,
has_init))
- | Tclass_fun (pat, vals, cl, partial) ->
+ | Tcl_fun (_, pat, vals, cl, partial) ->
+ let vals = List.map (fun (id, _, e) -> id,e) vals in
let (inh_init, obj_init) =
build_object_init cl_table obj (vals @ params) inh_init obj_init cl
in
@@ -166,22 +167,24 @@ let rec build_object_init cl_table obj params inh_init obj_init cl =
Lfunction (Curried, params, rem) -> build params rem
| rem -> build [] rem
end)
- | Tclass_apply (cl, oexprs) ->
+ | Tcl_apply (cl, oexprs) ->
let (inh_init, obj_init) =
build_object_init cl_table obj params inh_init obj_init cl
in
(inh_init, transl_apply obj_init oexprs Location.none)
- | Tclass_let (rec_flag, defs, vals, cl) ->
+ | Tcl_let (rec_flag, defs, vals, cl) ->
+ let vals = List.map (fun (id, _, e) -> id,e) vals in
let (inh_init, obj_init) =
build_object_init cl_table obj (vals @ params) inh_init obj_init cl
in
(inh_init, Translcore.transl_let rec_flag defs obj_init)
- | Tclass_constraint (cl, vals, pub_meths, concr_meths) ->
+ | Tcl_constraint (cl, _, vals, pub_meths, concr_meths) ->
build_object_init cl_table obj params inh_init obj_init cl
let rec build_object_init_0 cl_table params cl copy_env subst_env top ids =
match cl.cl_desc with
- Tclass_let (rec_flag, defs, vals, cl) ->
+ Tcl_let (rec_flag, defs, vals, cl) ->
+ let vals = List.map (fun (id, _, e) -> id,e) vals in
build_object_init_0 cl_table (vals@params) cl copy_env subst_env top ids
| _ ->
let self = Ident.create "self" in
@@ -230,8 +233,8 @@ let output_methods tbl methods lam =
let rec ignore_cstrs cl =
match cl.cl_desc with
- Tclass_constraint (cl, _, _, _) -> ignore_cstrs cl
- | Tclass_apply (cl, _) -> ignore_cstrs cl
+ Tcl_constraint (cl, _, _, _, _) -> ignore_cstrs cl
+ | Tcl_apply (cl, _) -> ignore_cstrs cl
| _ -> cl
let rec index a = function
@@ -239,11 +242,11 @@ let rec index a = function
| b :: l ->
if b = a then 0 else 1 + index a l
-let bind_id_as_val (id, _) = ("", id)
+let bind_id_as_val (id, _, _) = ("", id)
let rec build_class_init cla cstr super inh_init cl_init msubst top cl =
match cl.cl_desc with
- Tclass_ident path ->
+ Tcl_ident ( path, _, _) ->
begin match inh_init with
(obj_init, path')::inh_init ->
let lpath = transl_path path in
@@ -255,23 +258,28 @@ let rec build_class_init cla cstr super inh_init cl_init msubst top cl =
| _ ->
assert false
end
- | Tclass_structure str ->
+ | Tcl_structure str ->
let cl_init = bind_super cla super cl_init in
let (inh_init, cl_init, methods, values) =
List.fold_right
(fun field (inh_init, cl_init, methods, values) ->
- match field with
- Cf_inher (cl, vals, meths) ->
+ match field.cf_desc with
+ Tcf_inher (_, cl, _, vals, meths) ->
let cl_init = output_methods cla methods cl_init in
let inh_init, cl_init =
build_class_init cla false
- (vals, meths_super cla str.cl_meths meths)
+ (vals, meths_super cla str.cstr_meths meths)
inh_init cl_init msubst top cl in
(inh_init, cl_init, [], values)
- | Cf_val (name, id, exp, over) ->
+ | Tcf_val (name, _, _, id, Tcfk_concrete exp, over) ->
let values = if over then values else (name, id) :: values in
(inh_init, cl_init, methods, values)
- | Cf_meth (name, exp) ->
+ | Tcf_val (_, _, _, _, Tcfk_virtual _, _)
+ | Tcf_meth (_, _, _, Tcfk_virtual _, _)
+ | Tcf_constr _
+ ->
+ (inh_init, cl_init, methods, values)
+ | Tcf_meth (name, _, _, Tcfk_concrete exp, over) ->
let met_code = msubst true (transl_exp exp) in
let met_code =
if !Clflags.native_code && List.length met_code = 1 then
@@ -281,34 +289,34 @@ let rec build_class_init cla cstr super inh_init cl_init msubst top cl =
else met_code
in
(inh_init, cl_init,
- Lvar (Meths.find name str.cl_meths) :: met_code @ methods,
+ Lvar (Meths.find name str.cstr_meths) :: met_code @ methods,
values)
- | Cf_init exp ->
+ | Tcf_init exp ->
(inh_init,
Lsequence(mkappl (oo_prim "add_initializer",
Lvar cla :: msubst false (transl_exp exp)),
cl_init),
methods, values))
- str.cl_field
+ str.cstr_fields
(inh_init, cl_init, [], [])
in
let cl_init = output_methods cla methods cl_init in
- (inh_init, bind_methods cla str.cl_meths values cl_init)
- | Tclass_fun (pat, vals, cl, _) ->
+ (inh_init, bind_methods cla str.cstr_meths values cl_init)
+ | Tcl_fun (_, pat, vals, cl, _) ->
let (inh_init, cl_init) =
build_class_init cla cstr super inh_init cl_init msubst top cl
in
let vals = List.map bind_id_as_val vals in
(inh_init, transl_vals cla true StrictOpt vals cl_init)
- | Tclass_apply (cl, exprs) ->
+ | Tcl_apply (cl, exprs) ->
build_class_init cla cstr super inh_init cl_init msubst top cl
- | Tclass_let (rec_flag, defs, vals, cl) ->
+ | Tcl_let (rec_flag, defs, vals, cl) ->
let (inh_init, cl_init) =
build_class_init cla cstr super inh_init cl_init msubst top cl
in
let vals = List.map bind_id_as_val vals in
(inh_init, transl_vals cla true StrictOpt vals cl_init)
- | Tclass_constraint (cl, vals, meths, concr_meths) ->
+ | Tcl_constraint (cl, _, vals, meths, concr_meths) ->
let virt_meths =
List.filter (fun lab -> not (Concr.mem lab concr_meths)) meths in
let concr_meths = Concr.elements concr_meths in
@@ -319,7 +327,7 @@ let rec build_class_init cla cstr super inh_init cl_init msubst top cl =
transl_meth_list concr_meths] in
let cl = ignore_cstrs cl in
begin match cl.cl_desc, inh_init with
- Tclass_ident path, (obj_init, path')::inh_init ->
+ Tcl_ident (path, _, _), (obj_init, path')::inh_init ->
assert (Path.same path path');
let lpath = transl_path path in
let inh = Ident.create "inh"
@@ -356,7 +364,7 @@ let rec build_class_init cla cstr super inh_init cl_init msubst top cl =
let rec build_class_lets cl =
match cl.cl_desc with
- Tclass_let (rec_flag, defs, vals, cl) ->
+ Tcl_let (rec_flag, defs, vals, cl) ->
let env, wrap = build_class_lets cl in
(env, fun x -> Translcore.transl_let rec_flag defs (wrap x))
| _ ->
@@ -364,13 +372,13 @@ let rec build_class_lets cl =
let rec get_class_meths cl =
match cl.cl_desc with
- Tclass_structure cl ->
- Meths.fold (fun _ -> IdentSet.add) cl.cl_meths IdentSet.empty
- | Tclass_ident _ -> IdentSet.empty
- | Tclass_fun (_, _, cl, _)
- | Tclass_let (_, _, _, cl)
- | Tclass_apply (cl, _)
- | Tclass_constraint (cl, _, _, _) -> get_class_meths cl
+ Tcl_structure cl ->
+ Meths.fold (fun _ -> IdentSet.add) cl.cstr_meths IdentSet.empty
+ | Tcl_ident _ -> IdentSet.empty
+ | Tcl_fun (_, _, _, cl, _)
+ | Tcl_let (_, _, _, cl)
+ | Tcl_apply (cl, _)
+ | Tcl_constraint (cl, _, _, _, _) -> get_class_meths cl
(*
XXX Il devrait etre peu couteux d'ecrire des classes :
@@ -378,13 +386,13 @@ let rec get_class_meths cl =
*)
let rec transl_class_rebind obj_init cl vf =
match cl.cl_desc with
- Tclass_ident path ->
+ Tcl_ident (path, _, _) ->
if vf = Concrete then begin
try if (Env.find_class path cl.cl_env).cty_new = None then raise Exit
with Not_found -> raise Exit
end;
(path, obj_init)
- | Tclass_fun (pat, _, cl, partial) ->
+ | Tcl_fun (_, pat, _, cl, partial) ->
let path, obj_init = transl_class_rebind obj_init cl vf in
let build params rem =
let param = name_pattern "param" [pat, ()] in
@@ -396,18 +404,18 @@ let rec transl_class_rebind obj_init cl vf =
match obj_init with
Lfunction (Curried, params, rem) -> build params rem
| rem -> build [] rem)
- | Tclass_apply (cl, oexprs) ->
+ | Tcl_apply (cl, oexprs) ->
let path, obj_init = transl_class_rebind obj_init cl vf in
(path, transl_apply obj_init oexprs Location.none)
- | Tclass_let (rec_flag, defs, vals, cl) ->
+ | Tcl_let (rec_flag, defs, vals, cl) ->
let path, obj_init = transl_class_rebind obj_init cl vf in
(path, Translcore.transl_let rec_flag defs obj_init)
- | Tclass_structure _ -> raise Exit
- | Tclass_constraint (cl', _, _, _) ->
+ | Tcl_structure _ -> raise Exit
+ | Tcl_constraint (cl', _, _, _, _) ->
let path, obj_init = transl_class_rebind obj_init cl' vf in
let rec check_constraint = function
- Tcty_constr(path', _, _) when Path.same path path' -> ()
- | Tcty_fun (_, _, cty) -> check_constraint cty
+ Cty_constr(path', _, _) when Path.same path path' -> ()
+ | Cty_fun (_, _, cty) -> check_constraint cty
| _ -> raise Exit
in
check_constraint cl.cl_type;
@@ -415,7 +423,7 @@ let rec transl_class_rebind obj_init cl vf =
let rec transl_class_rebind_0 self obj_init cl vf =
match cl.cl_desc with
- Tclass_let (rec_flag, defs, vals, cl) ->
+ Tcl_let (rec_flag, defs, vals, cl) ->
let path, obj_init = transl_class_rebind_0 self obj_init cl vf in
(path, Translcore.transl_let rec_flag defs obj_init)
| _ ->
@@ -578,7 +586,7 @@ let prerr_ids msg ids =
let names = List.map Ident.unique_toplevel_name ids in
prerr_endline (String.concat " " (msg :: names))
-let transl_class ids cl_id arity pub_meths cl vflag =
+let transl_class ids cl_id pub_meths cl vflag =
(* First check if it is not only a rebind *)
let rebind = transl_class_rebind ids cl vflag in
if rebind <> lambda_unit then rebind else
@@ -788,12 +796,20 @@ let transl_class ids cl_id arity pub_meths cl vflag =
)))))
(* Wrapper for class compilation *)
+(*
+ let cl_id = ci.ci_id_class in
+(* TODO: cl_id is used somewhere else as typesharp ? *)
+ let _arity = List.length (fst ci.ci_params) in
+ let pub_meths = m in
+ let cl = ci.ci_expr in
+ let vflag = vf in
+*)
-let transl_class ids cl_id arity pub_meths cl vf =
- oo_wrap cl.cl_env false (transl_class ids cl_id arity pub_meths cl) vf
+let transl_class ids id pub_meths cl vf =
+ oo_wrap cl.cl_env false (transl_class ids id pub_meths cl) vf
let () =
- transl_object := (fun id meths cl -> transl_class [] id 0 meths cl Concrete)
+ transl_object := (fun id meths cl -> transl_class [] id meths cl Concrete)
(* Error report *)
diff --git a/bytecomp/translclass.mli b/bytecomp/translclass.mli
index 7a5d6d143..34dd7e671 100644
--- a/bytecomp/translclass.mli
+++ b/bytecomp/translclass.mli
@@ -17,7 +17,7 @@ open Lambda
val transl_class :
Ident.t list -> Ident.t ->
- int -> string list -> class_expr -> Asttypes.virtual_flag -> lambda;;
+ string list -> class_expr -> Asttypes.virtual_flag -> lambda;;
type error = Illegal_class_expr | Tags of string * string
diff --git a/bytecomp/translcore.ml b/bytecomp/translcore.ml
index 1b2bef230..0398d644c 100644
--- a/bytecomp/translcore.ml
+++ b/bytecomp/translcore.ml
@@ -294,10 +294,10 @@ let transl_prim loc prim args =
simplify_constant_constructor) =
Hashtbl.find comparisons_table prim_name in
begin match args with
- [arg1; {exp_desc = Texp_construct({cstr_tag = Cstr_constant _}, _)}]
+ [arg1; {exp_desc = Texp_construct(_, _, {cstr_tag = Cstr_constant _}, _, _)}]
when simplify_constant_constructor ->
intcomp
- | [{exp_desc = Texp_construct({cstr_tag = Cstr_constant _}, _)}; arg2]
+ | [{exp_desc = Texp_construct(_, _, {cstr_tag = Cstr_constant _}, _, _)}; arg2]
when simplify_constant_constructor ->
intcomp
| [arg1; {exp_desc = Texp_variant(_, None)}]
@@ -460,17 +460,17 @@ let rec name_pattern default = function
[] -> Ident.create default
| (p, e) :: rem ->
match p.pat_desc with
- Tpat_var id -> id
- | Tpat_alias(p, id) -> id
+ Tpat_var (id, _) -> id
+ | Tpat_alias(p, id, _) -> id
| _ -> name_pattern default rem
(* Push the default values under the functional abstractions *)
let rec push_defaults loc bindings pat_expr_list partial =
match pat_expr_list with
- [pat, ({exp_desc = Texp_function(pl,partial)} as exp)] ->
+ [pat, ({exp_desc = Texp_function(l, pl,partial)} as exp)] ->
let pl = push_defaults exp.exp_loc bindings pl partial in
- [pat, {exp with exp_desc = Texp_function(pl, partial)}]
+ [pat, {exp with exp_desc = Texp_function(l, pl, partial)}]
| [pat, {exp_desc = Texp_let
(Default, cases, ({exp_desc = Texp_function _} as e2))}] ->
push_defaults loc (cases :: bindings) [pat, e2] partial
@@ -488,14 +488,14 @@ let rec push_defaults loc bindings pat_expr_list partial =
{ exp with exp_loc = loc; exp_desc =
Texp_match
({exp with exp_type = pat.pat_type; exp_desc =
- Texp_ident (Path.Pident param,
+ Texp_ident (Path.Pident param, mknoloc (Longident.Lident "param"),
{val_type = pat.pat_type; val_kind = Val_reg;
- val_loc = Location.none;
+ Types.val_loc = Location.none;
})},
pat_expr_list, partial) }
in
push_defaults loc bindings
- [{pat with pat_desc = Tpat_var param}, exp] Total
+ [{pat with pat_desc = Tpat_var (param, mknoloc "param")}, exp] Total
| _ ->
pat_expr_list
@@ -571,7 +571,7 @@ let rec transl_exp e =
and transl_exp0 e =
match e.exp_desc with
- Texp_ident(path, {val_kind = Val_prim p}) ->
+ Texp_ident(path, _, {val_kind = Val_prim p}) ->
let public_send = p.prim_name = "%send" in
if public_send || p.prim_name = "%sendself" then
let kind = if public_send then Public else Self in
@@ -584,16 +584,16 @@ and transl_exp0 e =
Lsend(Cached, Lvar meth, Lvar obj, [Lvar cache; Lvar pos], e.exp_loc))
else
transl_primitive p
- | Texp_ident(path, {val_kind = Val_anc _}) ->
+ | Texp_ident(path, _, {val_kind = Val_anc _}) ->
raise(Error(e.exp_loc, Free_super_var))
- | Texp_ident(path, {val_kind = Val_reg | Val_self _}) ->
+ | Texp_ident(path, _, {val_kind = Val_reg | Val_self _}) ->
transl_path path
| Texp_ident _ -> fatal_error "Translcore.transl_exp: bad Texp_ident"
| Texp_constant cst ->
Lconst(Const_base cst)
| Texp_let(rec_flag, pat_expr_list, body) ->
transl_let rec_flag pat_expr_list (event_before body (transl_exp body))
- | Texp_function (pat_expr_list, partial) ->
+ | Texp_function (_, pat_expr_list, partial) ->
let ((kind, params), body) =
event_function e
(function repr ->
@@ -601,9 +601,9 @@ and transl_exp0 e =
transl_function e.exp_loc !Clflags.native_code repr partial pl)
in
Lfunction(kind, params, body)
- | Texp_apply({exp_desc = Texp_ident(path, {val_kind = Val_prim p})}, oargs)
+ | Texp_apply({exp_desc = Texp_ident(path, _, {val_kind = Val_prim p})}, oargs)
when List.length oargs >= p.prim_arity
- && List.for_all (fun (arg,_) -> arg <> None) oargs ->
+ && List.for_all (fun (_, arg,_) -> arg <> None) oargs ->
let args, args' = cut p.prim_arity oargs in
let wrap f =
if args' = []
@@ -612,7 +612,7 @@ and transl_exp0 e =
in
let wrap0 f =
if args' = [] then f else wrap f in
- let args = List.map (function Some x, _ -> x | _ -> assert false) args in
+ let args = List.map (function _, Some x, _ -> x | _ -> assert false) args in
let argl = transl_list args in
let public_send = p.prim_name = "%send"
|| not !Clflags.native_code && p.prim_name = "%sendcache"in
@@ -657,7 +657,7 @@ and transl_exp0 e =
with Not_constant ->
Lprim(Pmakeblock(0, Immutable), ll)
end
- | Texp_construct(cstr, args) ->
+ | Texp_construct(_, _, cstr, args, _) ->
let ll = transl_list args in
begin match cstr.cstr_tag with
Cstr_constant n ->
@@ -684,17 +684,17 @@ and transl_exp0 e =
Lprim(Pmakeblock(0, Immutable),
[Lconst(Const_base(Const_int tag)); lam])
end
- | Texp_record ((lbl1, _) :: _ as lbl_expr_list, opt_init_expr) ->
+ | Texp_record ((_, _, lbl1, _) :: _ as lbl_expr_list, opt_init_expr) ->
transl_record lbl1.lbl_all lbl1.lbl_repres lbl_expr_list opt_init_expr
| Texp_record ([], _) ->
fatal_error "Translcore.transl_exp: bad Texp_record"
- | Texp_field(arg, lbl) ->
+ | Texp_field(arg, _, _, lbl) ->
let access =
match lbl.lbl_repres with
Record_regular -> Pfield lbl.lbl_pos
| Record_float -> Pfloatfield lbl.lbl_pos in
Lprim(access, [transl_exp arg])
- | Texp_setfield(arg, lbl, newval) ->
+ | Texp_setfield(arg, _, _, lbl, newval) ->
let access =
match lbl.lbl_repres with
Record_regular -> Psetfield(lbl.lbl_pos, maybe_pointer newval)
@@ -731,14 +731,15 @@ and transl_exp0 e =
Lsequence(transl_exp expr1, event_before expr2 (transl_exp expr2))
| Texp_while(cond, body) ->
Lwhile(transl_exp cond, event_before body (transl_exp body))
- | Texp_for(param, low, high, dir, body) ->
+ | Texp_for(param, _, low, high, dir, body) ->
Lfor(param, transl_exp low, transl_exp high, dir,
event_before body (transl_exp body))
| Texp_when(cond, body) ->
event_before cond
(Lifthenelse(transl_exp cond, event_before body (transl_exp body),
staticfail))
- | Texp_send(expr, met) ->
+ | Texp_send(_, _, Some exp) -> transl_exp exp
+ | Texp_send(expr, met, None) ->
let obj = transl_exp expr in
let lam =
match met with
@@ -749,11 +750,11 @@ and transl_exp0 e =
Lsend (kind, tag, obj, cache, e.exp_loc)
in
event_after e lam
- | Texp_new (cl, _) ->
+ | Texp_new (cl, _, _) ->
Lapply(Lprim(Pfield 0, [transl_path cl]), [lambda_unit], Location.none)
- | Texp_instvar(path_self, path) ->
+ | Texp_instvar(path_self, path, _) ->
Lprim(Parrayrefu Paddrarray, [transl_path path_self; transl_path path])
- | Texp_setinstvar(path_self, path, expr) ->
+ | Texp_setinstvar(path_self, path, _, expr) ->
transl_setinstvar (transl_path path_self) path expr
| Texp_override(path_self, modifs) ->
let cpy = Ident.create "copy" in
@@ -761,11 +762,11 @@ and transl_exp0 e =
Lapply(Translobj.oo_prim "copy", [transl_path path_self],
Location.none),
List.fold_right
- (fun (path, expr) rem ->
+ (fun (path, _, expr) rem ->
Lsequence(transl_setinstvar (Lvar cpy) path expr, rem))
modifs
(Lvar cpy))
- | Texp_letmodule(id, modl, body) ->
+ | Texp_letmodule(id, _, modl, body) ->
Llet(Strict, id, !transl_module Tcoerce_none None modl, transl_exp body)
| Texp_pack modl ->
!transl_module Tcoerce_none None modl
@@ -783,12 +784,12 @@ and transl_exp0 e =
| Texp_constant
( Const_int _ | Const_char _ | Const_string _
| Const_int32 _ | Const_int64 _ | Const_nativeint _ )
- | Texp_function(_, _)
- | Texp_construct ({cstr_arity = 0}, _)
+ | Texp_function(_, _, _)
+ | Texp_construct (_, _, {cstr_arity = 0}, _, _)
-> transl_exp e
| Texp_constant(Const_float _) ->
Lprim(Pmakeblock(Obj.forward_tag, Immutable), [transl_exp e])
- | Texp_ident(_, _) -> (* according to the type *)
+ | Texp_ident(_, _, _) -> (* according to the type *)
begin match e.exp_type.desc with
(* the following may represent a float/forward/lazy: need a
forward_tag *)
@@ -824,13 +825,17 @@ and transl_exp0 e =
let fn = Lfunction (Curried, [Ident.create "param"], transl_exp e) in
Lprim(Pmakeblock(Config.lazy_tag, Immutable), [fn])
end
- | Texp_object (cs, cty, meths) ->
+ | Texp_object (cs, meths) ->
+ let cty = cs.cstr_type in
let cl = Ident.create "class" in
!transl_object cl meths
- { cl_desc = Tclass_structure cs;
+ { cl_desc = Tcl_structure cs;
cl_loc = e.exp_loc;
- cl_type = Tcty_signature cty;
+ cl_type = Cty_signature cty;
cl_env = e.exp_env }
+ | Texp_poly (exp, _ )
+ | Texp_newtype (_, exp)
+ -> transl_exp exp
and transl_list expr_list =
List.map transl_exp expr_list
@@ -891,11 +896,11 @@ and transl_apply lam sargs loc =
| [] ->
lapply lam (List.rev_map fst args)
in
- build_apply lam [] (List.map (fun (x,o) -> may_map transl_exp x, o) sargs)
+ build_apply lam [] (List.map (fun (l, x,o) -> may_map transl_exp x, o) sargs)
and transl_function loc untuplify_fn repr partial pat_expr_list =
match pat_expr_list with
- [pat, ({exp_desc = Texp_function(pl,partial')} as exp)]
+ [pat, ({exp_desc = Texp_function(_, pl,partial')} as exp)]
when Parmatch.fluid pat ->
let param = name_pattern "param" pat_expr_list in
let ((_, params), body) =
@@ -937,10 +942,9 @@ and transl_let rec_flag pat_expr_list body =
| Recursive ->
let idlist =
List.map
- (fun (pat, expr) ->
- match pat.pat_desc with
- Tpat_var id -> id
- | Tpat_alias ({pat_desc=Tpat_any}, id) -> id
+ (fun (pat, expr) -> match pat.pat_desc with
+ Tpat_var (id,_) -> id
+ | Tpat_alias ({pat_desc=Tpat_any}, id,_) -> id
| _ -> raise(Error(pat.pat_loc, Illegal_letrec_pat)))
pat_expr_list in
let transl_case (pat, expr) id =
@@ -975,11 +979,11 @@ and transl_record all_labels repres lbl_expr_list opt_init_expr =
done
end;
List.iter
- (fun (lbl, expr) -> lv.(lbl.lbl_pos) <- transl_exp expr)
+ (fun (_, _, lbl, expr) -> lv.(lbl.lbl_pos) <- transl_exp expr)
lbl_expr_list;
let ll = Array.to_list lv in
let mut =
- if List.exists (fun (lbl, expr) -> lbl.lbl_mut = Mutable) lbl_expr_list
+ if List.exists (fun (_, _, lbl, expr) -> lbl.lbl_mut = Mutable) lbl_expr_list
then Mutable
else Immutable in
let lam =
@@ -1004,7 +1008,7 @@ and transl_record all_labels repres lbl_expr_list opt_init_expr =
(* If you change anything here, you will likely have to change
[check_recursive_recordwith] in this file. *)
let copy_id = Ident.create "newrecord" in
- let update_field (lbl, expr) cont =
+ let update_field (_, _, lbl, expr) cont =
let upd =
match lbl.lbl_repres with
Record_regular -> Psetfield(lbl.lbl_pos, maybe_pointer expr)
diff --git a/bytecomp/translcore.mli b/bytecomp/translcore.mli
index 5cb22775b..71717d12e 100644
--- a/bytecomp/translcore.mli
+++ b/bytecomp/translcore.mli
@@ -16,14 +16,13 @@
for the core language *)
open Asttypes
-open Types
open Typedtree
open Lambda
val name_pattern: string -> (pattern * 'a) list -> Ident.t
val transl_exp: expression -> lambda
-val transl_apply: lambda -> (expression option * optional) list
+val transl_apply: lambda -> (label * expression option * optional) list
-> Location.t -> lambda
val transl_let:
rec_flag -> (pattern * expression) list -> lambda -> lambda
diff --git a/bytecomp/translmod.ml b/bytecomp/translmod.ml
index 69c5e3b37..980d6dde9 100644
--- a/bytecomp/translmod.ml
+++ b/bytecomp/translmod.ml
@@ -117,16 +117,16 @@ let undefined_location loc =
let init_shape modl =
let rec init_shape_mod env mty =
match Mtype.scrape env mty with
- Tmty_ident _ ->
+ Mty_ident _ ->
raise Not_found
- | Tmty_signature sg ->
+ | Mty_signature sg ->
Const_block(0, [Const_block(0, init_shape_struct env sg)])
- | Tmty_functor(id, arg, res) ->
+ | Mty_functor(id, arg, res) ->
raise Not_found (* can we do better? *)
and init_shape_struct env sg =
match sg with
[] -> []
- | Tsig_value(id, vdesc) :: rem ->
+ | Sig_value(id, vdesc) :: rem ->
let init_v =
match Ctype.expand_head env vdesc.val_type with
{desc = Tarrow(_,_,_,_)} ->
@@ -135,19 +135,19 @@ let init_shape modl =
Const_pointer 1 (* camlinternalMod.Lazy *)
| _ -> raise Not_found in
init_v :: init_shape_struct env rem
- | Tsig_type(id, tdecl, _) :: rem ->
+ | Sig_type(id, tdecl, _) :: rem ->
init_shape_struct (Env.add_type id tdecl env) rem
- | Tsig_exception(id, edecl) :: rem ->
+ | Sig_exception(id, edecl) :: rem ->
raise Not_found
- | Tsig_module(id, mty, _) :: rem ->
+ | Sig_module(id, mty, _) :: rem ->
init_shape_mod env mty ::
init_shape_struct (Env.add_module id mty env) rem
- | Tsig_modtype(id, minfo) :: rem ->
+ | Sig_modtype(id, minfo) :: rem ->
init_shape_struct (Env.add_modtype id minfo env) rem
- | Tsig_class(id, cdecl, _) :: rem ->
+ | Sig_class(id, cdecl, _) :: rem ->
Const_pointer 2 (* camlinternalMod.Class *)
:: init_shape_struct env rem
- | Tsig_cltype(id, ctyp, _) :: rem ->
+ | Sig_class_type(id, ctyp, _) :: rem ->
init_shape_struct env rem
in
try
@@ -224,20 +224,21 @@ let compile_recmodule compile_rhs bindings cont =
eval_rec_bindings
(reorder_rec_bindings
(List.map
- (fun (id, modl) ->
+ (fun ( id, _, _, modl) ->
(id, modl.mod_loc, init_shape modl, compile_rhs id modl))
bindings))
cont
+
(* Compile a module expression *)
let rec transl_module cc rootpath mexp =
match mexp.mod_desc with
- Tmod_ident path ->
+ Tmod_ident (path,_) ->
apply_coercion cc (transl_path path)
| Tmod_structure str ->
- transl_structure [] cc rootpath str
- | Tmod_functor(param, mty, body) ->
+ transl_struct [] cc rootpath str
+ | Tmod_functor( param, _, mty, body) ->
let bodypath = functor_path rootpath param in
oo_wrap mexp.mod_env true
(function
@@ -257,11 +258,14 @@ let rec transl_module cc rootpath mexp =
(apply_coercion cc)
(Lapply(transl_module Tcoerce_none None funct,
[transl_module ccarg None arg], mexp.mod_loc))
- | Tmod_constraint(arg, mty, ccarg) ->
+ | Tmod_constraint(arg, mty, _, ccarg) ->
transl_module (compose_coercions cc ccarg) rootpath arg
| Tmod_unpack(arg, _) ->
apply_coercion cc (Translcore.transl_exp arg)
+and transl_struct fields cc rootpath str =
+ transl_structure fields cc rootpath str.str_items
+
and transl_structure fields cc rootpath = function
[] ->
begin match cc with
@@ -280,48 +284,52 @@ and transl_structure fields cc rootpath = function
| _ ->
fatal_error "Translmod.transl_structure"
end
- | Tstr_eval expr :: rem ->
+ | item :: rem ->
+ match item.str_desc with
+ | Tstr_eval expr ->
Lsequence(transl_exp expr, transl_structure fields cc rootpath rem)
- | Tstr_value(rec_flag, pat_expr_list) :: rem ->
+ | Tstr_value(rec_flag, pat_expr_list) ->
let ext_fields = rev_let_bound_idents pat_expr_list @ fields in
transl_let rec_flag pat_expr_list
(transl_structure ext_fields cc rootpath rem)
- | Tstr_primitive(id, descr) :: rem ->
- record_primitive descr;
+ | Tstr_primitive(id, _, descr) ->
+ record_primitive descr.val_val;
transl_structure fields cc rootpath rem
- | Tstr_type(decls) :: rem ->
+ | Tstr_type(decls) ->
transl_structure fields cc rootpath rem
- | Tstr_exception(id, decl) :: rem ->
+ | Tstr_exception( id, _, decl) ->
Llet(Strict, id, transl_exception id (field_path rootpath id) decl,
transl_structure (id :: fields) cc rootpath rem)
- | Tstr_exn_rebind(id, path) :: rem ->
+ | Tstr_exn_rebind( id, _, path, _) ->
Llet(Strict, id, transl_path path,
transl_structure (id :: fields) cc rootpath rem)
- | Tstr_module(id, modl) :: rem ->
+ | Tstr_module( id, _, modl) ->
Llet(Strict, id,
transl_module Tcoerce_none (field_path rootpath id) modl,
transl_structure (id :: fields) cc rootpath rem)
- | Tstr_recmodule bindings :: rem ->
- let ext_fields = List.rev_append (List.map fst bindings) fields in
+ | Tstr_recmodule bindings ->
+ let ext_fields = List.rev_append (List.map (fun (id, _,_,_) -> id) bindings) fields in
compile_recmodule
(fun id modl ->
transl_module Tcoerce_none (field_path rootpath id) modl)
bindings
(transl_structure ext_fields cc rootpath rem)
- | Tstr_modtype(id, decl) :: rem ->
+ | Tstr_modtype(id, _, decl) ->
transl_structure fields cc rootpath rem
- | Tstr_open path :: rem ->
+ | Tstr_open (path, _) ->
transl_structure fields cc rootpath rem
- | Tstr_class cl_list :: rem ->
- let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in
+ | Tstr_class cl_list ->
+ let ids = List.map (fun (ci,_,_) -> ci.ci_id_class) cl_list in
Lletrec(List.map
- (fun (id, arity, meths, cl, vf) ->
- (id, transl_class ids id arity meths cl vf))
+ (fun (ci, meths, vf) ->
+ let id = ci.ci_id_class in
+ let cl = ci.ci_expr in
+ (id, transl_class ids id meths cl vf ))
cl_list,
transl_structure (List.rev ids @ fields) cc rootpath rem)
- | Tstr_cltype cl_list :: rem ->
+ | Tstr_class_type cl_list ->
transl_structure fields cc rootpath rem
- | Tstr_include(modl, ids) :: rem ->
+ | Tstr_include(modl, ids) ->
let mid = Ident.create "include" in
let rec rebind_idents pos newfields = function
[] ->
@@ -344,7 +352,7 @@ let transl_implementation module_name (str, cc) =
let module_id = Ident.create_persistent module_name in
Lprim(Psetglobal module_id,
[transl_label_init
- (transl_structure [] cc (global_path module_id) str)])
+ (transl_struct [] cc (global_path module_id) str)])
(* A variant of transl_structure used to compile toplevel structure definitions
for the native-code compiler. Store the defined values in the fields
@@ -370,29 +378,31 @@ let transl_store_structure glob map prims str =
let rec transl_store subst = function
[] ->
transl_store_subst := subst;
- lambda_unit
- | Tstr_eval expr :: rem ->
+ lambda_unit
+ | item :: rem ->
+ match item.str_desc with
+ | Tstr_eval expr ->
Lsequence(subst_lambda subst (transl_exp expr),
transl_store subst rem)
- | Tstr_value(rec_flag, pat_expr_list) :: rem ->
+ | Tstr_value(rec_flag, pat_expr_list) ->
let ids = let_bound_idents pat_expr_list in
let lam = transl_let rec_flag pat_expr_list (store_idents ids) in
Lsequence(subst_lambda subst lam,
transl_store (add_idents false ids subst) rem)
- | Tstr_primitive(id, descr) :: rem ->
- record_primitive descr;
+ | Tstr_primitive(id, _, descr) ->
+ record_primitive descr.val_val;
transl_store subst rem
- | Tstr_type(decls) :: rem ->
+ | Tstr_type(decls) ->
transl_store subst rem
- | Tstr_exception(id, decl) :: rem ->
+ | Tstr_exception( id, _, decl) ->
let lam = transl_exception id (field_path (global_path glob) id) decl in
Lsequence(Llet(Strict, id, lam, store_ident id),
transl_store (add_ident false id subst) rem)
- | Tstr_exn_rebind(id, path) :: rem ->
+ | Tstr_exn_rebind( id, _, path, _) ->
let lam = subst_lambda subst (transl_path path) in
Lsequence(Llet(Strict, id, lam, store_ident id),
transl_store (add_ident false id subst) rem)
- | Tstr_module(id, modl) :: rem ->
+ | Tstr_module( id, _, modl) ->
let lam =
transl_module Tcoerce_none (field_path (global_path glob) id) modl in
(* Careful: the module value stored in the global may be different
@@ -403,8 +413,8 @@ let transl_store_structure glob map prims str =
(add_ident true adds id -> Pgetglobal... to subst). *)
Llet(Strict, id, subst_lambda subst lam,
Lsequence(store_ident id, transl_store(add_ident true id subst) rem))
- | Tstr_recmodule bindings :: rem ->
- let ids = List.map fst bindings in
+ | Tstr_recmodule bindings ->
+ let ids = List.map fst4 bindings in
compile_recmodule
(fun id modl ->
subst_lambda subst
@@ -413,23 +423,25 @@ let transl_store_structure glob map prims str =
bindings
(Lsequence(store_idents ids,
transl_store (add_idents true ids subst) rem))
- | Tstr_modtype(id, decl) :: rem ->
+ | Tstr_modtype(id, _, decl) ->
transl_store subst rem
- | Tstr_open path :: rem ->
+ | Tstr_open (path, _) ->
transl_store subst rem
- | Tstr_class cl_list :: rem ->
- let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in
+ | Tstr_class cl_list ->
+ let ids = List.map (fun (ci, _, _) -> ci.ci_id_class) cl_list in
let lam =
Lletrec(List.map
- (fun (id, arity, meths, cl, vf) ->
- (id, transl_class ids id arity meths cl vf))
+ (fun (ci, meths, vf) ->
+ let id = ci.ci_id_class in
+ let cl = ci.ci_expr in
+ (id, transl_class ids id meths cl vf))
cl_list,
store_idents ids) in
Lsequence(subst_lambda subst lam,
transl_store (add_idents false ids subst) rem)
- | Tstr_cltype cl_list :: rem ->
+ | Tstr_class_type cl_list ->
transl_store subst rem
- | Tstr_include(modl, ids) :: rem ->
+ | Tstr_include(modl, ids) ->
let mid = Ident.create "include" in
let rec store_idents pos = function
[] -> transl_store (add_idents true ids subst) rem
@@ -475,23 +487,26 @@ let transl_store_structure glob map prims str =
(* Build the list of value identifiers defined by a toplevel structure
(excluding primitive declarations). *)
-let rec defined_idents = function
+let rec defined_idents items =
+ match items with
[] -> []
- | Tstr_eval expr :: rem -> defined_idents rem
- | Tstr_value(rec_flag, pat_expr_list) :: rem ->
+ | item :: rem ->
+ match item.str_desc with
+ | Tstr_eval expr -> defined_idents rem
+ | Tstr_value(rec_flag, pat_expr_list) ->
let_bound_idents pat_expr_list @ defined_idents rem
- | Tstr_primitive(id, descr) :: rem -> defined_idents rem
- | Tstr_type decls :: rem -> defined_idents rem
- | Tstr_exception(id, decl) :: rem -> id :: defined_idents rem
- | Tstr_exn_rebind(id, path) :: rem -> id :: defined_idents rem
- | Tstr_module(id, modl) :: rem -> id :: defined_idents rem
- | Tstr_recmodule decls :: rem -> List.map fst decls @ defined_idents rem
- | Tstr_modtype(id, decl) :: rem -> defined_idents rem
- | Tstr_open path :: rem -> defined_idents rem
- | Tstr_class cl_list :: rem ->
- List.map (fun (i, _, _, _, _) -> i) cl_list @ defined_idents rem
- | Tstr_cltype cl_list :: rem -> defined_idents rem
- | Tstr_include(modl, ids) :: rem -> ids @ defined_idents rem
+ | Tstr_primitive(id, _, descr) -> defined_idents rem
+ | Tstr_type decls -> defined_idents rem
+ | Tstr_exception(id, _, decl) -> id :: defined_idents rem
+ | Tstr_exn_rebind(id, _, path, _) -> id :: defined_idents rem
+ | Tstr_module(id, _, modl) -> id :: defined_idents rem
+ | Tstr_recmodule decls -> List.map fst4 decls @ defined_idents rem
+ | Tstr_modtype(id, _, decl) -> defined_idents rem
+ | Tstr_open (path, _) -> defined_idents rem
+ | Tstr_class cl_list ->
+ List.map (fun (ci, _, _) -> ci.ci_id_class) cl_list @ defined_idents rem
+ | Tstr_class_type cl_list -> defined_idents rem
+ | Tstr_include(modl, ids) -> ids @ defined_idents rem
(* Transform a coercion and the list of value identifiers defined by
a toplevel structure into a table [id -> (pos, coercion)],
@@ -532,13 +547,13 @@ let build_ident_map restr idlist =
(* Compile an implementation using transl_store_structure
(for the native-code compiler). *)
-let transl_store_gen module_name (str, restr) topl =
+let transl_store_gen module_name ({ str_items = str }, restr) topl =
reset_labels ();
primitive_declarations := [];
let module_id = Ident.create_persistent module_name in
let (map, prims, size) = build_ident_map restr (defined_idents str) in
let f = function
- | [ Tstr_eval expr ] when topl ->
+ | [ { str_desc = Tstr_eval expr } ] when topl ->
assert (size = 0);
subst_lambda !transl_store_subst (transl_exp expr)
| str -> transl_store_structure module_id map prims str in
@@ -589,50 +604,53 @@ let close_toplevel_term lam =
IdentSet.fold (fun id l -> Llet(Strict, id, toploop_getvalue id, l))
(free_variables lam) lam
-let transl_toplevel_item = function
+let transl_toplevel_item item =
+ match item.str_desc with
Tstr_eval expr ->
transl_exp expr
| Tstr_value(rec_flag, pat_expr_list) ->
let idents = let_bound_idents pat_expr_list in
transl_let rec_flag pat_expr_list
(make_sequence toploop_setvalue_id idents)
- | Tstr_primitive(id, descr) ->
+ | Tstr_primitive(id, _, descr) ->
lambda_unit
| Tstr_type(decls) ->
lambda_unit
- | Tstr_exception(id, decl) ->
+ | Tstr_exception(id, _, decl) ->
toploop_setvalue id (transl_exception id None decl)
- | Tstr_exn_rebind(id, path) ->
+ | Tstr_exn_rebind(id, _, path, _) ->
toploop_setvalue id (transl_path path)
- | Tstr_module(id, modl) ->
+ | Tstr_module(id, _, modl) ->
(* we need to use the unique name for the module because of issues
with "open" (PR#1672) *)
set_toplevel_unique_name id;
toploop_setvalue id
(transl_module Tcoerce_none (Some(Pident id)) modl)
| Tstr_recmodule bindings ->
- let idents = List.map fst bindings in
+ let idents = List.map fst4 bindings in
compile_recmodule
(fun id modl -> transl_module Tcoerce_none (Some(Pident id)) modl)
bindings
(make_sequence toploop_setvalue_id idents)
- | Tstr_modtype(id, decl) ->
+ | Tstr_modtype(id, _, decl) ->
lambda_unit
- | Tstr_open path ->
+ | Tstr_open (path, _) ->
lambda_unit
| Tstr_class cl_list ->
(* we need to use unique names for the classes because there might
be a value named identically *)
- let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in
+ let ids = List.map (fun (ci, _, _) -> ci.ci_id_class) cl_list in
List.iter set_toplevel_unique_name ids;
Lletrec(List.map
- (fun (id, arity, meths, cl, vf) ->
- (id, transl_class ids id arity meths cl vf))
+ (fun (ci, meths, vf) ->
+ let id = ci.ci_id_class in
+ let cl = ci.ci_expr in
+ (id, transl_class ids id meths cl vf))
cl_list,
make_sequence
- (fun (id, _, _, _, _) -> toploop_setvalue_id id)
+ (fun (ci, _, _) -> toploop_setvalue_id ci.ci_id_class)
cl_list)
- | Tstr_cltype cl_list ->
+ | Tstr_class_type cl_list ->
lambda_unit
| Tstr_include(modl, ids) ->
let mid = Ident.create "include" in
@@ -649,7 +667,7 @@ let transl_toplevel_item_and_close itm =
let transl_toplevel_definition str =
reset_labels ();
- make_sequence transl_toplevel_item_and_close str
+ make_sequence transl_toplevel_item_and_close str.str_items
(* Compile the initialization code for a packed library *)
diff --git a/camlp4/Camlp4/Printers/OCaml.ml b/camlp4/Camlp4/Printers/OCaml.ml
index 6cd292aba..c1b5f1d90 100644
--- a/camlp4/Camlp4/Printers/OCaml.ml
+++ b/camlp4/Camlp4/Printers/OCaml.ml
@@ -106,8 +106,8 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
"Cannot print %S this identifier does not respect OCaml lexing rules (%s)"
str (Lexer.Error.to_string exn)) ];
- (* This is to be sure character literals are always escaped. *)
- value ocaml_char x = Char.escaped (Struct.Token.Eval.char x);
+ value ocaml_char x =
+ match x with [ "'" -> "\\'" | c -> c ];
value rec get_expr_args a al =
match a with
@@ -557,7 +557,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| <:expr< $int64:s$ >> -> o#numeric f s "L"
| <:expr< $int32:s$ >> -> o#numeric f s "l"
| <:expr< $flo:s$ >> -> o#numeric f s ""
- | <:expr< $chr:s$ >> -> pp f "'%s'" (ocaml_char s)
+ | <:expr< $chr:s$ >> -> pp f "'%s'" s
| <:expr< $id:i$ >> -> o#var_ident f i
| <:expr< { $b$ } >> ->
pp f "@[<hv0>@[<hv2>{%a@]@ }@]" o#record_binding b
@@ -667,7 +667,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| <:patt< $int32:s$ >> -> o#numeric f s "l"
| <:patt< $int:s$ >> -> o#numeric f s ""
| <:patt< $flo:s$ >> -> o#numeric f s ""
- | <:patt< $chr:s$ >> -> pp f "'%s'" (ocaml_char s)
+ | <:patt< $chr:s$ >> -> pp f "'%s'" s
| <:patt< ~ $s$ >> -> pp f "~%s" s
| <:patt< ` $uid:s$ >> -> pp f "`%a" o#var s
| <:patt< # $i$ >> -> pp f "@[<2>#%a@]" o#ident i
diff --git a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
index e73e875ff..2838083fd 100644
--- a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
+++ b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
@@ -57,6 +57,8 @@ module Make (Ast : Sig.Camlp4Ast) = struct
value mkloc = Loc.to_ocaml_location;
value mkghloc loc = Loc.to_ocaml_location (Loc.ghostify loc);
+ value with_loc txt loc = Camlp4_import.Location.mkloc txt (mkloc loc);
+
value mktyp loc d = {ptyp_desc = d; ptyp_loc = mkloc loc};
value mkpat loc d = {ppat_desc = d; ppat_loc = mkloc loc};
value mkghpat loc d = {ppat_desc = d; ppat_loc = mkghloc loc};
@@ -67,7 +69,10 @@ module Make (Ast : Sig.Camlp4Ast) = struct
value mkstr loc d = {pstr_desc = d; pstr_loc = mkloc loc};
value mkfield loc d = {pfield_desc = d; pfield_loc = mkloc loc};
value mkcty loc d = {pcty_desc = d; pcty_loc = mkloc loc};
- value mkpcl loc d = {pcl_desc = d; pcl_loc = mkloc loc};
+ value mkcl loc d = {pcl_desc = d; pcl_loc = mkloc loc};
+ value mkcf loc d = { pcf_desc = d; pcf_loc = mkloc loc; };
+ value mkctf loc d = { pctf_desc = d; pctf_loc = mkloc loc; };
+
value mkpolytype t =
match t.ptyp_desc with
[ Ptyp_poly _ _ -> t
@@ -85,6 +90,9 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| _ -> assert False ];
value lident s = Lident s;
+ value lident_with_loc s loc = with_loc (Lident s) loc;
+
+
value ldot l s = Ldot l s;
value lapply l s = Lapply l s;
@@ -106,17 +114,17 @@ module Make (Ast : Sig.Camlp4Ast) = struct
}
;
- value array_function str name =
+ value array_function_no_loc str name =
ldot (lident str) (if Camlp4_config.unsafe.val then "unsafe_" ^ name else name)
;
-
+ value array_function loc str name = with_loc (array_function_no_loc str name) loc;
value mkrf =
fun
[ <:rec_flag< rec >> -> Recursive
| <:rec_flag<>> -> Nonrecursive
| _ -> assert False ];
- value mkli s = loop lident
+ value mkli sloc s list = with_loc (loop lident list) sloc
where rec loop f =
fun
[ [i :: il] -> loop (ldot (f i)) il
@@ -161,18 +169,20 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| _ -> error (loc_of_ident i) "invalid long identifier" ]
in self i None;
- value ident ?conv_lid i = fst (ident_tag ?conv_lid i);
+ value ident_noloc ?conv_lid i = fst (ident_tag ?conv_lid i);
+ value ident ?conv_lid i =
+ with_loc (ident_noloc ?conv_lid i) (loc_of_ident i);
- value long_lident msg i =
- match ident_tag i with
- [ (i, `lident) -> i
- | _ -> error (loc_of_ident i) msg ]
+ value long_lident msg id =
+ match ident_tag id with
+ [ (i, `lident) -> with_loc i (loc_of_ident id)
+ | _ -> error (loc_of_ident id) msg ]
;
value long_type_ident = long_lident "invalid long identifier type";
value long_class_ident = long_lident "invalid class name";
- value long_uident ?(conv_con = fun x -> x) i =
+ value long_uident_noloc ?(conv_con = fun x -> x) i =
match ident_tag i with
[ (Ldot i s, `uident) -> ldot i (conv_con s)
| (Lident s, `uident) -> lident (conv_con s)
@@ -180,9 +190,12 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| _ -> error (loc_of_ident i) "uppercase identifier expected" ]
;
+ value long_uident ?conv_con i =
+ with_loc (long_uident_noloc ?conv_con i) (loc_of_ident i);
+
value rec ctyp_long_id_prefix t =
match t with
- [ <:ctyp< $id:i$ >> -> ident i
+ [ <:ctyp< $id:i$ >> -> ident_noloc i
| <:ctyp< $m1$ $m2$ >> ->
let li1 = ctyp_long_id_prefix m1 in
let li2 = ctyp_long_id_prefix m2 in
@@ -318,20 +331,21 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| _ -> assert False ];
value mktrecord =
fun
- [ <:ctyp@loc< $lid:s$ : mutable $t$ >> ->
- (s, Mutable, mkpolytype (ctyp t), mkloc loc)
- | <:ctyp@loc< $lid:s$ : $t$ >> ->
- (s, Immutable, mkpolytype (ctyp t), mkloc loc)
+ [ <:ctyp@loc< $id:(<:ident@sloc< $lid:s$ >>)$ : mutable $t$ >> ->
+ (with_loc s sloc, Mutable, mkpolytype (ctyp t), mkloc loc)
+ | <:ctyp@loc< $id:(<:ident@sloc< $lid:s$ >>)$ : $t$ >> ->
+ (with_loc s sloc, Immutable, mkpolytype (ctyp t), mkloc loc)
| _ -> assert False (*FIXME*) ];
value mkvariant =
fun
- [ <:ctyp@loc< $uid:s$ >> -> (conv_con s, [], None, mkloc loc)
- | <:ctyp@loc< $uid:s$ of $t$ >> ->
- (conv_con s, List.map ctyp (list_of_ctyp t []), None, mkloc loc)
- | <:ctyp@loc< $uid:s$ : ($t$ -> $u$) >> ->
- (conv_con s, List.map ctyp (list_of_ctyp t []), Some (ctyp u), mkloc loc)
- | <:ctyp@loc< $uid:s$ : $t$ >> ->
- (conv_con s, [], Some (ctyp t), mkloc loc)
+ [ <:ctyp@loc< $id:(<:ident@sloc< $uid:s$ >>)$ >> ->
+ (with_loc (conv_con s) sloc, [], None, mkloc loc)
+ | <:ctyp@loc< $id:(<:ident@sloc< $uid:s$ >>)$ of $t$ >> ->
+ (with_loc (conv_con s) sloc, List.map ctyp (list_of_ctyp t []), None, mkloc loc)
+ | <:ctyp@loc< $id:(<:ident@sloc< $uid:s$ >>)$ : ($t$ -> $u$) >> ->
+ (with_loc (conv_con s) sloc, List.map ctyp (list_of_ctyp t []), Some (ctyp u), mkloc loc)
+ | <:ctyp@loc< $id:(<:ident@sloc< $uid:s$ >>)$ : $t$ >> ->
+ (with_loc (conv_con s) sloc, [], Some (ctyp t), mkloc loc)
| _ -> assert False (*FIXME*) ];
value rec type_decl tl cl loc m pflag =
@@ -359,7 +373,7 @@ module Make (Ast : Sig.Camlp4Ast) = struct
value type_decl tl cl t loc = type_decl tl cl loc None False t;
- value mkvalue_desc t p = {pval_type = ctyp t; pval_prim = p};
+ value mkvalue_desc loc t p = {pval_type = ctyp t; pval_prim = p; pval_loc = mkloc loc};
value rec list_of_meta_list =
fun
@@ -395,20 +409,20 @@ module Make (Ast : Sig.Camlp4Ast) = struct
value rec optional_type_parameters t acc =
match t with
[ <:ctyp< $t1$ $t2$ >> -> optional_type_parameters t1 (optional_type_parameters t2 acc)
- | <:ctyp< +'$s$ >> -> [(Some s, (True, False)) :: acc]
+ | <:ctyp@loc< +'$s$ >> -> [(Some (with_loc s loc), (True, False)) :: acc]
| Ast.TyAnP _loc -> [(None, (True, False)) :: acc]
- | <:ctyp< -'$s$ >> -> [(Some s, (False, True)) :: acc]
+ | <:ctyp@loc< -'$s$ >> -> [(Some (with_loc s loc), (False, True)) :: acc]
| Ast.TyAnM _loc -> [(None, (False, True)) :: acc]
- | <:ctyp< '$s$ >> -> [(Some s, (False, False)) :: acc]
+ | <:ctyp@loc< '$s$ >> -> [(Some (with_loc s loc), (False, False)) :: acc]
| Ast.TyAny _loc -> [(None, (False, False)) :: acc]
| _ -> assert False ];
value rec class_parameters t acc =
match t with
[ <:ctyp< $t1$, $t2$ >> -> class_parameters t1 (class_parameters t2 acc)
- | <:ctyp< +'$s$ >> -> [(s, (True, False)) :: acc]
- | <:ctyp< -'$s$ >> -> [(s, (False, True)) :: acc]
- | <:ctyp< '$s$ >> -> [(s, (False, False)) :: acc]
+ | <:ctyp@loc< +'$s$ >> -> [(with_loc s loc, (True, False)) :: acc]
+ | <:ctyp@loc< -'$s$ >> -> [(with_loc s loc, (False, True)) :: acc]
+ | <:ctyp@loc< '$s$ >> -> [(with_loc s loc, (False, False)) :: acc]
| _ -> assert False ];
value rec type_parameters_and_type_name t acc =
@@ -470,7 +484,8 @@ module Make (Ast : Sig.Camlp4Ast) = struct
value rec patt =
fun
- [ <:patt@loc< $lid:s$ >> -> mkpat loc (Ppat_var s)
+ [ <:patt@loc< $id:(<:ident@sloc< $lid:s$ >>)$ >> ->
+ mkpat loc (Ppat_var (with_loc s sloc))
| <:patt@loc< $id:i$ >> ->
let p = Ppat_construct (long_uident ~conv_con i)
None (constructors_arity ())
@@ -478,15 +493,15 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| PaAli loc p1 p2 ->
let (p, i) =
match (p1, p2) with
- [ (p, <:patt< $lid:s$ >>) -> (p, s)
- | (<:patt< $lid:s$ >>, p) -> (p, s)
+ [ (p, <:patt< $id:(<:ident@sloc< $lid:s$ >>)$ >>) -> (p, with_loc s sloc)
+ | (<:patt< $id:(<:ident@sloc< $lid:s$ >>)$ >>, p) -> (p, with_loc s sloc)
| _ -> error loc "invalid alias pattern" ]
in
mkpat loc (Ppat_alias (patt p) i)
| PaAnt loc _ -> error loc "antiquotation not allowed here"
| PaAny loc -> mkpat loc Ppat_any
- | <:patt@loc< $uid:s$ ($tup:<:patt@loc_any< _ >>$) >> ->
- mkpat loc (Ppat_construct (lident (conv_con s))
+ | <:patt@loc< $id:(<:ident@sloc< $uid:s$ >>)$ ($tup:<:patt@loc_any< _ >>$) >> ->
+ mkpat loc (Ppat_construct (lident_with_loc (conv_con s) sloc)
(Some (mkpat loc_any Ppat_any)) False)
| PaApp loc _ _ as f ->
let (f, al) = patt_fa [] f in
@@ -560,7 +575,7 @@ module Make (Ast : Sig.Camlp4Ast) = struct
| PaTyp loc i -> mkpat loc (Ppat_type (long_type_ident i))
| PaVrn loc s -> mkpat loc (Ppat_variant (conv_con s) None)
| PaLaz loc p -> mkpat loc (Ppat_lazy (patt p))
- | PaMod loc m -> mkpat loc (Ppat_unpack m)
+ | PaMod loc m -> mkpat loc (Ppat_unpack (with_loc m loc))
| PaEq _ _ _ | PaSem _ _ _ | PaCom _ _ _ | PaNil _ as p ->
error (loc_of_patt p) "invalid pattern" ]
and mklabpat =
@@ -612,9 +627,9 @@ module Make (Ast : Sig.Camlp4Ast) = struct
[ <:ctyp<>> -> acc
| t -> list_of_ctyp t acc ];
-value varify_constructors var_names =
- let rec loop t =
- let desc =
+value varify_constructors var_names =
+ let rec loop t =
+ let desc =
match t.ptyp_desc with
[
Ptyp_any -> Ptyp_any
@@ -622,27 +637,27 @@ value varify_constructors var_names =
| Ptyp_arrow label core_type core_type' ->
Ptyp_arrow label (loop core_type) (loop core_type')
| Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
- | Ptyp_constr (Lident s) [] when List.mem s var_names ->
+ | Ptyp_constr ({ txt = Lident s }) [] when List.mem s var_names ->
Ptyp_var ("&" ^ s)
| Ptyp_constr longident lst ->
- Ptyp_constr longident (List.map loop lst)
+ Ptyp_constr longident (List.map loop lst)
| Ptyp_object lst ->
- Ptyp_object (List.map loop_core_field lst)
+ Ptyp_object (List.map loop_core_field lst)
| Ptyp_class longident lst lbl_list ->
- Ptyp_class (longident, List.map loop lst, lbl_list)
+ Ptyp_class (longident, List.map loop lst, lbl_list)
| Ptyp_alias core_type string ->
- Ptyp_alias(loop core_type, string)
- | Ptyp_variant row_field_list flag lbl_lst_option ->
- Ptyp_variant(List.map loop_row_field row_field_list, flag, lbl_lst_option)
+ Ptyp_alias(loop core_type, string)
+ | Ptyp_variant row_field_list flag lbl_lst_option ->
+ Ptyp_variant(List.map loop_row_field row_field_list, flag, lbl_lst_option)
| Ptyp_poly string_lst core_type ->
- Ptyp_poly(string_lst, loop core_type)
+ Ptyp_poly(string_lst, loop core_type)
| Ptyp_package longident lst ->
Ptyp_package(longident,List.map (fun (n,typ) -> (n,loop typ) ) lst)
]
in
{(t) with ptyp_desc = desc}
- and loop_core_field t =
- let desc =
+ and loop_core_field t =
+ let desc =
match t.pfield_desc with
[ Pfield(n,typ) ->
Pfield(n,loop typ)
@@ -650,10 +665,10 @@ value varify_constructors var_names =
Pfield_var]
in
{ (t) with pfield_desc=desc}
- and loop_row_field x =
+ and loop_row_field x =
match x with
[ Rtag(label,flag,lst) ->
- Rtag(label,flag,List.map loop lst)
+ Rtag(label,flag,List.map loop lst)
| Rinherit t ->
Rinherit (loop t) ]
in
@@ -665,15 +680,15 @@ value varify_constructors var_names =
fun
[ <:expr@loc< $x$.val >> ->
mkexp loc
- (Pexp_apply (mkexp loc (Pexp_ident (Lident "!"))) [("", expr x)])
+ (Pexp_apply (mkexp loc (Pexp_ident (lident_with_loc "!" loc))) [("", expr x)])
| ExAcc loc _ _ | <:expr@loc< $id:<:ident< $_$ . $_$ >>$ >> as e ->
let (e, l) =
match sep_expr_acc [] e with
- [ [(loc, ml, <:expr< $uid:s$ >>) :: l] ->
+ [ [(loc, ml, <:expr@sloc< $uid:s$ >>) :: l] ->
let ca = constructors_arity () in
- (mkexp loc (Pexp_construct (mkli (conv_con s) ml) None ca), l)
- | [(loc, ml, <:expr< $lid:s$ >>) :: l] ->
- (mkexp loc (Pexp_ident (mkli s ml)), l)
+ (mkexp loc (Pexp_construct (mkli sloc (conv_con s) ml) None ca), l)
+ | [(loc, ml, <:expr@sloc< $lid:s$ >>) :: l] ->
+ (mkexp loc (Pexp_ident (mkli sloc s ml)), l)
| [(_, [], e) :: l] -> (expr e, l)
| _ -> error loc "bad ast in expression" ]
in
@@ -681,9 +696,9 @@ value varify_constructors var_names =
List.fold_left
(fun (loc_bp, e1) (loc_ep, ml, e2) ->
match e2 with
- [ <:expr< $lid:s$ >> ->
+ [ <:expr@sloc< $lid:s$ >> ->
let loc = Loc.merge loc_bp loc_ep
- in (loc, mkexp loc (Pexp_field e1 (mkli (conv_lab s) ml)))
+ in (loc, mkexp loc (Pexp_field e1 (mkli sloc (conv_lab s) ml)))
| _ -> error (loc_of_expr e2) "lowercase identifier expected" ])
(loc, e) l
in
@@ -717,7 +732,7 @@ value varify_constructors var_names =
| _ -> mkexp loc (Pexp_apply (expr f) al) ]
| ExAre loc e1 e2 ->
mkexp loc
- (Pexp_apply (mkexp loc (Pexp_ident (array_function "Array" "get")))
+ (Pexp_apply (mkexp loc (Pexp_ident (array_function loc "Array" "get")))
[("", expr e1); ("", expr e2)])
| ExArr loc e -> mkexp loc (Pexp_array (List.map expr (list_of_expr e [])))
| ExAsf loc -> mkexp loc Pexp_assertfalse
@@ -725,19 +740,19 @@ value varify_constructors var_names =
let e =
match e with
[ <:expr@loc< $x$.val >> ->
- Pexp_apply (mkexp loc (Pexp_ident (Lident ":=")))
+ Pexp_apply (mkexp loc (Pexp_ident (lident_with_loc ":=" loc)))
[("", expr x); ("", expr v)]
| ExAcc loc _ _ ->
match (expr e).pexp_desc with
[ Pexp_field e lab -> Pexp_setfield e lab (expr v)
| _ -> error loc "bad record access" ]
- | ExAre _ e1 e2 ->
- Pexp_apply (mkexp loc (Pexp_ident (array_function "Array" "set")))
+ | ExAre loc e1 e2 ->
+ Pexp_apply (mkexp loc (Pexp_ident (array_function loc "Array" "set")))
[("", expr e1); ("", expr e2); ("", expr v)]
- | <:expr< $lid:lab$ >> -> Pexp_setinstvar lab (expr v)
- | ExSte _ e1 e2 ->
+ | <:expr< $id:(<:ident@lloc< $lid:lab$ >>)$ >> -> Pexp_setinstvar (with_loc lab lloc) (expr v)
+ | ExSte loc e1 e2 ->
Pexp_apply
- (mkexp loc (Pexp_ident (array_function "String" "set")))
+ (mkexp loc (Pexp_ident (array_function loc "String" "set")))
[("", expr e1); ("", expr e2); ("", expr v)]
| _ -> error loc "bad left part of assignment" ]
in
@@ -754,7 +769,7 @@ value varify_constructors var_names =
| ExFlo loc s -> mkexp loc (Pexp_constant (Const_float (remove_underscores s)))
| ExFor loc i e1 e2 df el ->
let e3 = ExSeq loc el in
- mkexp loc (Pexp_for i (expr e1) (expr e2) (mkdirection df) (expr e3))
+ mkexp loc (Pexp_for (with_loc i loc) (expr e1) (expr e2) (mkdirection df) (expr e3))
| <:expr@loc< fun [ $PaLab _ lab po$ when $w$ -> $e$ ] >> ->
mkexp loc
(Pexp_function lab None
@@ -790,7 +805,7 @@ value varify_constructors var_names =
| ExLaz loc e -> mkexp loc (Pexp_lazy (expr e))
| ExLet loc rf bi e ->
mkexp loc (Pexp_let (mkrf rf) (binding bi []) (expr e))
- | ExLmd loc i me e -> mkexp loc (Pexp_letmodule i (module_expr me) (expr e))
+ | ExLmd loc i me e -> mkexp loc (Pexp_letmodule (with_loc i loc) (module_expr me) (expr e))
| ExMat loc e a -> mkexp loc (Pexp_match (expr e) (match_case a []))
| ExNew loc id -> mkexp loc (Pexp_new (long_type_ident id))
| ExObj loc po cfl ->
@@ -800,7 +815,7 @@ value varify_constructors var_names =
| p -> p ]
in
let cil = class_str_item cfl [] in
- mkexp loc (Pexp_object (patt p, cil))
+ mkexp loc (Pexp_object { pcstr_pat = patt p; pcstr_fields = cil })
| ExOlb loc _ _ -> error loc "labeled expression not allowed here"
| ExOvr loc iel -> mkexp loc (Pexp_override (mkideexp iel []))
| ExRec loc lel eo ->
@@ -825,7 +840,7 @@ value varify_constructors var_names =
| ExSnd loc e s -> mkexp loc (Pexp_send (expr e) s)
| ExSte loc e1 e2 ->
mkexp loc
- (Pexp_apply (mkexp loc (Pexp_ident (array_function "String" "get")))
+ (Pexp_apply (mkexp loc (Pexp_ident (array_function loc "String" "get")))
[("", expr e1); ("", expr e2)])
| ExStr loc s ->
mkexp loc (Pexp_constant (Const_string (string_of_string_token loc s)))
@@ -835,12 +850,12 @@ value varify_constructors var_names =
| <:expr@loc< ($tup:_$) >> -> error loc "singleton tuple"
| ExTyc loc e t -> mkexp loc (Pexp_constraint (expr e) (Some (ctyp t)) None)
| <:expr@loc< () >> ->
- mkexp loc (Pexp_construct (lident "()") None True)
+ mkexp loc (Pexp_construct (lident_with_loc "()" loc) None True)
| <:expr@loc< $lid:s$ >> ->
- mkexp loc (Pexp_ident (lident s))
+ mkexp loc (Pexp_ident (lident_with_loc s loc))
| <:expr@loc< $uid:s$ >> ->
(* let ca = constructors_arity () in *)
- mkexp loc (Pexp_construct (lident (conv_con s)) None True)
+ mkexp loc (Pexp_construct (lident_with_loc (conv_con s) loc) None True)
| ExVrn loc s -> mkexp loc (Pexp_variant (conv_con s) None)
| ExWhi loc e1 el ->
let e2 = ExSeq loc el in
@@ -875,10 +890,10 @@ value varify_constructors var_names =
match x with
[ <:binding< $x$ and $y$ >> ->
binding x (binding y acc)
- | <:binding@_loc< $lid:bind_name$ = ($e$ : $TyTypePol _ vs ty$) >> ->
+ | <:binding@_loc< $pat:( <:patt@sloc< $lid:bind_name$ >> )$ = ($e$ : $TyTypePol _ vs ty$) >> ->
(* this code is not pretty because it is temporary *)
- let rec id_to_string x =
- match x with
+ let rec id_to_string x =
+ match x with
[ <:ctyp< $lid:x$ >> -> [x]
| <:ctyp< $x$ $y$ >> -> (id_to_string x) @ (id_to_string y)
| _ -> assert False]
@@ -889,15 +904,16 @@ value varify_constructors var_names =
let mkexp = mkexp _loc in
let mkpat = mkpat _loc in
let e = mkexp (Pexp_constraint (expr e) (Some (ctyp ty)) None) in
- let rec mk_newtypes x =
+ let rec mk_newtypes x =
match x with
[ [newtype :: []] -> mkexp (Pexp_newtype(newtype, e))
| [newtype :: newtypes] ->
mkexp(Pexp_newtype (newtype,mk_newtypes newtypes))
| [] -> assert False]
in
- let pat =
- mkpat (Ppat_constraint (mkpat (Ppat_var bind_name), mktyp _loc (Ptyp_poly ampersand_vars ty')))
+ let pat =
+ mkpat (Ppat_constraint (mkpat (Ppat_var (with_loc bind_name sloc)),
+ mktyp _loc (Ptyp_poly ampersand_vars ty')))
in
let e = mk_newtypes vars in
[( pat, e) :: acc]
@@ -928,13 +944,13 @@ value varify_constructors var_names =
[ <:rec_binding<>> -> acc
| <:rec_binding< $x$; $y$ >> ->
mkideexp x (mkideexp y acc)
- | <:rec_binding< $lid:s$ = $e$ >> -> [(s, expr e) :: acc]
+ | <:rec_binding< $id:( <:ident@sloc< $lid:s$ >>)$ = $e$ >> -> [(with_loc s sloc, expr e) :: acc]
| _ -> assert False ]
and mktype_decl x acc =
match x with
[ <:ctyp< $x$ and $y$ >> ->
mktype_decl x (mktype_decl y acc)
- | Ast.TyDcl loc c tl td cl ->
+ | Ast.TyDcl cloc c tl td cl ->
let cl =
List.map
(fun (t1, t2) ->
@@ -942,14 +958,15 @@ value varify_constructors var_names =
(ctyp t1, ctyp t2, mkloc loc))
cl
in
- [(c, type_decl (List.fold_right optional_type_parameters tl []) cl td loc) :: acc]
+ [(with_loc c cloc,
+ type_decl (List.fold_right optional_type_parameters tl []) cl td cloc) :: acc]
| _ -> assert False ]
and module_type =
fun
[ <:module_type@loc<>> -> error loc "abstract/nil module type not allowed here"
| <:module_type@loc< $id:i$ >> -> mkmty loc (Pmty_ident (long_uident i))
| <:module_type@loc< functor ($n$ : $nt$) -> $mt$ >> ->
- mkmty loc (Pmty_functor n (module_type nt) (module_type mt))
+ mkmty loc (Pmty_functor (with_loc n loc) (module_type nt) (module_type mt))
| <:module_type@loc< '$_$ >> -> error loc "module type variable not allowed here"
| <:module_type@loc< sig $sl$ end >> ->
mkmty loc (Pmty_signature (sig_item sl []))
@@ -970,14 +987,14 @@ value varify_constructors var_names =
| <:sig_item< $sg1$; $sg2$ >> -> sig_item sg1 (sig_item sg2 l)
| SgDir _ _ _ -> l
| <:sig_item@loc< exception $uid:s$ >> ->
- [mksig loc (Psig_exception (conv_con s) []) :: l]
+ [mksig loc (Psig_exception (with_loc (conv_con s) loc) []) :: l]
| <:sig_item@loc< exception $uid:s$ of $t$ >> ->
- [mksig loc (Psig_exception (conv_con s)
+ [mksig loc (Psig_exception (with_loc (conv_con s) loc)
(List.map ctyp (list_of_ctyp t []))) :: l]
| SgExc _ _ -> assert False (*FIXME*)
- | SgExt loc n t sl -> [mksig loc (Psig_value n (mkvalue_desc t (list_of_meta_list sl))) :: l]
+ | SgExt loc n t sl -> [mksig loc (Psig_value (with_loc n loc) (mkvalue_desc loc t (list_of_meta_list sl))) :: l]
| SgInc loc mt -> [mksig loc (Psig_include (module_type mt)) :: l]
- | SgMod loc n mt -> [mksig loc (Psig_module n (module_type mt)) :: l]
+ | SgMod loc n mt -> [mksig loc (Psig_module (with_loc n loc) (module_type mt)) :: l]
| SgRecMod loc mb ->
[mksig loc (Psig_recmodule (module_sig_binding mb [])) :: l]
| SgMty loc n mt ->
@@ -986,25 +1003,25 @@ value varify_constructors var_names =
[ MtQuo _ _ -> Pmodtype_abstract
| _ -> Pmodtype_manifest (module_type mt) ]
in
- [mksig loc (Psig_modtype n si) :: l]
+ [mksig loc (Psig_modtype (with_loc n loc) si) :: l]
| SgOpn loc id ->
[mksig loc (Psig_open (long_uident id)) :: l]
| SgTyp loc tdl -> [mksig loc (Psig_type (mktype_decl tdl [])) :: l]
- | SgVal loc n t -> [mksig loc (Psig_value n (mkvalue_desc t [])) :: l]
+ | SgVal loc n t -> [mksig loc (Psig_value (with_loc n loc) (mkvalue_desc loc t [])) :: l]
| <:sig_item@loc< $anti:_$ >> -> error loc "antiquotation in sig_item" ]
and module_sig_binding x acc =
match x with
[ <:module_binding< $x$ and $y$ >> ->
module_sig_binding x (module_sig_binding y acc)
- | <:module_binding< $s$ : $mt$ >> ->
- [(s, module_type mt) :: acc]
+ | <:module_binding@loc< $s$ : $mt$ >> ->
+ [(with_loc s loc, module_type mt) :: acc]
| _ -> assert False ]
and module_str_binding x acc =
match x with
[ <:module_binding< $x$ and $y$ >> ->
module_str_binding x (module_str_binding y acc)
- | <:module_binding< $s$ : $mt$ = $me$ >> ->
- [(s, module_type mt, module_expr me) :: acc]
+ | <:module_binding@loc< $s$ : $mt$ = $me$ >> ->
+ [(with_loc s loc, module_type mt, module_expr me) :: acc]
| _ -> assert False ]
and module_expr =
fun
@@ -1013,7 +1030,7 @@ value varify_constructors var_names =
| <:module_expr@loc< $me1$ $me2$ >> ->
mkmod loc (Pmod_apply (module_expr me1) (module_expr me2))
| <:module_expr@loc< functor ($n$ : $mt$) -> $me$ >> ->
- mkmod loc (Pmod_functor n (module_type mt) (module_expr me))
+ mkmod loc (Pmod_functor (with_loc n loc) (module_type mt) (module_expr me))
| <:module_expr@loc< struct $sl$ end >> ->
mkmod loc (Pmod_structure (str_item sl []))
| <:module_expr@loc< ($me$ : $mt$) >> ->
@@ -1038,22 +1055,22 @@ value varify_constructors var_names =
| <:str_item< $st1$; $st2$ >> -> str_item st1 (str_item st2 l)
| StDir _ _ _ -> l
| <:str_item@loc< exception $uid:s$ >> ->
- [mkstr loc (Pstr_exception (conv_con s) []) :: l ]
+ [mkstr loc (Pstr_exception (with_loc (conv_con s) loc) []) :: l ]
| <:str_item@loc< exception $uid:s$ of $t$ >> ->
- [mkstr loc (Pstr_exception (conv_con s)
+ [mkstr loc (Pstr_exception (with_loc (conv_con s) loc)
(List.map ctyp (list_of_ctyp t []))) :: l ]
| <:str_item@loc< exception $uid:s$ = $i$ >> ->
- [mkstr loc (Pstr_exn_rebind (conv_con s) (ident i)) :: l ]
+ [mkstr loc (Pstr_exn_rebind (with_loc (conv_con s) loc) (ident i)) :: l ]
| <:str_item@loc< exception $uid:_$ of $_$ = $_$ >> ->
error loc "type in exception alias"
| StExc _ _ _ -> assert False (*FIXME*)
| StExp loc e -> [mkstr loc (Pstr_eval (expr e)) :: l]
- | StExt loc n t sl -> [mkstr loc (Pstr_primitive n (mkvalue_desc t (list_of_meta_list sl))) :: l]
+ | StExt loc n t sl -> [mkstr loc (Pstr_primitive (with_loc n loc) (mkvalue_desc loc t (list_of_meta_list sl))) :: l]
| StInc loc me -> [mkstr loc (Pstr_include (module_expr me)) :: l]
- | StMod loc n me -> [mkstr loc (Pstr_module n (module_expr me)) :: l]
+ | StMod loc n me -> [mkstr loc (Pstr_module (with_loc n loc) (module_expr me)) :: l]
| StRecMod loc mb ->
[mkstr loc (Pstr_recmodule (module_str_binding mb [])) :: l]
- | StMty loc n mt -> [mkstr loc (Pstr_modtype n (module_type mt)) :: l]
+ | StMty loc n mt -> [mkstr loc (Pstr_modtype (with_loc n loc) (module_type mt)) :: l]
| StOpn loc id ->
[mkstr loc (Pstr_open (long_uident id)) :: l]
| StTyp loc tdl -> [mkstr loc (Pstr_type (mktype_decl tdl [])) :: l]
@@ -1078,7 +1095,11 @@ value varify_constructors var_names =
| t -> t ]
in
let cil = class_sig_item ctfl [] in
- mkcty loc (Pcty_signature (ctyp t, cil))
+ mkcty loc (Pcty_signature {
+ pcsig_self = ctyp t;
+ pcsig_fields = cil;
+ pcsig_loc = mkloc loc;
+ })
| CtCon loc _ _ _ ->
error loc "invalid virtual class inside a class type"
| CtAnt _ _ | CtEq _ _ _ | CtCol _ _ _ | CtAnd _ _ _ | CtNil _ ->
@@ -1086,7 +1107,7 @@ value varify_constructors var_names =
and class_info_class_expr ci =
match ci with
- [ CeEq _ (CeCon loc vir (IdLid _ name) params) ce ->
+ [ CeEq _ (CeCon loc vir (IdLid nloc name) params) ce ->
let (loc_params, (params, variance)) =
match params with
[ <:ctyp<>> -> (loc, ([], []))
@@ -1094,15 +1115,15 @@ value varify_constructors var_names =
in
{pci_virt = mkvirtual vir;
pci_params = (params, mkloc loc_params);
- pci_name = name;
+ pci_name = with_loc name nloc;
pci_expr = class_expr ce;
pci_loc = mkloc loc;
pci_variance = variance}
| ce -> error (loc_of_class_expr ce) "bad class definition" ]
and class_info_class_type ci =
match ci with
- [ CtEq _ (CtCon loc vir (IdLid _ name) params) ct |
- CtCol _ (CtCon loc vir (IdLid _ name) params) ct ->
+ [ CtEq _ (CtCon loc vir (IdLid nloc name) params) ct |
+ CtCol _ (CtCon loc vir (IdLid nloc name) params) ct ->
let (loc_params, (params, variance)) =
match params with
[ <:ctyp<>> -> (loc, ([], []))
@@ -1110,7 +1131,7 @@ value varify_constructors var_names =
in
{pci_virt = mkvirtual vir;
pci_params = (params, mkloc loc_params);
- pci_name = name;
+ pci_name = with_loc name nloc;
pci_expr = class_type ct;
pci_loc = mkloc loc;
pci_variance = variance}
@@ -1119,39 +1140,39 @@ value varify_constructors var_names =
and class_sig_item c l =
match c with
[ <:class_sig_item<>> -> l
- | CgCtr loc t1 t2 -> [Pctf_cstr (ctyp t1, ctyp t2, mkloc loc) :: l]
+ | CgCtr loc t1 t2 -> [mkctf loc (Pctf_cstr (ctyp t1, ctyp t2)) :: l]
| <:class_sig_item< $csg1$; $csg2$ >> ->
class_sig_item csg1 (class_sig_item csg2 l)
- | CgInh _ ct -> [Pctf_inher (class_type ct) :: l]
+ | CgInh loc ct -> [mkctf loc (Pctf_inher (class_type ct)) :: l]
| CgMth loc s pf t ->
- [Pctf_meth (s, mkprivate pf, mkpolytype (ctyp t), mkloc loc) :: l]
+ [mkctf loc (Pctf_meth (s, mkprivate pf, mkpolytype (ctyp t))) :: l]
| CgVal loc s b v t ->
- [Pctf_val (s, mkmutable b, mkvirtual v, ctyp t, mkloc loc) :: l]
+ [mkctf loc (Pctf_val (s, mkmutable b, mkvirtual v, ctyp t)) :: l]
| CgVir loc s b t ->
- [Pctf_virt (s, mkprivate b, mkpolytype (ctyp t), mkloc loc) :: l]
+ [mkctf loc (Pctf_virt (s, mkprivate b, mkpolytype (ctyp t))) :: l]
| CgAnt _ _ -> assert False ]
and class_expr =
fun
[ CeApp loc _ _ as c ->
let (ce, el) = class_expr_fa [] c in
let el = List.map label_expr el in
- mkpcl loc (Pcl_apply (class_expr ce) el)
+ mkcl loc (Pcl_apply (class_expr ce) el)
| CeCon loc ViNil id tl ->
- mkpcl loc
+ mkcl loc
(Pcl_constr (long_class_ident id) (List.map ctyp (list_of_opt_ctyp tl [])))
| CeFun loc (PaLab _ lab po) ce ->
- mkpcl loc
+ mkcl loc
(Pcl_fun lab None (patt_of_lab loc lab po) (class_expr ce))
| CeFun loc (PaOlbi _ lab p e) ce ->
let lab = paolab lab p in
- mkpcl loc (Pcl_fun ("?" ^ lab) (Some (expr e)) (patt p) (class_expr ce))
+ mkcl loc (Pcl_fun ("?" ^ lab) (Some (expr e)) (patt p) (class_expr ce))
| CeFun loc (PaOlb _ lab p) ce ->
let lab = paolab lab p in
- mkpcl loc
+ mkcl loc
(Pcl_fun ("?" ^ lab) None (patt_of_lab loc lab p) (class_expr ce))
- | CeFun loc p ce -> mkpcl loc (Pcl_fun "" None (patt p) (class_expr ce))
+ | CeFun loc p ce -> mkcl loc (Pcl_fun "" None (patt p) (class_expr ce))
| CeLet loc rf bi ce ->
- mkpcl loc (Pcl_let (mkrf rf) (binding bi []) (class_expr ce))
+ mkcl loc (Pcl_let (mkrf rf) (binding bi []) (class_expr ce))
| CeStr loc po cfl ->
let p =
match po with
@@ -1159,35 +1180,38 @@ value varify_constructors var_names =
| p -> p ]
in
let cil = class_str_item cfl [] in
- mkpcl loc (Pcl_structure (patt p, cil))
+ mkcl loc (Pcl_structure {
+ pcstr_pat = patt p;
+ pcstr_fields = cil;
+ })
| CeTyc loc ce ct ->
- mkpcl loc (Pcl_constraint (class_expr ce) (class_type ct))
+ mkcl loc (Pcl_constraint (class_expr ce) (class_type ct))
| CeCon loc _ _ _ ->
error loc "invalid virtual class inside a class expression"
| CeAnt _ _ | CeEq _ _ _ | CeAnd _ _ _ | CeNil _ -> assert False ]
and class_str_item c l =
match c with
[ CrNil _ -> l
- | CrCtr loc t1 t2 -> [Pcf_cstr (ctyp t1, ctyp t2, mkloc loc) :: l]
+ | CrCtr loc t1 t2 -> [mkcf loc (Pcf_constr (ctyp t1, ctyp t2)) :: l]
| <:class_str_item< $cst1$; $cst2$ >> ->
class_str_item cst1 (class_str_item cst2 l)
| CrInh loc ov ce pb ->
let opb = if pb = "" then None else Some pb in
- [Pcf_inher (override_flag loc ov) (class_expr ce) opb :: l]
- | CrIni _ e -> [Pcf_init (expr e) :: l]
+ [mkcf loc (Pcf_inher (override_flag loc ov) (class_expr ce) opb) :: l]
+ | CrIni loc e -> [mkcf loc (Pcf_init (expr e)) :: l]
| CrMth loc s ov pf e t ->
let t =
match t with
[ <:ctyp<>> -> None
| t -> Some (mkpolytype (ctyp t)) ] in
let e = mkexp loc (Pexp_poly (expr e) t) in
- [Pcf_meth (s, mkprivate pf, override_flag loc ov, e, mkloc loc) :: l]
+ [mkcf loc (Pcf_meth (with_loc s loc, mkprivate pf, override_flag loc ov, e)) :: l]
| CrVal loc s ov mf e ->
- [Pcf_val (s, mkmutable mf, override_flag loc ov, expr e, mkloc loc) :: l]
+ [mkcf loc (Pcf_val (with_loc s loc, mkmutable mf, override_flag loc ov, expr e)) :: l]
| CrVir loc s pf t ->
- [Pcf_virt (s, mkprivate pf, mkpolytype (ctyp t), mkloc loc) :: l]
+ [mkcf loc (Pcf_virt (with_loc s loc, mkprivate pf, mkpolytype (ctyp t))) :: l]
| CrVvr loc s mf t ->
- [Pcf_valvirt (s, mkmutable mf, ctyp t, mkloc loc) :: l]
+ [mkcf loc (Pcf_valvirt (with_loc s loc, mkmutable mf, ctyp t)) :: l]
| CrAnt _ _ -> assert False ];
value sig_item ast = sig_item ast [];
@@ -1200,7 +1224,7 @@ value varify_constructors var_names =
| ExInt _ i -> Pdir_int (int_of_string i)
| <:expr< True >> -> Pdir_bool True
| <:expr< False >> -> Pdir_bool False
- | e -> Pdir_ident (ident (ident_of_expr e)) ]
+ | e -> Pdir_ident (ident_noloc (ident_of_expr e)) ]
;
value phrase =
diff --git a/camlp4/Camlp4/Struct/Token.ml b/camlp4/Camlp4/Struct/Token.ml
index 262072972..701e990d5 100644
--- a/camlp4/Camlp4/Struct/Token.ml
+++ b/camlp4/Camlp4/Struct/Token.ml
@@ -211,7 +211,7 @@ module Eval = struct
| [: `'b' :] -> '\b'
| [: `'\\' :] -> '\\'
| [: `'"' :] -> '"'
- | [: `''' :] -> '''
+ | [: `'\'' :] -> '\''
| [: `' ' :] -> ' '
| [: `('0'..'9' as c1); `('0'..'9' as c2); `('0'..'9' as c3) :] ->
chr (100 * (valch c1) + 10 * (valch c2) + (valch c3))
diff --git a/camlp4/boot/Camlp4.ml b/camlp4/boot/Camlp4.ml
index 3967ba21b..4030702ae 100644
--- a/camlp4/boot/Camlp4.ml
+++ b/camlp4/boot/Camlp4.ml
@@ -81,25 +81,15 @@ module Debug :
let formatter =
let header = "camlp4-debug: " in
- let normal s =
- let rec self from accu =
- try
- let i = String.index_from s from '\n'
- in self (i + 1) ((String.sub s from ((i - from) + 1)) :: accu)
- with
- | Not_found ->
- (String.sub s from ((String.length s) - from)) :: accu
- in String.concat header (List.rev (self 0 [])) in
- let after_new_line str = header ^ (normal str) in
- let f = ref after_new_line in
- let output str chr =
- (output_string out_channel (!f str);
- output_char out_channel chr;
- f := if chr = '\n' then after_new_line else normal)
+ let at_bol = ref true
in
make_formatter
(fun buf pos len ->
- let p = pred len in output (String.sub buf pos p) buf.[pos + p])
+ for i = pos to (pos + len) - 1 do
+ if !at_bol then output_string out_channel header else ();
+ let ch = buf.[i]
+ in (output_char out_channel ch; at_bol := ch = '\n')
+ done)
(fun () -> flush out_channel)
let printf section fmt = fprintf formatter ("%s: " ^^ fmt) section
@@ -424,6 +414,16 @@ module Sig =
(** A signature for locations. *)
module type Loc =
sig
+ (** The type of locations. Note that, as for OCaml locations,
+ character numbers in locations refer to character numbers in the
+ parsed character stream, while line numbers refer to line
+ numbers in the source file. The source file and the parsed
+ character stream differ, for instance, when the parsed character
+ stream contains a line number directive. The line number
+ directive will only update the file-name field and the
+ line-number field of the position. It makes therefore no sense
+ to use character numbers with the source file if the sources
+ contain line number directives. *)
type t
(** Return a start location for the given file name.
@@ -457,7 +457,8 @@ module Sig =
val to_tuple :
t -> (string * int * int * int * int * int * int * bool)
- (** [merge loc1 loc2] Return a location that starts at [loc1] and end at [loc2]. *)
+ (** [merge loc1 loc2] Return a location that starts at [loc1] and end at
+ [loc2]. *)
val merge : t -> t -> t
(** The stop pos becomes equal to the start pos. *)
@@ -488,19 +489,19 @@ module Sig =
(** Return the line number of the ending of this location. *)
val stop_line : t -> int
- (** Returns the number of characters from the begining of the file
+ (** Returns the number of characters from the begining of the stream
to the begining of the line of location's begining. *)
val start_bol : t -> int
- (** Returns the number of characters from the begining of the file
+ (** Returns the number of characters from the begining of the stream
to the begining of the line of location's ending. *)
val stop_bol : t -> int
- (** Returns the number of characters from the begining of the file
+ (** Returns the number of characters from the begining of the stream
of the begining of this location. *)
val start_off : t -> int
- (** Return the number of characters from the begining of the file
+ (** Return the number of characters from the begining of the stream
of the ending of this location. *)
val stop_off : t -> int
@@ -801,6 +802,8 @@ module Sig =
(* source tree. *)
(* *)
(****************************************************************************)
+ (* Note: when you modify these types you must increment
+ ast magic numbers defined in Camlp4_config.ml. *)
type loc =
Loc.
t
@@ -14159,6 +14162,9 @@ module Struct =
let mkghloc loc = Loc.to_ocaml_location (Loc.ghostify loc)
+ let with_loc txt loc =
+ Camlp4_import.Location.mkloc txt (mkloc loc)
+
let mktyp loc d = { ptyp_desc = d; ptyp_loc = mkloc loc; }
let mkpat loc d = { ppat_desc = d; ppat_loc = mkloc loc; }
@@ -14179,7 +14185,11 @@ module Struct =
let mkcty loc d = { pcty_desc = d; pcty_loc = mkloc loc; }
- let mkpcl loc d = { pcl_desc = d; pcl_loc = mkloc loc; }
+ let mkcl loc d = { pcl_desc = d; pcl_loc = mkloc loc; }
+
+ let mkcf loc d = { pcf_desc = d; pcf_loc = mkloc loc; }
+
+ let mkctf loc d = { pctf_desc = d; pctf_loc = mkloc loc; }
let mkpolytype t =
match t.ptyp_desc with
@@ -14200,6 +14210,8 @@ module Struct =
let lident s = Lident s
+ let lident_with_loc s loc = with_loc (Lident s) loc
+
let ldot l s = Ldot (l, s)
let lapply l s = Lapply (l, s)
@@ -14219,20 +14231,23 @@ module Struct =
[ ("val", "contents") ];
fun s -> try Hashtbl.find t s with | Not_found -> s)
- let array_function str name =
+ let array_function_no_loc str name =
ldot (lident str)
(if !Camlp4_config.unsafe then "unsafe_" ^ name else name)
+ let array_function loc str name =
+ with_loc (array_function_no_loc str name) loc
+
let mkrf =
function
| Ast.ReRecursive -> Recursive
| Ast.ReNil -> Nonrecursive
| _ -> assert false
- let mkli s =
+ let mkli sloc s list =
let rec loop f =
function | i :: il -> loop (ldot (f i)) il | [] -> f s
- in loop lident
+ in with_loc (loop lident list) sloc
let rec ctyp_fa al =
function
@@ -14242,6 +14257,9 @@ module Struct =
let ident_tag ?(conv_lid = fun x -> x) i =
let rec self i acc =
match i with
+ | Ast.IdAcc (_, (Ast.IdLid (_, "*predef*")),
+ (Ast.IdLid (_, "option"))) ->
+ ((ldot (lident "*predef*") "option"), `lident)
| Ast.IdAcc (_, i1, i2) -> self i2 (Some (self i1 acc))
| Ast.IdApp (_, i1, i2) ->
let i' =
@@ -14272,27 +14290,33 @@ module Struct =
| _ -> error (loc_of_ident i) "invalid long identifier"
in self i None
- let ident ?conv_lid i = fst (ident_tag ?conv_lid i)
+ let ident_noloc ?conv_lid i = fst (ident_tag ?conv_lid i)
- let long_lident msg i =
- match ident_tag i with
- | (i, `lident) -> i
- | _ -> error (loc_of_ident i) msg
+ let ident ?conv_lid i =
+ with_loc (ident_noloc ?conv_lid i) (loc_of_ident i)
+
+ let long_lident msg id =
+ match ident_tag id with
+ | (i, `lident) -> with_loc i (loc_of_ident id)
+ | _ -> error (loc_of_ident id) msg
let long_type_ident = long_lident "invalid long identifier type"
let long_class_ident = long_lident "invalid class name"
- let long_uident ?(conv_con = fun x -> x) i =
+ let long_uident_noloc ?(conv_con = fun x -> x) i =
match ident_tag i with
| (Ldot (i, s), `uident) -> ldot i (conv_con s)
| (Lident s, `uident) -> lident (conv_con s)
| (i, `app) -> i
| _ -> error (loc_of_ident i) "uppercase identifier expected"
+ let long_uident ?conv_con i =
+ with_loc (long_uident_noloc ?conv_con i) (loc_of_ident i)
+
let rec ctyp_long_id_prefix t =
match t with
- | Ast.TyId (_, i) -> ident i
+ | Ast.TyId (_, i) -> ident_noloc i
| Ast.TyApp (_, m1, m2) ->
let li1 = ctyp_long_id_prefix m1 in
let li2 = ctyp_long_id_prefix m2 in Lapply (li1, li2)
@@ -14312,6 +14336,13 @@ module Struct =
| Ast.TyQuo (_, s) -> [ s ]
| _ -> assert false
+ let predef_option loc =
+ TyId
+ ((loc,
+ (IdAcc
+ ((loc, (IdLid ((loc, "*predef*"))),
+ (IdLid ((loc, "option"))))))))
+
let rec ctyp =
function
| TyId (loc, i) ->
@@ -14335,9 +14366,7 @@ module Struct =
| TyArr (loc, (TyLab (_, lab, t1)), t2) ->
mktyp loc (Ptyp_arrow (lab, (ctyp t1), (ctyp t2)))
| TyArr (loc, (TyOlb (loc1, lab, t1)), t2) ->
- let t1 =
- TyApp (loc1,
- (Ast.TyId (loc1, (Ast.IdLid (loc1, "option")))), t1)
+ let t1 = TyApp (loc1, (predef_option loc1), t1)
in
mktyp loc
(Ptyp_arrow (("?" ^ lab), (ctyp t1), (ctyp t2)))
@@ -14421,8 +14450,8 @@ module Struct =
and package_type_constraints wc acc =
match wc with
| Ast.WcNil _ -> acc
- | Ast.WcTyp (_, (Ast.TyId (_, (Ast.IdLid (_, id)))), ct) ->
- (Lident id, (ctyp ct)) :: acc
+ | Ast.WcTyp (_, (Ast.TyId (_, id)), ct) ->
+ ((ident id), (ctyp ct)) :: acc
| Ast.WcAnd (_, wc1, wc2) ->
package_type_constraints wc1
(package_type_constraints wc2 acc)
@@ -14459,26 +14488,30 @@ module Struct =
let mktrecord =
function
- | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (_, s)))),
+ | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (sloc, s)))),
(Ast.TyMut (_, t))) ->
- (s, Mutable, (mkpolytype (ctyp t)), (mkloc loc))
- | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (_, s)))), t) ->
- (s, Immutable, (mkpolytype (ctyp t)), (mkloc loc))
+ ((with_loc s sloc), Mutable, (mkpolytype (ctyp t)),
+ (mkloc loc))
+ | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (sloc, s)))), t) ->
+ ((with_loc s sloc), Immutable, (mkpolytype (ctyp t)),
+ (mkloc loc))
| _ -> assert false
let mkvariant =
function
- | Ast.TyId (loc, (Ast.IdUid (_, s))) ->
- ((conv_con s), [], None, (mkloc loc))
- | Ast.TyOf (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))), t) ->
- ((conv_con s), (List.map ctyp (list_of_ctyp t [])), None,
- (mkloc loc))
- | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))),
+ | Ast.TyId (loc, (Ast.IdUid (sloc, s))) ->
+ ((with_loc (conv_con s) sloc), [], None, (mkloc loc))
+ | Ast.TyOf (loc, (Ast.TyId (_, (Ast.IdUid (sloc, s)))), t) ->
+ ((with_loc (conv_con s) sloc),
+ (List.map ctyp (list_of_ctyp t [])), None, (mkloc loc))
+ | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdUid (sloc, s)))),
(Ast.TyArr (_, t, u))) ->
- ((conv_con s), (List.map ctyp (list_of_ctyp t [])),
- (Some (ctyp u)), (mkloc loc))
- | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))), t) ->
- ((conv_con s), [], (Some (ctyp t)), (mkloc loc))
+ ((with_loc (conv_con s) sloc),
+ (List.map ctyp (list_of_ctyp t [])), (Some (ctyp u)),
+ (mkloc loc))
+ | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdUid (sloc, s)))), t) ->
+ ((with_loc (conv_con s) sloc), [], (Some (ctyp t)),
+ (mkloc loc))
| _ -> assert false
let rec type_decl tl cl loc m pflag =
@@ -14505,10 +14538,10 @@ module Struct =
| _ -> Some (ctyp t)
in mktype loc tl cl Ptype_abstract (mkprivate' pflag) m)
- let type_decl tl cl t =
- type_decl tl cl (loc_of_ctyp t) None false t
+ let type_decl tl cl t loc = type_decl tl cl loc None false t
- let mkvalue_desc t p = { pval_type = ctyp t; pval_prim = p; }
+ let mkvalue_desc loc t p =
+ { pval_type = ctyp t; pval_prim = p; pval_loc = mkloc loc; }
let rec list_of_meta_list =
function
@@ -14550,11 +14583,14 @@ module Struct =
| Ast.TyApp (_, t1, t2) ->
optional_type_parameters t1
(optional_type_parameters t2 acc)
- | Ast.TyQuP (_, s) -> ((Some s), (true, false)) :: acc
+ | Ast.TyQuP (loc, s) ->
+ ((Some (with_loc s loc)), (true, false)) :: acc
| Ast.TyAnP _loc -> (None, (true, false)) :: acc
- | Ast.TyQuM (_, s) -> ((Some s), (false, true)) :: acc
+ | Ast.TyQuM (loc, s) ->
+ ((Some (with_loc s loc)), (false, true)) :: acc
| Ast.TyAnM _loc -> (None, (false, true)) :: acc
- | Ast.TyQuo (_, s) -> ((Some s), (false, false)) :: acc
+ | Ast.TyQuo (loc, s) ->
+ ((Some (with_loc s loc)), (false, false)) :: acc
| Ast.TyAny _loc -> (None, (false, false)) :: acc
| _ -> assert false
@@ -14562,9 +14598,12 @@ module Struct =
match t with
| Ast.TyCom (_, t1, t2) ->
class_parameters t1 (class_parameters t2 acc)
- | Ast.TyQuP (_, s) -> (s, (true, false)) :: acc
- | Ast.TyQuM (_, s) -> (s, (false, true)) :: acc
- | Ast.TyQuo (_, s) -> (s, (false, false)) :: acc
+ | Ast.TyQuP (loc, s) ->
+ ((with_loc s loc), (true, false)) :: acc
+ | Ast.TyQuM (loc, s) ->
+ ((with_loc s loc), (false, true)) :: acc
+ | Ast.TyQuo (loc, s) ->
+ ((with_loc s loc), (false, false)) :: acc
| _ -> assert false
let rec type_parameters_and_type_name t acc =
@@ -14636,7 +14675,8 @@ module Struct =
let rec patt =
function
- | Ast.PaId (loc, (Ast.IdLid (_, s))) -> mkpat loc (Ppat_var s)
+ | Ast.PaId (loc, (Ast.IdLid (sloc, s))) ->
+ mkpat loc (Ppat_var (with_loc s sloc))
| Ast.PaId (loc, i) ->
let p =
Ppat_construct ((long_uident ~conv_con i), None,
@@ -14645,16 +14685,18 @@ module Struct =
| PaAli (loc, p1, p2) ->
let (p, i) =
(match (p1, p2) with
- | (p, Ast.PaId (_, (Ast.IdLid (_, s)))) -> (p, s)
- | (Ast.PaId (_, (Ast.IdLid (_, s))), p) -> (p, s)
+ | (p, Ast.PaId (_, (Ast.IdLid (sloc, s)))) ->
+ (p, (with_loc s sloc))
+ | (Ast.PaId (_, (Ast.IdLid (sloc, s))), p) ->
+ (p, (with_loc s sloc))
| _ -> error loc "invalid alias pattern")
in mkpat loc (Ppat_alias ((patt p), i))
| PaAnt (loc, _) -> error loc "antiquotation not allowed here"
| PaAny loc -> mkpat loc Ppat_any
- | Ast.PaApp (loc, (Ast.PaId (_, (Ast.IdUid (_, s)))),
+ | Ast.PaApp (loc, (Ast.PaId (_, (Ast.IdUid (sloc, s)))),
(Ast.PaTup (_, (Ast.PaAny loc_any)))) ->
mkpat loc
- (Ppat_construct ((lident (conv_con s)),
+ (Ppat_construct ((lident_with_loc (conv_con s) sloc),
(Some (mkpat loc_any Ppat_any)), false))
| (PaApp (loc, _, _) as f) ->
let (f, al) = patt_fa [] f in
@@ -14762,9 +14804,10 @@ module Struct =
| PaTyc (loc, p, t) ->
mkpat loc (Ppat_constraint ((patt p), (ctyp t)))
| PaTyp (loc, i) -> mkpat loc (Ppat_type (long_type_ident i))
- | PaVrn (loc, s) -> mkpat loc (Ppat_variant (s, None))
+ | PaVrn (loc, s) ->
+ mkpat loc (Ppat_variant ((conv_con s), None))
| PaLaz (loc, p) -> mkpat loc (Ppat_lazy (patt p))
- | PaMod (loc, m) -> mkpat loc (Ppat_unpack m)
+ | PaMod (loc, m) -> mkpat loc (Ppat_unpack (with_loc m loc))
| (PaEq (_, _, _) | PaSem (_, _, _) | PaCom (_, _, _) | PaNil _
as p) -> error (loc_of_patt p) "invalid pattern"
and mklabpat =
@@ -14824,8 +14867,8 @@ module Struct =
| Ptyp_arrow (label, core_type, core_type') ->
Ptyp_arrow (label, (loop core_type), (loop core_type'))
| Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
- | Ptyp_constr ((Lident s), []) when List.mem s var_names ->
- Ptyp_var ("&" ^ s)
+ | Ptyp_constr ({ txt = Lident s }, []) when
+ List.mem s var_names -> Ptyp_var ("&" ^ s)
| Ptyp_constr (longident, lst) ->
Ptyp_constr (longident, (List.map loop lst))
| Ptyp_object lst ->
@@ -14862,33 +14905,35 @@ module Struct =
function
| Ast.ExAcc (loc, x, (Ast.ExId (_, (Ast.IdLid (_, "val"))))) ->
mkexp loc
- (Pexp_apply ((mkexp loc (Pexp_ident (Lident "!"))),
+ (Pexp_apply
+ ((mkexp loc (Pexp_ident (lident_with_loc "!" loc))),
[ ("", (expr x)) ]))
| (ExAcc (loc, _, _) | Ast.ExId (loc, (Ast.IdAcc (_, _, _))) as
e) ->
let (e, l) =
(match sep_expr_acc [] e with
- | (loc, ml, Ast.ExId (_, (Ast.IdUid (_, s)))) :: l ->
+ | (loc, ml, Ast.ExId (sloc, (Ast.IdUid (_, s)))) :: l ->
let ca = constructors_arity ()
in
((mkexp loc
- (Pexp_construct ((mkli (conv_con s) ml), None,
- ca))),
+ (Pexp_construct ((mkli sloc (conv_con s) ml),
+ None, ca))),
l)
- | (loc, ml, Ast.ExId (_, (Ast.IdLid (_, s)))) :: l ->
- ((mkexp loc (Pexp_ident (mkli s ml))), l)
+ | (loc, ml, Ast.ExId (sloc, (Ast.IdLid (_, s)))) :: l ->
+ ((mkexp loc (Pexp_ident (mkli sloc s ml))), l)
| (_, [], e) :: l -> ((expr e), l)
| _ -> error loc "bad ast in expression") in
let (_, e) =
List.fold_left
(fun (loc_bp, e1) (loc_ep, ml, e2) ->
match e2 with
- | Ast.ExId (_, (Ast.IdLid (_, s))) ->
+ | Ast.ExId (sloc, (Ast.IdLid (_, s))) ->
let loc = Loc.merge loc_bp loc_ep
in
(loc,
(mkexp loc
- (Pexp_field (e1, (mkli (conv_lab s) ml)))))
+ (Pexp_field (e1,
+ (mkli sloc (conv_lab s) ml)))))
| _ ->
error (loc_of_expr e2)
"lowercase identifier expected")
@@ -14931,7 +14976,7 @@ module Struct =
mkexp loc
(Pexp_apply
((mkexp loc
- (Pexp_ident (array_function "Array" "get"))),
+ (Pexp_ident (array_function loc "Array" "get"))),
[ ("", (expr e1)); ("", (expr e2)) ]))
| ExArr (loc, e) ->
mkexp loc (Pexp_array (List.map expr (list_of_expr e [])))
@@ -14941,24 +14986,27 @@ module Struct =
(match e with
| Ast.ExAcc (loc, x,
(Ast.ExId (_, (Ast.IdLid (_, "val"))))) ->
- Pexp_apply ((mkexp loc (Pexp_ident (Lident ":="))),
+ Pexp_apply
+ ((mkexp loc
+ (Pexp_ident (lident_with_loc ":=" loc))),
[ ("", (expr x)); ("", (expr v)) ])
| ExAcc (loc, _, _) ->
(match (expr e).pexp_desc with
| Pexp_field (e, lab) ->
Pexp_setfield (e, lab, (expr v))
| _ -> error loc "bad record access")
- | ExAre (_, e1, e2) ->
+ | ExAre (loc, e1, e2) ->
Pexp_apply
((mkexp loc
- (Pexp_ident (array_function "Array" "set"))),
+ (Pexp_ident (array_function loc "Array" "set"))),
[ ("", (expr e1)); ("", (expr e2)); ("", (expr v)) ])
- | Ast.ExId (_, (Ast.IdLid (_, lab))) ->
- Pexp_setinstvar (lab, (expr v))
- | ExSte (_, e1, e2) ->
+ | Ast.ExId (_, (Ast.IdLid (lloc, lab))) ->
+ Pexp_setinstvar ((with_loc lab lloc), (expr v))
+ | ExSte (loc, e1, e2) ->
Pexp_apply
((mkexp loc
- (Pexp_ident (array_function "String" "set"))),
+ (Pexp_ident
+ (array_function loc "String" "set"))),
[ ("", (expr e1)); ("", (expr e2)); ("", (expr v)) ])
| _ -> error loc "bad left part of assignment")
in mkexp loc e
@@ -14979,8 +15027,8 @@ module Struct =
let e3 = ExSeq (loc, el)
in
mkexp loc
- (Pexp_for (i, (expr e1), (expr e2), (mkdirection df),
- (expr e3)))
+ (Pexp_for ((with_loc i loc), (expr e1), (expr e2),
+ (mkdirection df), (expr e3)))
| Ast.ExFun (loc, (Ast.McArr (_, (PaLab (_, lab, po)), w, e)))
->
mkexp loc
@@ -15043,7 +15091,9 @@ module Struct =
| ExLet (loc, rf, bi, e) ->
mkexp loc (Pexp_let ((mkrf rf), (binding bi []), (expr e)))
| ExLmd (loc, i, me, e) ->
- mkexp loc (Pexp_letmodule (i, (module_expr me), (expr e)))
+ mkexp loc
+ (Pexp_letmodule ((with_loc i loc), (module_expr me),
+ (expr e)))
| ExMat (loc, e, a) ->
mkexp loc (Pexp_match ((expr e), (match_case a [])))
| ExNew (loc, id) -> mkexp loc (Pexp_new (long_type_ident id))
@@ -15051,7 +15101,10 @@ module Struct =
let p =
(match po with | Ast.PaNil _ -> Ast.PaAny loc | p -> p) in
let cil = class_str_item cfl []
- in mkexp loc (Pexp_object (((patt p), cil)))
+ in
+ mkexp loc
+ (Pexp_object
+ { pcstr_pat = patt p; pcstr_fields = cil; })
| ExOlb (loc, _, _) ->
error loc "labeled expression not allowed here"
| ExOvr (loc, iel) ->
@@ -15079,7 +15132,7 @@ module Struct =
mkexp loc
(Pexp_apply
((mkexp loc
- (Pexp_ident (array_function "String" "get"))),
+ (Pexp_ident (array_function loc "String" "get"))),
[ ("", (expr e1)); ("", (expr e2)) ]))
| ExStr (loc, s) ->
mkexp loc
@@ -15096,13 +15149,16 @@ module Struct =
mkexp loc
(Pexp_constraint ((expr e), (Some (ctyp t)), None))
| Ast.ExId (loc, (Ast.IdUid (_, "()"))) ->
- mkexp loc (Pexp_construct ((lident "()"), None, true))
+ mkexp loc
+ (Pexp_construct ((lident_with_loc "()" loc), None, true))
| Ast.ExId (loc, (Ast.IdLid (_, s))) ->
- mkexp loc (Pexp_ident (lident s))
+ mkexp loc (Pexp_ident (lident_with_loc s loc))
| Ast.ExId (loc, (Ast.IdUid (_, s))) ->
mkexp loc
- (Pexp_construct ((lident (conv_con s)), None, true))
- | ExVrn (loc, s) -> mkexp loc (Pexp_variant (s, None))
+ (Pexp_construct ((lident_with_loc (conv_con s) loc),
+ None, true))
+ | ExVrn (loc, s) ->
+ mkexp loc (Pexp_variant ((conv_con s), None))
| ExWhi (loc, e1, el) ->
let e2 = ExSeq (loc, el)
in mkexp loc (Pexp_while ((expr e1), (expr e2)))
@@ -15142,7 +15198,8 @@ module Struct =
and binding x acc =
match x with
| Ast.BiAnd (_, x, y) -> binding x (binding y acc)
- | Ast.BiEq (_loc, (Ast.PaId (_, (Ast.IdLid (_, bind_name)))),
+ | Ast.BiEq (_loc,
+ (Ast.PaId (sloc, (Ast.IdLid (_, bind_name)))),
(Ast.ExTyc (_, e, (TyTypePol (_, vs, ty))))) ->
let rec id_to_string x =
(match x with
@@ -15152,11 +15209,6 @@ module Struct =
| _ -> assert false) in
let vars = id_to_string vs in
let ampersand_vars = List.map (fun x -> "&" ^ x) vars in
- let rec merge_quoted_vars lst =
- (match lst with
- | [ x ] -> x
- | x :: y -> Ast.TyApp (_loc, x, (merge_quoted_vars y))
- | [] -> assert false) in
let ty' = varify_constructors vars (ctyp ty) in
let mkexp = mkexp _loc in
let mkpat = mkpat _loc in
@@ -15173,7 +15225,7 @@ module Struct =
let pat =
mkpat
(Ppat_constraint
- (((mkpat (Ppat_var bind_name)),
+ (((mkpat (Ppat_var (with_loc bind_name sloc))),
(mktyp _loc (Ptyp_poly (ampersand_vars, ty')))))) in
let e = mk_newtypes vars in (pat, e) :: acc
| Ast.BiEq (_loc, p,
@@ -15203,12 +15255,13 @@ module Struct =
match x with
| Ast.RbNil _ -> acc
| Ast.RbSem (_, x, y) -> mkideexp x (mkideexp y acc)
- | Ast.RbEq (_, (Ast.IdLid (_, s)), e) -> (s, (expr e)) :: acc
+ | Ast.RbEq (_, (Ast.IdLid (sloc, s)), e) ->
+ ((with_loc s sloc), (expr e)) :: acc
| _ -> assert false
and mktype_decl x acc =
match x with
| Ast.TyAnd (_, x, y) -> mktype_decl x (mktype_decl y acc)
- | Ast.TyDcl (_, c, tl, td, cl) ->
+ | Ast.TyDcl (cloc, c, tl, td, cl) ->
let cl =
List.map
(fun (t1, t2) ->
@@ -15217,10 +15270,10 @@ module Struct =
in ((ctyp t1), (ctyp t2), (mkloc loc)))
cl
in
- (c,
+ ((with_loc c cloc),
(type_decl
(List.fold_right optional_type_parameters tl []) cl
- td)) ::
+ td cloc)) ::
acc
| _ -> assert false
and module_type =
@@ -15230,7 +15283,8 @@ module Struct =
| Ast.MtId (loc, i) -> mkmty loc (Pmty_ident (long_uident i))
| Ast.MtFun (loc, n, nt, mt) ->
mkmty loc
- (Pmty_functor (n, (module_type nt), (module_type mt)))
+ (Pmty_functor ((with_loc n loc), (module_type nt),
+ (module_type mt)))
| Ast.MtQuo (loc, _) ->
error loc "module type variable not allowed here"
| Ast.MtSig (loc, sl) ->
@@ -15258,22 +15312,27 @@ module Struct =
| Ast.SgSem (_, sg1, sg2) -> sig_item sg1 (sig_item sg2 l)
| SgDir (_, _, _) -> l
| Ast.SgExc (loc, (Ast.TyId (_, (Ast.IdUid (_, s))))) ->
- (mksig loc (Psig_exception ((conv_con s), []))) :: l
+ (mksig loc
+ (Psig_exception ((with_loc (conv_con s) loc), []))) ::
+ l
| Ast.SgExc (loc,
(Ast.TyOf (_, (Ast.TyId (_, (Ast.IdUid (_, s)))), t))) ->
(mksig loc
- (Psig_exception ((conv_con s),
+ (Psig_exception ((with_loc (conv_con s) loc),
(List.map ctyp (list_of_ctyp t []))))) ::
l
| SgExc (_, _) -> assert false
| SgExt (loc, n, t, sl) ->
(mksig loc
- (Psig_value (n, (mkvalue_desc t (list_of_meta_list sl))))) ::
+ (Psig_value ((with_loc n loc),
+ (mkvalue_desc loc t (list_of_meta_list sl))))) ::
l
| SgInc (loc, mt) ->
(mksig loc (Psig_include (module_type mt))) :: l
| SgMod (loc, n, mt) ->
- (mksig loc (Psig_module (n, (module_type mt)))) :: l
+ (mksig loc
+ (Psig_module ((with_loc n loc), (module_type mt)))) ::
+ l
| SgRecMod (loc, mb) ->
(mksig loc (Psig_recmodule (module_sig_binding mb []))) ::
l
@@ -15282,26 +15341,30 @@ module Struct =
(match mt with
| MtQuo (_, _) -> Pmodtype_abstract
| _ -> Pmodtype_manifest (module_type mt))
- in (mksig loc (Psig_modtype (n, si))) :: l
+ in (mksig loc (Psig_modtype ((with_loc n loc), si))) :: l
| SgOpn (loc, id) ->
(mksig loc (Psig_open (long_uident id))) :: l
| SgTyp (loc, tdl) ->
(mksig loc (Psig_type (mktype_decl tdl []))) :: l
| SgVal (loc, n, t) ->
- (mksig loc (Psig_value (n, (mkvalue_desc t [])))) :: l
+ (mksig loc
+ (Psig_value ((with_loc n loc), (mkvalue_desc loc t [])))) ::
+ l
| Ast.SgAnt (loc, _) -> error loc "antiquotation in sig_item"
and module_sig_binding x acc =
match x with
| Ast.MbAnd (_, x, y) ->
module_sig_binding x (module_sig_binding y acc)
- | Ast.MbCol (_, s, mt) -> (s, (module_type mt)) :: acc
+ | Ast.MbCol (loc, s, mt) ->
+ ((with_loc s loc), (module_type mt)) :: acc
| _ -> assert false
and module_str_binding x acc =
match x with
| Ast.MbAnd (_, x, y) ->
module_str_binding x (module_str_binding y acc)
- | Ast.MbColEq (_, s, mt, me) ->
- (s, (module_type mt), (module_expr me)) :: acc
+ | Ast.MbColEq (loc, s, mt, me) ->
+ ((with_loc s loc), (module_type mt), (module_expr me)) ::
+ acc
| _ -> assert false
and module_expr =
function
@@ -15312,7 +15375,8 @@ module Struct =
(Pmod_apply ((module_expr me1), (module_expr me2)))
| Ast.MeFun (loc, n, mt, me) ->
mkmod loc
- (Pmod_functor (n, (module_type mt), (module_expr me)))
+ (Pmod_functor ((with_loc n loc), (module_type mt),
+ (module_expr me)))
| Ast.MeStr (loc, sl) ->
mkmod loc (Pmod_structure (str_item sl []))
| Ast.MeTyc (loc, me, mt) ->
@@ -15349,17 +15413,21 @@ module Struct =
| StDir (_, _, _) -> l
| Ast.StExc (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))), Ast.
ONone) ->
- (mkstr loc (Pstr_exception ((conv_con s), []))) :: l
+ (mkstr loc
+ (Pstr_exception ((with_loc (conv_con s) loc), []))) ::
+ l
| Ast.StExc (loc,
(Ast.TyOf (_, (Ast.TyId (_, (Ast.IdUid (_, s)))), t)), Ast.
ONone) ->
(mkstr loc
- (Pstr_exception ((conv_con s),
+ (Pstr_exception ((with_loc (conv_con s) loc),
(List.map ctyp (list_of_ctyp t []))))) ::
l
| Ast.StExc (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))),
(Ast.OSome i)) ->
- (mkstr loc (Pstr_exn_rebind ((conv_con s), (ident i)))) ::
+ (mkstr loc
+ (Pstr_exn_rebind ((with_loc (conv_con s) loc),
+ (ident i)))) ::
l
| Ast.StExc (loc,
(Ast.TyOf (_, (Ast.TyId (_, (Ast.IdUid (_, _)))), _)),
@@ -15368,18 +15436,22 @@ module Struct =
| StExp (loc, e) -> (mkstr loc (Pstr_eval (expr e))) :: l
| StExt (loc, n, t, sl) ->
(mkstr loc
- (Pstr_primitive (n,
- (mkvalue_desc t (list_of_meta_list sl))))) ::
+ (Pstr_primitive ((with_loc n loc),
+ (mkvalue_desc loc t (list_of_meta_list sl))))) ::
l
| StInc (loc, me) ->
(mkstr loc (Pstr_include (module_expr me))) :: l
| StMod (loc, n, me) ->
- (mkstr loc (Pstr_module (n, (module_expr me)))) :: l
+ (mkstr loc
+ (Pstr_module ((with_loc n loc), (module_expr me)))) ::
+ l
| StRecMod (loc, mb) ->
(mkstr loc (Pstr_recmodule (module_str_binding mb []))) ::
l
| StMty (loc, n, mt) ->
- (mkstr loc (Pstr_modtype (n, (module_type mt)))) :: l
+ (mkstr loc
+ (Pstr_modtype ((with_loc n loc), (module_type mt)))) ::
+ l
| StOpn (loc, id) ->
(mkstr loc (Pstr_open (long_uident id))) :: l
| StTyp (loc, tdl) ->
@@ -15396,9 +15468,7 @@ module Struct =
| CtFun (loc, (TyLab (_, lab, t)), ct) ->
mkcty loc (Pcty_fun (lab, (ctyp t), (class_type ct)))
| CtFun (loc, (TyOlb (loc1, lab, t)), ct) ->
- let t =
- TyApp (loc1,
- (Ast.TyId (loc1, (Ast.IdLid (loc1, "option")))), t)
+ let t = TyApp (loc1, (predef_option loc1), t)
in
mkcty loc
(Pcty_fun (("?" ^ lab), (ctyp t), (class_type ct)))
@@ -15408,15 +15478,22 @@ module Struct =
let t =
(match t_o with | Ast.TyNil _ -> Ast.TyAny loc | t -> t) in
let cil = class_sig_item ctfl []
- in mkcty loc (Pcty_signature (((ctyp t), cil)))
+ in
+ mkcty loc
+ (Pcty_signature
+ {
+ pcsig_self = ctyp t;
+ pcsig_fields = cil;
+ pcsig_loc = mkloc loc;
+ })
| CtCon (loc, _, _, _) ->
error loc "invalid virtual class inside a class type"
| CtAnt (_, _) | CtEq (_, _, _) | CtCol (_, _, _) |
CtAnd (_, _, _) | CtNil _ -> assert false
and class_info_class_expr ci =
match ci with
- | CeEq (_, (CeCon (loc, vir, (IdLid (_, name)), params)), ce)
- ->
+ | CeEq (_, (CeCon (loc, vir, (IdLid (nloc, name)), params)),
+ ce) ->
let (loc_params, (params, variance)) =
(match params with
| Ast.TyNil _ -> (loc, ([], []))
@@ -15427,7 +15504,7 @@ module Struct =
{
pci_virt = mkvirtual vir;
pci_params = (params, (mkloc loc_params));
- pci_name = name;
+ pci_name = with_loc name nloc;
pci_expr = class_expr ce;
pci_loc = mkloc loc;
pci_variance = variance;
@@ -15435,8 +15512,9 @@ module Struct =
| ce -> error (loc_of_class_expr ce) "bad class definition"
and class_info_class_type ci =
match ci with
- | CtEq (_, (CtCon (loc, vir, (IdLid (_, name)), params)), ct) |
- CtCol (_, (CtCon (loc, vir, (IdLid (_, name)), params)),
+ | CtEq (_, (CtCon (loc, vir, (IdLid (nloc, name)), params)),
+ ct) |
+ CtCol (_, (CtCon (loc, vir, (IdLid (nloc, name)), params)),
ct)
->
let (loc_params, (params, variance)) =
@@ -15449,7 +15527,7 @@ module Struct =
{
pci_virt = mkvirtual vir;
pci_params = (params, (mkloc loc_params));
- pci_name = name;
+ pci_name = with_loc name nloc;
pci_expr = class_type ct;
pci_loc = mkloc loc;
pci_variance = variance;
@@ -15461,22 +15539,22 @@ module Struct =
match c with
| Ast.CgNil _ -> l
| CgCtr (loc, t1, t2) ->
- (Pctf_cstr (((ctyp t1), (ctyp t2), (mkloc loc)))) :: l
+ (mkctf loc (Pctf_cstr (((ctyp t1), (ctyp t2))))) :: l
| Ast.CgSem (_, csg1, csg2) ->
class_sig_item csg1 (class_sig_item csg2 l)
- | CgInh (_, ct) -> (Pctf_inher (class_type ct)) :: l
+ | CgInh (loc, ct) ->
+ (mkctf loc (Pctf_inher (class_type ct))) :: l
| CgMth (loc, s, pf, t) ->
- (Pctf_meth
- ((s, (mkprivate pf), (mkpolytype (ctyp t)), (mkloc loc)))) ::
+ (mkctf loc
+ (Pctf_meth ((s, (mkprivate pf), (mkpolytype (ctyp t)))))) ::
l
| CgVal (loc, s, b, v, t) ->
- (Pctf_val
- ((s, (mkmutable b), (mkvirtual v), (ctyp t),
- (mkloc loc)))) ::
+ (mkctf loc
+ (Pctf_val ((s, (mkmutable b), (mkvirtual v), (ctyp t))))) ::
l
| CgVir (loc, s, b, t) ->
- (Pctf_virt
- ((s, (mkprivate b), (mkpolytype (ctyp t)), (mkloc loc)))) ::
+ (mkctf loc
+ (Pctf_virt ((s, (mkprivate b), (mkpolytype (ctyp t)))))) ::
l
| CgAnt (_, _) -> assert false
and class_expr =
@@ -15484,39 +15562,42 @@ module Struct =
| (CeApp (loc, _, _) as c) ->
let (ce, el) = class_expr_fa [] c in
let el = List.map label_expr el
- in mkpcl loc (Pcl_apply ((class_expr ce), el))
+ in mkcl loc (Pcl_apply ((class_expr ce), el))
| CeCon (loc, ViNil, id, tl) ->
- mkpcl loc
+ mkcl loc
(Pcl_constr ((long_class_ident id),
(List.map ctyp (list_of_opt_ctyp tl []))))
| CeFun (loc, (PaLab (_, lab, po)), ce) ->
- mkpcl loc
+ mkcl loc
(Pcl_fun (lab, None, (patt_of_lab loc lab po),
(class_expr ce)))
| CeFun (loc, (PaOlbi (_, lab, p, e)), ce) ->
let lab = paolab lab p
in
- mkpcl loc
+ mkcl loc
(Pcl_fun (("?" ^ lab), (Some (expr e)), (patt p),
(class_expr ce)))
| CeFun (loc, (PaOlb (_, lab, p)), ce) ->
let lab = paolab lab p
in
- mkpcl loc
+ mkcl loc
(Pcl_fun (("?" ^ lab), None, (patt_of_lab loc lab p),
(class_expr ce)))
| CeFun (loc, p, ce) ->
- mkpcl loc (Pcl_fun ("", None, (patt p), (class_expr ce)))
+ mkcl loc (Pcl_fun ("", None, (patt p), (class_expr ce)))
| CeLet (loc, rf, bi, ce) ->
- mkpcl loc
+ mkcl loc
(Pcl_let ((mkrf rf), (binding bi []), (class_expr ce)))
| CeStr (loc, po, cfl) ->
let p =
(match po with | Ast.PaNil _ -> Ast.PaAny loc | p -> p) in
let cil = class_str_item cfl []
- in mkpcl loc (Pcl_structure (((patt p), cil)))
+ in
+ mkcl loc
+ (Pcl_structure
+ { pcstr_pat = patt p; pcstr_fields = cil; })
| CeTyc (loc, ce, ct) ->
- mkpcl loc
+ mkcl loc
(Pcl_constraint ((class_expr ce), (class_type ct)))
| CeCon (loc, _, _, _) ->
error loc "invalid virtual class inside a class expression"
@@ -15526,15 +15607,17 @@ module Struct =
match c with
| CrNil _ -> l
| CrCtr (loc, t1, t2) ->
- (Pcf_cstr (((ctyp t1), (ctyp t2), (mkloc loc)))) :: l
+ (mkcf loc (Pcf_constr (((ctyp t1), (ctyp t2))))) :: l
| Ast.CrSem (_, cst1, cst2) ->
class_str_item cst1 (class_str_item cst2 l)
| CrInh (loc, ov, ce, pb) ->
let opb = if pb = "" then None else Some pb
in
- (Pcf_inher ((override_flag loc ov), (class_expr ce), opb)) ::
+ (mkcf loc
+ (Pcf_inher ((override_flag loc ov), (class_expr ce),
+ opb))) ::
l
- | CrIni (_, e) -> (Pcf_init (expr e)) :: l
+ | CrIni (loc, e) -> (mkcf loc (Pcf_init (expr e))) :: l
| CrMth (loc, s, ov, pf, e, t) ->
let t =
(match t with
@@ -15542,21 +15625,27 @@ module Struct =
| t -> Some (mkpolytype (ctyp t))) in
let e = mkexp loc (Pexp_poly ((expr e), t))
in
- (Pcf_meth
- ((s, (mkprivate pf), (override_flag loc ov), e,
- (mkloc loc)))) ::
+ (mkcf loc
+ (Pcf_meth
+ (((with_loc s loc), (mkprivate pf),
+ (override_flag loc ov), e)))) ::
l
| CrVal (loc, s, ov, mf, e) ->
- (Pcf_val
- ((s, (mkmutable mf), (override_flag loc ov), (expr e),
- (mkloc loc)))) ::
+ (mkcf loc
+ (Pcf_val
+ (((with_loc s loc), (mkmutable mf),
+ (override_flag loc ov), (expr e))))) ::
l
| CrVir (loc, s, pf, t) ->
- (Pcf_virt
- ((s, (mkprivate pf), (mkpolytype (ctyp t)), (mkloc loc)))) ::
+ (mkcf loc
+ (Pcf_virt
+ (((with_loc s loc), (mkprivate pf),
+ (mkpolytype (ctyp t)))))) ::
l
| CrVvr (loc, s, mf, t) ->
- (Pcf_valvirt ((s, (mkmutable mf), (ctyp t), (mkloc loc)))) ::
+ (mkcf loc
+ (Pcf_valvirt
+ (((with_loc s loc), (mkmutable mf), (ctyp t))))) ::
l
| CrAnt (_, _) -> assert false
@@ -15571,7 +15660,7 @@ module Struct =
| ExInt (_, i) -> Pdir_int (int_of_string i)
| Ast.ExId (_, (Ast.IdUid (_, "True"))) -> Pdir_bool true
| Ast.ExId (_, (Ast.IdUid (_, "False"))) -> Pdir_bool false
- | e -> Pdir_ident (ident (ident_of_expr e))
+ | e -> Pdir_ident (ident_noloc (ident_of_expr e))
let phrase =
function
@@ -16986,9 +17075,14 @@ module Struct =
let drop_prev_loc = Tools.drop_prev_loc
let add_loc bp parse_fun strm =
+ let count1 = Stream.count strm in
let x = parse_fun strm in
- let ep = loc_ep strm in
- let loc = Loc.merge bp ep in (x, loc)
+ let count2 = Stream.count strm in
+ let loc =
+ if count1 < count2
+ then (let ep = loc_ep strm in Loc.merge bp ep)
+ else Loc.join bp
+ in (x, loc)
let stream_peek_nth strm n =
let rec loop i =
@@ -17799,13 +17893,6 @@ module Struct =
in Some t
| None -> None)
| LocAct (_, _) | DeadEnd -> None
- and insert_new =
- function
- | s :: sl ->
- Node
- { node = s; son = insert_new sl; brother = DeadEnd;
- }
- | [] -> LocAct (action, [])
in insert gsymbols tree
let insert_level entry e1 symbols action slev =
@@ -18868,7 +18955,7 @@ module Printers =
"Cannot print %S this identifier does not respect OCaml lexing rules (%s)"
str (Lexer.Error.to_string exn))
- let ocaml_char = function | "'" -> "\\'" | c -> c
+ let ocaml_char x = match x with | "'" -> "\\'" | c -> c
let rec get_expr_args a al =
match a with
@@ -19150,7 +19237,16 @@ module Printers =
fun f t ->
match Ast.list_of_ctyp t [] with
| [] -> ()
- | ts -> pp f "@[<hv0>| %a@]" (list o#ctyp "@ | ") ts
+ | ts ->
+ pp f "@[<hv0>| %a@]"
+ (list o#constructor_declaration "@ | ") ts
+ method private constructor_declaration =
+ fun f t ->
+ match t with
+ | Ast.TyCol (_, t1, (Ast.TyArr (_, t2, t3))) ->
+ pp f "@[<2>%a :@ @[<2>%a@ ->@ %a@]@]" o#ctyp t1
+ o#constructor_type t2 o#ctyp t3
+ | t -> o#ctyp f t
method string = fun f -> pp f "%s"
method quoted_string = fun f -> pp f "%S"
method numeric =
@@ -19388,7 +19484,7 @@ module Printers =
| Ast.ExInt64 (_, s) -> o#numeric f s "L"
| Ast.ExInt32 (_, s) -> o#numeric f s "l"
| Ast.ExFlo (_, s) -> o#numeric f s ""
- | Ast.ExChr (_, s) -> pp f "'%s'" (ocaml_char s)
+ | Ast.ExChr (_, s) -> pp f "'%s'" s
| Ast.ExId (_, i) -> o#var_ident f i
| Ast.ExRec (_, b, (Ast.ExNil _)) ->
pp f "@[<hv0>@[<hv2>{%a@]@ }@]" o#record_binding b
@@ -19533,7 +19629,7 @@ module Printers =
| Ast.PaInt32 (_, s) -> o#numeric f s "l"
| Ast.PaInt (_, s) -> o#numeric f s ""
| Ast.PaFlo (_, s) -> o#numeric f s ""
- | Ast.PaChr (_, s) -> pp f "'%s'" (ocaml_char s)
+ | Ast.PaChr (_, s) -> pp f "'%s'" s
| Ast.PaLab (_, s, (Ast.PaNil _)) -> pp f "~%s" s
| Ast.PaVrn (_, s) -> pp f "`%a" o#var s
| Ast.PaTyp (_, i) -> pp f "@[<2>#%a@]" o#ident i
@@ -19889,7 +19985,7 @@ module Printers =
in
match ce with
| Ast.CeApp (_, ce, e) ->
- pp f "@[<2>%a@ %a@]" o#class_expr ce o#expr e
+ pp f "@[<2>%a@ %a@]" o#class_expr ce o#apply_expr e
| Ast.CeCon (_, Ast.ViNil, i, (Ast.TyNil _)) ->
pp f "@[<2>%a@]" o#ident i
| Ast.CeCon (_, Ast.ViNil, i, t) ->
diff --git a/camlp4/boot/Camlp4Ast.ml b/camlp4/boot/Camlp4Ast.ml
index acb8afd3c..fb49d01b5 100644
--- a/camlp4/boot/Camlp4Ast.ml
+++ b/camlp4/boot/Camlp4Ast.ml
@@ -471,11 +471,10 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
value meta_loc = meta_loc_expr;
module Expr =
struct
- value meta_string _loc s =
- Ast.ExStr _loc (safe_string_escaped s);
+ value meta_string _loc s = Ast.ExStr _loc s;
value meta_int _loc s = Ast.ExInt _loc s;
value meta_float _loc s = Ast.ExFlo _loc s;
- value meta_char _loc s = Ast.ExChr _loc (String.escaped s);
+ value meta_char _loc s = Ast.ExChr _loc s;
value meta_bool _loc =
fun
[ False -> Ast.ExId _loc (Ast.IdUid _loc "False")
@@ -5048,6 +5047,8 @@ module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc =
(* source tree. *)
(* *)
(****************************************************************************)
+ (* Note: when you modify these types you must increment
+ ast magic numbers defined in Camlp4_config.ml. *)
'a 'a_out.
('self_type -> 'a -> 'a_out) ->
meta_option 'a -> meta_option 'a_out =
diff --git a/camlp4/boot/camlp4boot.ml b/camlp4/boot/camlp4boot.ml
index 6cc5466c0..a434eea4f 100644
--- a/camlp4/boot/camlp4boot.ml
+++ b/camlp4/boot/camlp4boot.ml
@@ -588,6 +588,12 @@ New syntax:\
let stopped_at _loc = Some (Loc.move_line 1 _loc)
(* FIXME be more precise *)
+ let rec generalized_type_of_type =
+ function
+ | Ast.TyArr (_, t1, t2) ->
+ let (tl, rt) = generalized_type_of_type t2 in ((t1 :: tl), rt)
+ | t -> ([], t)
+
let symbolchar =
let list =
[ '$'; '!'; '%'; '&'; '*'; '+'; '-'; '.'; '/'; ':'; '<'; '=';
@@ -676,8 +682,8 @@ New syntax:\
(match Stream.peek __strm with
| Some
((KEYWORD
- (("mod" | "land" | "lor" | "lxor" | "lsl" | "lsr" |
- "asr"
+ (("or" | "mod" | "land" | "lor" | "lxor" | "lsl" |
+ "lsr" | "asr"
as i)),
_loc))
->
@@ -3027,16 +3033,8 @@ New syntax:\
[ (None, (Some Camlp4.Sig.Grammar.RightA),
[ ([ Gram.Snterm
(Gram.Entry.obj
- (cvalue_binding :
- 'cvalue_binding Gram.Entry.t)) ],
- (Gram.Action.mk
- (fun (bi : 'cvalue_binding) (_loc : Gram.Loc.t)
- -> (bi : 'fun_binding))));
- ([ Gram.Stry
- (Gram.Snterm
- (Gram.Entry.obj
- (labeled_ipatt :
- 'labeled_ipatt Gram.Entry.t)));
+ (labeled_ipatt :
+ 'labeled_ipatt Gram.Entry.t));
Gram.Sself ],
(Gram.Action.mk
(fun (e : 'fun_binding) (p : 'labeled_ipatt)
@@ -3045,6 +3043,14 @@ New syntax:\
(Ast.McArr (_loc, p, (Ast.ExNil _loc), e))) :
'fun_binding))));
([ Gram.Stry
+ (Gram.Snterm
+ (Gram.Entry.obj
+ (cvalue_binding :
+ 'cvalue_binding Gram.Entry.t))) ],
+ (Gram.Action.mk
+ (fun (bi : 'cvalue_binding) (_loc : Gram.Loc.t)
+ -> (bi : 'fun_binding))));
+ ([ Gram.Stry
(Gram.srules fun_binding
[ ([ Gram.Skeyword "("; Gram.Skeyword "type" ],
(Gram.Action.mk
@@ -4294,6 +4300,25 @@ New syntax:\
([ Gram.Snterm
(Gram.Entry.obj
(label_ipatt : 'label_ipatt Gram.Entry.t));
+ Gram.Skeyword ";"; Gram.Skeyword "_";
+ Gram.Skeyword ";" ],
+ (Gram.Action.mk
+ (fun _ _ _ (p1 : 'label_ipatt)
+ (_loc : Gram.Loc.t) ->
+ (Ast.PaSem (_loc, p1, (Ast.PaAny _loc)) :
+ 'label_ipatt_list))));
+ ([ Gram.Snterm
+ (Gram.Entry.obj
+ (label_ipatt : 'label_ipatt Gram.Entry.t));
+ Gram.Skeyword ";"; Gram.Skeyword "_" ],
+ (Gram.Action.mk
+ (fun _ _ (p1 : 'label_ipatt) (_loc : Gram.Loc.t)
+ ->
+ (Ast.PaSem (_loc, p1, (Ast.PaAny _loc)) :
+ 'label_ipatt_list))));
+ ([ Gram.Snterm
+ (Gram.Entry.obj
+ (label_ipatt : 'label_ipatt Gram.Entry.t));
Gram.Skeyword ";"; Gram.Sself ],
(Gram.Action.mk
(fun (p2 : 'label_ipatt_list) _
@@ -5037,40 +5062,16 @@ New syntax:\
(a_UIDENT : 'a_UIDENT Gram.Entry.t));
Gram.Skeyword ":";
Gram.Snterm
- (Gram.Entry.obj
- (constructor_arg_list :
- 'constructor_arg_list Gram.Entry.t)) ],
- (Gram.Action.mk
- (fun (ret : 'constructor_arg_list) _
- (s : 'a_UIDENT) (_loc : Gram.Loc.t) ->
- (match Ast.list_of_ctyp ret [] with
- | [ c ] ->
- Ast.TyCol (_loc,
- (Ast.TyId (_loc,
- (Ast.IdUid (_loc, s)))),
- c)
- | _ ->
- raise
- (Stream.Error
- "invalid generalized constructor type") :
- 'constructor_declarations))));
- ([ Gram.Snterm
- (Gram.Entry.obj
- (a_UIDENT : 'a_UIDENT Gram.Entry.t));
- Gram.Skeyword ":";
- Gram.Snterm
- (Gram.Entry.obj
- (constructor_arg_list :
- 'constructor_arg_list Gram.Entry.t));
- Gram.Skeyword "->";
- Gram.Snterm
(Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ],
(Gram.Action.mk
- (fun (ret : 'ctyp) _ (t : 'constructor_arg_list)
- _ (s : 'a_UIDENT) (_loc : Gram.Loc.t) ->
- (Ast.TyCol (_loc,
- (Ast.TyId (_loc, (Ast.IdUid (_loc, s)))),
- (Ast.TyArr (_loc, t, ret))) :
+ (fun (t : 'ctyp) _ (s : 'a_UIDENT)
+ (_loc : Gram.Loc.t) ->
+ (let (tl, rt) = generalized_type_of_type t
+ in
+ Ast.TyCol (_loc,
+ (Ast.TyId (_loc, (Ast.IdUid (_loc, s)))),
+ (Ast.TyArr (_loc,
+ (Ast.tyAnd_of_list tl), rt))) :
'constructor_declarations))));
([ Gram.Snterm
(Gram.Entry.obj
@@ -8756,7 +8757,10 @@ New syntax:\
(Gram.Action.mk
(fun (st2 : 'str_item_quot) _ (st1 : 'str_item)
(_loc : Gram.Loc.t) ->
- (Ast.StSem (_loc, st1, st2) : 'str_item_quot))));
+ (match st2 with
+ | Ast.StNil _ -> st1
+ | _ -> Ast.StSem (_loc, st1, st2) :
+ 'str_item_quot))));
([ Gram.Skeyword "#";
Gram.Snterm
(Gram.Entry.obj
@@ -8792,7 +8796,10 @@ New syntax:\
(Gram.Action.mk
(fun (sg2 : 'sig_item_quot) _ (sg1 : 'sig_item)
(_loc : Gram.Loc.t) ->
- (Ast.SgSem (_loc, sg1, sg2) : 'sig_item_quot))));
+ (match sg2 with
+ | Ast.SgNil _ -> sg1
+ | _ -> Ast.SgSem (_loc, sg1, sg2) :
+ 'sig_item_quot))));
([ Gram.Skeyword "#";
Gram.Snterm
(Gram.Entry.obj
@@ -9232,7 +9239,9 @@ New syntax:\
(Gram.Action.mk
(fun (x2 : 'class_str_item_quot) _
(x1 : 'class_str_item) (_loc : Gram.Loc.t) ->
- (Ast.CrSem (_loc, x1, x2) :
+ (match x2 with
+ | Ast.CrNil _ -> x1
+ | _ -> Ast.CrSem (_loc, x1, x2) :
'class_str_item_quot)))) ]) ]))
());
Gram.extend
@@ -9261,7 +9270,9 @@ New syntax:\
(Gram.Action.mk
(fun (x2 : 'class_sig_item_quot) _
(x1 : 'class_sig_item) (_loc : Gram.Loc.t) ->
- (Ast.CgSem (_loc, x1, x2) :
+ (match x2 with
+ | Ast.CgNil _ -> x1
+ | _ -> Ast.CgSem (_loc, x1, x2) :
'class_sig_item_quot)))) ]) ]))
());
Gram.extend (with_constr_quot : 'with_constr_quot Gram.Entry.t)
@@ -13692,6 +13703,7 @@ Added statements:
DEFINE <lident> = <expression> IN <expression>
__FILE__
__LOCATION__
+ LOCATION_OF <parameter>
In patterns:
@@ -13724,6 +13736,10 @@ Added statements:
The expression __FILE__ returns the current compiled file name.
The expression __LOCATION__ returns the current location of itself.
+ If used inside a macro, it returns the location where the macro is
+ called.
+ The expression (LOCATION_OF parameter) returns the location of the given
+ macro parameter. It cannot be used outside a macro definition.
*)
open Camlp4
@@ -13794,6 +13810,48 @@ Added statements:
Ast.ExId (_, (Ast.IdUid (_, x)))
as e) ->
(try List.assoc x env with | Not_found -> super#expr e)
+ | (Ast.ExApp (_loc,
+ (Ast.ExId (_, (Ast.IdUid (_, "LOCATION_OF")))),
+ (Ast.ExId (_, (Ast.IdLid (_, x))))) |
+ Ast.ExApp (_loc,
+ (Ast.ExId (_, (Ast.IdUid (_, "LOCATION_OF")))),
+ (Ast.ExId (_, (Ast.IdUid (_, x)))))
+ as e) ->
+ (try
+ let loc = Ast.loc_of_expr (List.assoc x env) in
+ let (a, b, c, d, e, f, g, h) = Loc.to_tuple loc
+ in
+ Ast.ExApp (_loc,
+ (Ast.ExId (_loc,
+ (Ast.IdAcc (_loc, (Ast.IdUid (_loc, "Loc")),
+ (Ast.IdLid (_loc, "of_tuple")))))),
+ (Ast.ExTup (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExStr (_loc, (Ast.safe_string_escaped a))),
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExInt (_loc,
+ (string_of_int b))),
+ (Ast.ExInt (_loc,
+ (string_of_int c))))),
+ (Ast.ExInt (_loc,
+ (string_of_int d))))),
+ (Ast.ExInt (_loc,
+ (string_of_int e))))),
+ (Ast.ExInt (_loc, (string_of_int f))))),
+ (Ast.ExInt (_loc, (string_of_int g))))),
+ (if h
+ then
+ Ast.ExId (_loc,
+ (Ast.IdUid (_loc, "True")))
+ else
+ Ast.ExId (_loc,
+ (Ast.IdUid (_loc, "False")))))))))))
+ with | Not_found -> super#expr e)
| e -> super#expr e
method patt =
function
@@ -14541,87 +14599,6 @@ Added statements:
(i : 'uident) _ (_loc : Gram.Loc.t) ->
(if is_defined i then e1 else e2 : 'expr)))) ]) ]))
());
- Gram.extend (expr : 'expr Gram.Entry.t)
- ((fun () ->
- ((Some (Camlp4.Sig.Grammar.Level "simple")),
- [ (None, None,
- [ ([ Gram.Stoken
- (((function
- | LIDENT "__LOCATION__" -> true
- | _ -> false),
- "LIDENT \"__LOCATION__\"")) ],
- (Gram.Action.mk
- (fun (__camlp4_0 : Gram.Token.t)
- (_loc : Gram.Loc.t) ->
- match __camlp4_0 with
- | LIDENT "__LOCATION__" ->
- (let (a, b, c, d, e, f, g, h) =
- Loc.to_tuple _loc
- in
- Ast.ExApp (_loc,
- (Ast.ExId (_loc,
- (Ast.IdAcc (_loc,
- (Ast.IdUid (_loc, "Loc")),
- (Ast.IdLid (_loc, "of_tuple")))))),
- (Ast.ExTup (_loc,
- (Ast.ExCom (_loc,
- (Ast.ExStr (_loc,
- (Ast.safe_string_escaped a))),
- (Ast.ExCom (_loc,
- (Ast.ExCom (_loc,
- (Ast.ExCom (_loc,
- (Ast.ExCom (_loc,
- (Ast.ExCom (_loc,
- (Ast.ExCom
- (_loc,
- (Ast.ExInt
- (_loc,
- (
- string_of_int
- b))),
- (Ast.ExInt
- (_loc,
- (
- string_of_int
- c))))),
- (Ast.ExInt
- (_loc,
- (string_of_int
- d))))),
- (Ast.ExInt (_loc,
- (string_of_int
- e))))),
- (Ast.ExInt (_loc,
- (string_of_int f))))),
- (Ast.ExInt (_loc,
- (string_of_int g))))),
- (if h
- then
- Ast.ExId (_loc,
- (Ast.IdUid (_loc,
- "True")))
- else
- Ast.ExId (_loc,
- (Ast.IdUid (_loc,
- "False"))))))))))) :
- 'expr)
- | _ -> assert false)));
- ([ Gram.Stoken
- (((function
- | LIDENT "__FILE__" -> true
- | _ -> false),
- "LIDENT \"__FILE__\"")) ],
- (Gram.Action.mk
- (fun (__camlp4_0 : Gram.Token.t)
- (_loc : Gram.Loc.t) ->
- match __camlp4_0 with
- | LIDENT "__FILE__" ->
- (Ast.ExStr (_loc,
- (Ast.safe_string_escaped
- (Loc.file_name _loc))) :
- 'expr)
- | _ -> assert false))) ]) ]))
- ());
Gram.extend (patt : 'patt Gram.Entry.t)
((fun () ->
(None,
@@ -14790,17 +14767,47 @@ Added statements:
open Ast
- let remove_nothings =
+ (* Remove NOTHING and expanse __FILE__ and __LOCATION__ *)
+ let map_expr =
function
| Ast.ExApp (_, e, (Ast.ExId (_, (Ast.IdUid (_, "NOTHING"))))) |
Ast.ExFun (_,
(Ast.McArr (_, (Ast.PaId (_, (Ast.IdUid (_, "NOTHING")))),
(Ast.ExNil _), e)))
-> e
+ | Ast.ExId (_loc, (Ast.IdLid (_, "__FILE__"))) ->
+ Ast.ExStr (_loc,
+ (Ast.safe_string_escaped (Loc.file_name _loc)))
+ | Ast.ExId (_loc, (Ast.IdLid (_, "__LOCATION__"))) ->
+ let (a, b, c, d, e, f, g, h) = Loc.to_tuple _loc
+ in
+ Ast.ExApp (_loc,
+ (Ast.ExId (_loc,
+ (Ast.IdAcc (_loc, (Ast.IdUid (_loc, "Loc")),
+ (Ast.IdLid (_loc, "of_tuple")))))),
+ (Ast.ExTup (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExStr (_loc, (Ast.safe_string_escaped a))),
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExCom (_loc,
+ (Ast.ExInt (_loc,
+ (string_of_int b))),
+ (Ast.ExInt (_loc,
+ (string_of_int c))))),
+ (Ast.ExInt (_loc, (string_of_int d))))),
+ (Ast.ExInt (_loc, (string_of_int e))))),
+ (Ast.ExInt (_loc, (string_of_int f))))),
+ (Ast.ExInt (_loc, (string_of_int g))))),
+ (if h
+ then Ast.ExId (_loc, (Ast.IdUid (_loc, "True")))
+ else Ast.ExId (_loc, (Ast.IdUid (_loc, "False")))))))))))
| e -> e
- let _ =
- register_str_item_filter (Ast.map_expr remove_nothings)#str_item
+ let _ = register_str_item_filter (Ast.map_expr map_expr)#str_item
end
diff --git a/debugger/.depend b/debugger/.depend
index 1a04b1eaa..75ed135a3 100644
--- a/debugger/.depend
+++ b/debugger/.depend
@@ -124,12 +124,14 @@ main.cmo: unix_tools.cmi $(UNIXDIR)/unix.cmi time_travel.cmi \
show_information.cmi question.cmi program_management.cmi primitives.cmi \
parameters.cmi ../utils/misc.cmi input_handling.cmi frames.cmi exec.cmi \
../typing/env.cmi debugger_config.cmi ../utils/config.cmi \
- command_line.cmi ../utils/clflags.cmi checkpoints.cmi
+ command_line.cmi ../typing/cmi_format.cmi ../utils/clflags.cmi \
+ checkpoints.cmi
main.cmx: unix_tools.cmx $(UNIXDIR)/unix.cmx time_travel.cmx \
show_information.cmx question.cmx program_management.cmx primitives.cmx \
parameters.cmx ../utils/misc.cmx input_handling.cmx frames.cmx exec.cmx \
../typing/env.cmx debugger_config.cmx ../utils/config.cmx \
- command_line.cmx ../utils/clflags.cmx checkpoints.cmx
+ command_line.cmx ../typing/cmi_format.cmx ../utils/clflags.cmx \
+ checkpoints.cmx
parameters.cmo: primitives.cmi envaux.cmi debugger_config.cmi \
../utils/config.cmi parameters.cmi
parameters.cmx: primitives.cmx envaux.cmx debugger_config.cmx \
diff --git a/debugger/Makefile.shared b/debugger/Makefile.shared
index 820af9af9..964f71f69 100644
--- a/debugger/Makefile.shared
+++ b/debugger/Makefile.shared
@@ -15,8 +15,8 @@
include ../config/Makefile
CAMLC=../ocamlcomp.sh
-COMPFLAGS=-warn-error A $(INCLUDES)
-LINKFLAGS=-linkall -I $(UNIXDIR)
+COMPFLAGS=-g -warn-error A $(INCLUDES)
+LINKFLAGS=-g -linkall -I $(UNIXDIR)
CAMLYACC=../boot/ocamlyacc
YACCFLAGS=
CAMLLEX=../boot/ocamlrun ../boot/ocamllex
@@ -35,7 +35,7 @@ OTHEROBJS=\
../typing/ident.cmo ../typing/path.cmo ../typing/types.cmo \
../typing/btype.cmo ../typing/primitive.cmo ../typing/typedtree.cmo \
../typing/subst.cmo ../typing/predef.cmo \
- ../typing/datarepr.cmo ../typing/env.cmo ../typing/oprint.cmo \
+ ../typing/datarepr.cmo ../typing/cmi_format.cmo ../typing/env.cmo ../typing/oprint.cmo \
../typing/ctype.cmo ../typing/printtyp.cmo ../typing/mtype.cmo \
../bytecomp/runtimedef.cmo ../bytecomp/bytesections.cmo \
../bytecomp/dll.cmo ../bytecomp/meta.cmo ../bytecomp/symtable.cmo \
diff --git a/debugger/command_line.ml b/debugger/command_line.ml
index 9b0084daf..3977a8567 100644
--- a/debugger/command_line.ml
+++ b/debugger/command_line.ml
@@ -209,8 +209,8 @@ let line_loop ppf line_buffer =
with
| Exit ->
stop_user_input ()
- | Sys_error s ->
- error ("System error : " ^ s)
+(* | Sys_error s ->
+ error ("System error : " ^ s) *)
(** Instructions. **)
let instr_cd ppf lexbuf =
diff --git a/debugger/envaux.ml b/debugger/envaux.ml
index 56786929e..d146cd0fd 100644
--- a/debugger/envaux.ml
+++ b/debugger/envaux.ml
@@ -31,7 +31,7 @@ let reset_cache () =
let extract_sig env mty =
match Mtype.scrape env mty with
- Tmty_signature sg -> sg
+ Mty_signature sg -> sg
| _ -> fatal_error "Envaux.extract_sig"
let rec env_from_summary sum subst =
diff --git a/debugger/eval.ml b/debugger/eval.ml
index 0f8c8a056..1e84d9208 100644
--- a/debugger/eval.ml
+++ b/debugger/eval.ml
@@ -149,7 +149,7 @@ and find_label lbl env ty path tydesc pos = function
[] ->
raise(Error(Wrong_label(ty, lbl)))
| (name, mut, ty_arg) :: rem ->
- if name = lbl then begin
+ if Ident.name name = lbl then begin
let ty_res =
Btype.newgenty(Tconstr(path, tydesc.type_params, ref Mnil))
in
diff --git a/debugger/main.ml b/debugger/main.ml
index 9dbb41ee6..1dcd5cf40 100644
--- a/debugger/main.ml
+++ b/debugger/main.ml
@@ -224,6 +224,11 @@ let main () =
Env.report_error err_formatter e;
eprintf "@]@.";
exit 2
+ | Cmi_format.Error e ->
+ eprintf "Debugger [version %s] environment error:@ @[@;" Config.version;
+ Cmi_format.report_error err_formatter e;
+ eprintf "@]@.";
+ exit 2
let _ =
Printexc.catch (Unix.handle_unix_error main) ()
diff --git a/debugger/program_management.ml b/debugger/program_management.ml
index 3e6ffa81d..27f1d9cc5 100644
--- a/debugger/program_management.ml
+++ b/debugger/program_management.ml
@@ -116,8 +116,10 @@ let ask_kill_program () =
(*** Program loading and initializations. ***)
let initialize_loading () =
- if !debug_loading then
+ if !debug_loading then begin
prerr_endline "Loading debugging information...";
+ Printf.fprintf Pervasives.stderr "\tProgram: [%s]\n%!" !program_name;
+ end;
begin try access !program_name [F_OK]
with Unix_error _ ->
prerr_endline "Program not found.";
diff --git a/debugger/source.ml b/debugger/source.ml
index 0f705f259..65634cbe5 100644
--- a/debugger/source.ml
+++ b/debugger/source.ml
@@ -28,7 +28,7 @@ let source_of_module pos mdle =
try
(String.sub m 0 len') = m' && (String.get m len') = '.'
with
- Invalid_argument _ -> false in
+ Invalid_argument _ -> false in
let path =
Hashtbl.fold
(fun mdl dirs acc ->
@@ -39,7 +39,20 @@ let source_of_module pos mdle =
Debugger_config.load_path_for
!Config.load_path in
let fname = pos.Lexing.pos_fname in
- if Filename.is_implicit fname then
+ if fname = "" then
+ let innermost_module =
+ try
+ let dot_index = String.rindex mdle '.' in
+ String.sub mdle (succ dot_index) (pred ((String.length mdle) - dot_index))
+ with Not_found -> mdle in
+ let rec loop =
+ function
+ | [] -> raise Not_found
+ | ext :: exts ->
+ try find_in_path_uncap path (innermost_module ^ ext)
+ with Not_found -> loop exts
+ in loop source_extensions
+ else if Filename.is_implicit fname then
find_in_path path fname
else
fname
diff --git a/debugger/unix_tools.ml b/debugger/unix_tools.ml
index dea47f99f..2897420bc 100644
--- a/debugger/unix_tools.ml
+++ b/debugger/unix_tools.ml
@@ -58,6 +58,7 @@ let report_error = function
(* Return the full path if found. *)
(* Raise `Not_found' otherwise. *)
let search_in_path name =
+ Printf.fprintf Pervasives.stderr "search_in_path [%s]\n%!" name;
let check name =
try access name [X_OK]; name with Unix_error _ -> raise Not_found
in
diff --git a/driver/compile.ml b/driver/compile.ml
index b19dca023..e8104bdea 100644
--- a/driver/compile.ml
+++ b/driver/compile.ml
@@ -17,6 +17,7 @@
open Misc
open Config
open Format
+open Typedtree
(* Initialize the search path.
The current directory is always searched first,
@@ -78,19 +79,24 @@ let interface ppf sourcefile outputprefix =
check_unit_name ppf sourcefile modulename;
Env.set_unit_name modulename;
let inputfile = Pparse.preprocess sourcefile in
+ let initial_env = initial_env () in
try
let ast =
Pparse.file ppf inputfile Parse.interface ast_intf_magic_number in
if !Clflags.dump_parsetree then fprintf ppf "%a@." Printast.interface ast;
- let sg = Typemod.transl_signature (initial_env()) ast in
+ let tsg = Typemod.transl_signature initial_env ast in
+ let sg = tsg.sig_type in
if !Clflags.print_types then
fprintf std_formatter "%a@." Printtyp.signature
(Typemod.simplify_signature sg);
- ignore (Includemod.signatures (initial_env()) sg sg);
+ ignore (Includemod.signatures initial_env sg sg);
Typecore.force_delayed_checks ();
Warnings.check_fatal ();
- if not !Clflags.print_types then
- Env.save_signature sg modulename (outputprefix ^ ".cmi");
+ if not !Clflags.print_types then begin
+ let sg = Env.save_signature sg modulename (outputprefix ^ ".cmi") in
+ Typemod.save_signature modulename tsg outputprefix sourcefile
+ initial_env sg ;
+ end;
Pparse.remove_preprocessed inputfile
with e ->
Pparse.remove_preprocessed_if_ast inputfile;
@@ -120,10 +126,10 @@ let implementation ppf sourcefile outputprefix =
++ Typemod.type_implementation sourcefile outputprefix modulename env);
Warnings.check_fatal ();
Pparse.remove_preprocessed inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
with x ->
Pparse.remove_preprocessed_if_ast inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
raise x
end else begin
let objfile = outputprefix ^ ".cmo" in
@@ -142,12 +148,12 @@ let implementation ppf sourcefile outputprefix =
Warnings.check_fatal ();
close_out oc;
Pparse.remove_preprocessed inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
with x ->
close_out oc;
remove_file objfile;
Pparse.remove_preprocessed_if_ast inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
raise x
end
diff --git a/driver/errors.ml b/driver/errors.ml
index 9400e9ebc..47ae99542 100644
--- a/driver/errors.ml
+++ b/driver/errors.ml
@@ -34,6 +34,9 @@ let report_error ppf exn =
| Env.Error err ->
Location.print_error_cur_file ppf;
Env.report_error ppf err
+ | Cmi_format.Error err ->
+ Location.print_error_cur_file ppf;
+ Cmi_format.report_error ppf err
| Ctype.Tags(l, l') ->
Location.print_error_cur_file ppf;
fprintf ppf
diff --git a/driver/main.ml b/driver/main.ml
index 94b024eaa..9d448baa1 100644
--- a/driver/main.ml
+++ b/driver/main.ml
@@ -93,6 +93,7 @@ module Options = Main_args.Make_bytecomp_options (struct
let _a = set make_archive
let _absname = set Location.absname
let _annot = set annotations
+ let _binannot = set binary_annotations
let _c = set compile_only
let _cc s = c_compiler := Some s
let _cclib s = ccobjs := Misc.rev_split_words s @ !ccobjs
diff --git a/driver/main_args.ml b/driver/main_args.ml
index 75e3f164a..fa0b83ff4 100644
--- a/driver/main_args.ml
+++ b/driver/main_args.ml
@@ -24,6 +24,10 @@ let mk_annot f =
"-annot", Arg.Unit f, " Save information in <filename>.annot"
;;
+let mk_binannot f =
+ "-bin-annot", Arg.Unit f, " Save typedtree in <filename>.cmt"
+;;
+
let mk_c f =
"-c", Arg.Unit f, " Compile only (do not link)"
;;
@@ -397,6 +401,7 @@ module type Bytecomp_options = sig
val _a : unit -> unit
val _absname : unit -> unit
val _annot : unit -> unit
+ val _binannot : unit -> unit
val _c : unit -> unit
val _cc : string -> unit
val _cclib : string -> unit
@@ -484,6 +489,7 @@ module type Optcomp_options = sig
val _a : unit -> unit
val _absname : unit -> unit
val _annot : unit -> unit
+ val _binannot : unit -> unit
val _c : unit -> unit
val _cc : string -> unit
val _cclib : string -> unit
@@ -606,6 +612,7 @@ struct
mk_a F._a;
mk_absname F._absname;
mk_annot F._annot;
+ mk_binannot F._binannot;
mk_c F._c;
mk_cc F._cc;
mk_cclib F._cclib;
@@ -705,6 +712,7 @@ struct
mk_a F._a;
mk_absname F._absname;
mk_annot F._annot;
+ mk_binannot F._binannot;
mk_c F._c;
mk_cc F._cc;
mk_cclib F._cclib;
diff --git a/driver/main_args.mli b/driver/main_args.mli
index 4c9eacca5..b7984cab4 100644
--- a/driver/main_args.mli
+++ b/driver/main_args.mli
@@ -17,6 +17,7 @@ module type Bytecomp_options =
val _a : unit -> unit
val _absname : unit -> unit
val _annot : unit -> unit
+ val _binannot : unit -> unit
val _c : unit -> unit
val _cc : string -> unit
val _cclib : string -> unit
@@ -105,6 +106,7 @@ module type Optcomp_options = sig
val _a : unit -> unit
val _absname : unit -> unit
val _annot : unit -> unit
+ val _binannot : unit -> unit
val _c : unit -> unit
val _cc : string -> unit
val _cclib : string -> unit
diff --git a/driver/optcompile.ml b/driver/optcompile.ml
index a796bbe1e..cb3805234 100644
--- a/driver/optcompile.ml
+++ b/driver/optcompile.ml
@@ -17,6 +17,7 @@
open Misc
open Config
open Format
+open Typedtree
(* Initialize the search path.
The current directory is always searched first,
@@ -75,24 +76,28 @@ let interface ppf sourcefile outputprefix =
check_unit_name ppf sourcefile modulename;
Env.set_unit_name modulename;
let inputfile = Pparse.preprocess sourcefile in
+ let initial_env = initial_env() in
try
let ast =
Pparse.file ppf inputfile Parse.interface ast_intf_magic_number in
if !Clflags.dump_parsetree then fprintf ppf "%a@." Printast.interface ast;
- let sg = Typemod.transl_signature (initial_env()) ast in
+ let tsg = Typemod.transl_signature initial_env ast in
+ let sg = tsg.sig_type in
if !Clflags.print_types then
fprintf std_formatter "%a@." Printtyp.signature
(Typemod.simplify_signature sg);
- ignore (Includemod.signatures (initial_env()) sg sg);
+ ignore (Includemod.signatures initial_env sg sg);
Typecore.force_delayed_checks ();
Warnings.check_fatal ();
- if not !Clflags.print_types then
- Env.save_signature sg modulename (outputprefix ^ ".cmi");
+ if not !Clflags.print_types then begin
+ let sg = Env.save_signature sg modulename (outputprefix ^ ".cmi") in
+ Typemod.save_signature modulename tsg outputprefix sourcefile initial_env sg ;
+ end;
Pparse.remove_preprocessed inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"))
with e ->
Pparse.remove_preprocessed_if_ast inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
raise e
(* Compile a .ml file *)
@@ -134,12 +139,12 @@ let implementation ppf sourcefile outputprefix =
end;
Warnings.check_fatal ();
Pparse.remove_preprocessed inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
with x ->
remove_file objfile;
remove_file cmxfile;
Pparse.remove_preprocessed_if_ast inputfile;
- Stypes.dump (outputprefix ^ ".annot");
+ Stypes.dump (Some (outputprefix ^ ".annot"));
raise x
let c_file name =
diff --git a/driver/opterrors.ml b/driver/opterrors.ml
index f931990a4..a30c2de26 100644
--- a/driver/opterrors.ml
+++ b/driver/opterrors.ml
@@ -33,6 +33,9 @@ let report_error ppf exn =
| Env.Error err ->
Location.print_error_cur_file ppf;
Env.report_error ppf err
+ | Cmi_format.Error err ->
+ Location.print_error_cur_file ppf;
+ Cmi_format.report_error ppf err
| Ctype.Tags(l, l') ->
Location.print_error_cur_file ppf;
fprintf ppf
diff --git a/driver/optmain.ml b/driver/optmain.ml
index 87f4c75f0..b6b86bbba 100644
--- a/driver/optmain.ml
+++ b/driver/optmain.ml
@@ -104,6 +104,7 @@ module Options = Main_args.Make_optcomp_options (struct
let _a = set make_archive
let _absname = set Location.absname
let _annot = set annotations
+ let _binannot = set binary_annotations
let _c = set compile_only
let _cc s = c_compiler := Some s
let _cclib s = ccobjs := Misc.rev_split_words s @ !ccobjs
diff --git a/myocamlbuild_config.mli b/myocamlbuild_config.mli
index 5eec98032..340ce687f 100644
--- a/myocamlbuild_config.mli
+++ b/myocamlbuild_config.mli
@@ -69,3 +69,4 @@ val toolchain : string
val ccomptype : string
val extralibs : string
val tk_defs : string
+val asm_cfi_supported : bool
diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile
index d04809aa3..f4bbd6e89 100644
--- a/ocamldoc/Makefile
+++ b/ocamldoc/Makefile
@@ -158,6 +158,7 @@ OCAMLCMOFILES=$(OCAMLSRCDIR)/parsing/printast.cmo \
$(OCAMLSRCDIR)/typing/predef.cmo \
$(OCAMLSRCDIR)/typing/datarepr.cmo \
$(OCAMLSRCDIR)/typing/subst.cmo \
+ $(OCAMLSRCDIR)/typing/cmi_format.cmo \
$(OCAMLSRCDIR)/typing/env.cmo \
$(OCAMLSRCDIR)/typing/ctype.cmo \
$(OCAMLSRCDIR)/typing/primitive.cmo \
@@ -168,6 +169,7 @@ OCAMLCMOFILES=$(OCAMLSRCDIR)/parsing/printast.cmo \
$(OCAMLSRCDIR)/typing/typedtree.cmo \
$(OCAMLSRCDIR)/typing/parmatch.cmo \
$(OCAMLSRCDIR)/typing/stypes.cmo \
+ $(OCAMLSRCDIR)/typing/cmt_format.cmo \
$(OCAMLSRCDIR)/typing/typecore.cmo \
$(OCAMLSRCDIR)/typing/includeclass.cmo \
$(OCAMLSRCDIR)/typing/typedecl.cmo \
diff --git a/ocamldoc/Makefile.nt b/ocamldoc/Makefile.nt
index a65b59738..9c9af694f 100644
--- a/ocamldoc/Makefile.nt
+++ b/ocamldoc/Makefile.nt
@@ -148,6 +148,7 @@ OCAMLCMOFILES=$(OCAMLSRCDIR)/parsing/printast.cmo \
$(OCAMLSRCDIR)/typing/predef.cmo \
$(OCAMLSRCDIR)/typing/datarepr.cmo \
$(OCAMLSRCDIR)/typing/subst.cmo \
+ $(OCAMLSRCDIR)/typing/cmi_format.cmo \
$(OCAMLSRCDIR)/typing/env.cmo \
$(OCAMLSRCDIR)/typing/ctype.cmo \
$(OCAMLSRCDIR)/typing/primitive.cmo \
diff --git a/ocamldoc/odoc_analyse.ml b/ocamldoc/odoc_analyse.ml
index bbcfaf93d..9e9cc1839 100644
--- a/ocamldoc/odoc_analyse.ml
+++ b/ocamldoc/odoc_analyse.ml
@@ -113,7 +113,10 @@ let process_implementation_file ppf sourcefile =
let env = initial_env () in
try
let parsetree = parse_file inputfile Parse.implementation ast_impl_magic_number in
- let typedtree = Typemod.type_implementation sourcefile prefixname modulename env parsetree in
+ let typedtree =
+ Typemod.type_implementation
+ sourcefile prefixname modulename env parsetree
+ in
(Some (parsetree, typedtree), inputfile)
with
e ->
@@ -164,6 +167,9 @@ let process_error exn =
| Env.Error err ->
Location.print_error_cur_file ppf;
Env.report_error ppf err
+ | Cmi_format.Error err ->
+ Location.print_error_cur_file ppf;
+ Cmi_format.report_error ppf err
| Ctype.Tags(l, l') ->
Location.print_error_cur_file ppf;
fprintf ppf
@@ -251,7 +257,7 @@ let process_file ppf sourcefile =
try
let (ast, signat, input_file) = process_interface_file ppf file in
let file_module = Sig_analyser.analyse_signature file
- !Location.input_name ast signat
+ !Location.input_name ast signat.sig_type
in
file_module.Odoc_module.m_top_deps <- Odoc_dep.intf_dependencies ast ;
@@ -288,7 +294,7 @@ let process_file ppf sourcefile =
let m =
{
Odoc_module.m_name = mod_name ;
- Odoc_module.m_type = Types.Tmty_signature [] ;
+ Odoc_module.m_type = Types.Mty_signature [] ;
Odoc_module.m_info = None ;
Odoc_module.m_is_interface = true ;
Odoc_module.m_file = file ;
diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml
index a6390ab23..26f813cad 100644
--- a/ocamldoc/odoc_ast.ml
+++ b/ocamldoc/odoc_ast.ml
@@ -54,50 +54,50 @@ module Typedtree_search =
| P of string
| IM of string
- type tab = (ele, Typedtree.structure_item) Hashtbl.t
+ type tab = (ele, Typedtree.structure_item_desc) Hashtbl.t
type tab_values = (Odoc_module.Name.t, Typedtree.pattern * Typedtree.expression) Hashtbl.t
let iter_val_pattern = function
| Typedtree.Tpat_any -> None
- | Typedtree.Tpat_var name -> Some (Name.from_ident name)
+ | Typedtree.Tpat_var (name, _) -> Some (Name.from_ident name)
| Typedtree.Tpat_tuple _ -> None (* A VOIR quand on traitera les tuples *)
| _ -> None
let add_to_hashes table table_values tt =
match tt with
- | Typedtree.Tstr_module (ident, _) ->
+ | Typedtree.Tstr_module (ident, _, _) ->
Hashtbl.add table (M (Name.from_ident ident)) tt
| Typedtree.Tstr_recmodule mods ->
List.iter
- (fun (ident,mod_expr) ->
+ (fun (ident,ident_loc, _, mod_expr) ->
Hashtbl.add table (M (Name.from_ident ident))
- (Typedtree.Tstr_module (ident,mod_expr))
+ (Typedtree.Tstr_module (ident,ident_loc, mod_expr))
)
mods
- | Typedtree.Tstr_modtype (ident, _) ->
+ | Typedtree.Tstr_modtype (ident, _, _) ->
Hashtbl.add table (MT (Name.from_ident ident)) tt
- | Typedtree.Tstr_exception (ident, _) ->
+ | Typedtree.Tstr_exception (ident, _, _) ->
Hashtbl.add table (E (Name.from_ident ident)) tt
- | Typedtree.Tstr_exn_rebind (ident, _) ->
+ | Typedtree.Tstr_exn_rebind (ident, _, _, _) ->
Hashtbl.add table (ER (Name.from_ident ident)) tt
| Typedtree.Tstr_type ident_type_decl_list ->
List.iter
- (fun (id, e) ->
+ (fun (id, id_loc, e) ->
Hashtbl.add table (T (Name.from_ident id))
- (Typedtree.Tstr_type [(id,e)]))
+ (Typedtree.Tstr_type [(id,id_loc,e)]))
ident_type_decl_list
| Typedtree.Tstr_class info_list ->
List.iter
- (fun ((id,_,_,_,_) as ci) ->
- Hashtbl.add table (C (Name.from_ident id))
- (Typedtree.Tstr_class [ci]))
+ (fun (ci, m, s) ->
+ Hashtbl.add table (C (Name.from_ident ci.ci_id_class))
+ (Typedtree.Tstr_class [ci, m, s]))
info_list
- | Typedtree.Tstr_cltype info_list ->
+ | Typedtree.Tstr_class_type info_list ->
List.iter
- (fun ((id,_) as ci) ->
+ (fun ((id,id_loc,_) as ci) ->
Hashtbl.add table
(CT (Name.from_ident id))
- (Typedtree.Tstr_cltype [ci]))
+ (Typedtree.Tstr_class_type [ci]))
info_list
| Typedtree.Tstr_value (_, pat_exp_list) ->
List.iter
@@ -107,7 +107,7 @@ module Typedtree_search =
| Some n -> Hashtbl.add table_values n (pat,exp)
)
pat_exp_list
- | Typedtree.Tstr_primitive (ident, _) ->
+ | Typedtree.Tstr_primitive (ident, _, _) ->
Hashtbl.add table (P (Name.from_ident ident)) tt
| Typedtree.Tstr_open _ -> ()
| Typedtree.Tstr_include _ -> ()
@@ -116,41 +116,42 @@ module Typedtree_search =
let tables typedtree =
let t = Hashtbl.create 13 in
let t_values = Hashtbl.create 13 in
- List.iter (add_to_hashes t t_values) typedtree;
+ List.iter (fun str -> add_to_hashes t t_values str.str_desc) typedtree;
(t, t_values)
let search_module table name =
match Hashtbl.find table (M name) with
- (Typedtree.Tstr_module (_, module_expr)) -> module_expr
+ (Typedtree.Tstr_module (_, _, module_expr)) -> module_expr
| _ -> assert false
let search_module_type table name =
match Hashtbl.find table (MT name) with
- | (Typedtree.Tstr_modtype (_, module_type)) -> module_type
+ | (Typedtree.Tstr_modtype (_, _, module_type)) -> module_type
| _ -> assert false
let search_exception table name =
match Hashtbl.find table (E name) with
- | (Typedtree.Tstr_exception (_, excep_decl)) -> excep_decl
+ | (Typedtree.Tstr_exception (_, _, excep_decl)) -> excep_decl
| _ -> assert false
let search_exception_rebind table name =
match Hashtbl.find table (ER name) with
- | (Typedtree.Tstr_exn_rebind (_, p)) -> p
+ | (Typedtree.Tstr_exn_rebind (_, _, p, _)) -> p
| _ -> assert false
let search_type_declaration table name =
match Hashtbl.find table (T name) with
- | (Typedtree.Tstr_type [(_,decl)]) -> decl
+ | (Typedtree.Tstr_type [(_,_, decl)]) -> decl
| _ -> assert false
let search_class_exp table name =
match Hashtbl.find table (C name) with
- | (Typedtree.Tstr_class [(_,_,_,ce,_)]) ->
+ | (Typedtree.Tstr_class [(ci, _, _ )]) ->
+ let ce = ci.ci_expr in
(
try
let type_decl = search_type_declaration table name in
- (ce, type_decl.Types.type_params)
+ (ce, type_decl.typ_type.Types.type_params)
with
Not_found ->
(ce, [])
@@ -159,50 +160,50 @@ module Typedtree_search =
let search_class_type_declaration table name =
match Hashtbl.find table (CT name) with
- | (Typedtree.Tstr_cltype [(_,cltype_decl)]) -> cltype_decl
+ | (Typedtree.Tstr_class_type [(_,_,cltype_decl)]) -> cltype_decl
| _ -> assert false
let search_value table name = Hashtbl.find table name
let search_primitive table name =
match Hashtbl.find table (P name) with
- Tstr_primitive (ident, val_desc) -> val_desc.Types.val_type
+ Tstr_primitive (ident, _, val_desc) -> val_desc.val_val.Types.val_type
| _ -> assert false
let get_nth_inherit_class_expr cls n =
let rec iter cpt = function
| [] ->
raise Not_found
- | Typedtree.Cf_inher (clexp, _, _) :: q ->
+ | { cf_desc = Typedtree.Tcf_inher (_, clexp, _, _, _) } :: q ->
if n = cpt then clexp else iter (cpt+1) q
| _ :: q ->
iter cpt q
in
- iter 0 cls.Typedtree.cl_field
+ iter 0 cls.Typedtree.cstr_fields
let search_attribute_type cls name =
let rec iter = function
| [] ->
raise Not_found
- | Typedtree.Cf_val (_, ident, Some exp, _) :: q
+ | { cf_desc = Typedtree.Tcf_val (_, _, _, ident, Tcfk_concrete exp, _) } :: q
when Name.from_ident ident = name ->
exp.Typedtree.exp_type
| _ :: q ->
iter q
in
- iter cls.Typedtree.cl_field
+ iter cls.Typedtree.cstr_fields
let class_sig_of_cltype_decl =
let rec iter = function
- Types.Tcty_constr (_, _, cty) -> iter cty
- | Types.Tcty_signature s -> s
- | Types.Tcty_fun (_,_, cty) -> iter cty
+ Types.Cty_constr (_, _, cty) -> iter cty
+ | Types.Cty_signature s -> s
+ | Types.Cty_fun (_,_, cty) -> iter cty
in
fun ct_decl -> iter ct_decl.Types.clty_type
let search_virtual_attribute_type table ctname name =
let ct_decl = search_class_type_declaration table ctname in
- let cls_sig = class_sig_of_cltype_decl ct_decl in
+ let cls_sig = class_sig_of_cltype_decl ct_decl.ci_type_decl in
let (_,_,texp) = Types.Vars.find name cls_sig.cty_vars in
texp
@@ -210,12 +211,12 @@ module Typedtree_search =
let rec iter = function
| [] ->
raise Not_found
- | Typedtree.Cf_meth (label, exp) :: q when label = name ->
+ | { cf_desc = Typedtree.Tcf_meth (label, _, _, Tcfk_concrete exp, _) } :: q when label = name ->
exp
| _ :: q ->
iter q
in
- iter cls.Typedtree.cl_field
+ iter cls.Typedtree.cstr_fields
end
module Analyser =
@@ -253,14 +254,14 @@ module Analyser =
let tt_param_info_from_pattern env f_desc pat =
let rec iter_pattern pat =
match pat.pat_desc with
- Typedtree.Tpat_var ident ->
+ Typedtree.Tpat_var (ident, _) ->
let name = Name.from_ident ident in
Simple_name { sn_name = name ;
sn_text = f_desc name ;
sn_type = Odoc_env.subst_type env pat.pat_type
}
- | Typedtree.Tpat_alias (pat, _) ->
+ | Typedtree.Tpat_alias (pat, _, _) ->
iter_pattern pat
| Typedtree.Tpat_tuple patlist ->
@@ -268,7 +269,7 @@ module Analyser =
(List.map iter_pattern patlist,
Odoc_env.subst_type env pat.pat_type)
- | Typedtree.Tpat_construct (cons_desc, _) when
+ | Typedtree.Tpat_construct (_, _, cons_desc, _, _) when
(* we give a name to the parameter only if it unit *)
(match cons_desc.cstr_res.desc with
Tconstr (p, _, _) ->
@@ -322,7 +323,7 @@ module Analyser =
(
(
match func_body.exp_desc with
- Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, func_body2) ->
+ Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var (id, _) } , exp) :: _, func_body2) ->
let name = Name.from_ident id in
let new_param = Simple_name
{ sn_name = name ;
@@ -341,7 +342,7 @@ module Analyser =
in
(* continue if the body is still a function *)
match next_exp.exp_desc with
- Texp_function (pat_exp_list, _) ->
+ Texp_function (_, pat_exp_list, _) ->
p :: (tt_analyse_function_parameters env current_comment_opt pat_exp_list)
| _ ->
(* something else ; no more parameter *)
@@ -352,7 +353,7 @@ module Analyser =
let tt_analyse_value env current_module_name comment_opt loc pat_exp rec_flag =
let (pat, exp) = pat_exp in
match (pat.pat_desc, exp.exp_desc) with
- (Typedtree.Tpat_var ident, Typedtree.Texp_function (pat_exp_list2, partial)) ->
+ (Typedtree.Tpat_var (ident, _), Typedtree.Texp_function (_, pat_exp_list2, partial)) ->
(* a new function is defined *)
let name_pre = Name.from_ident ident in
let name = Name.parens_if_infix name_pre in
@@ -370,7 +371,7 @@ module Analyser =
in
[ new_value ]
- | (Typedtree.Tpat_var ident, _) ->
+ | (Typedtree.Tpat_var (ident, _), _) ->
(* a new value is defined *)
let name_pre = Name.from_ident ident in
let name = Name.parens_if_infix name_pre in
@@ -411,9 +412,9 @@ module Analyser =
);
*)
match clexp.Typedtree.cl_desc with
- Typedtree.Tclass_ident p -> Name.from_path p
- | Typedtree.Tclass_constraint (class_expr, _, _, _)
- | Typedtree.Tclass_apply (class_expr, _) -> tt_name_of_class_expr class_expr
+ Typedtree.Tcl_ident (p, _, _) -> Name.from_path p
+ | Typedtree.Tcl_constraint (class_expr, _, _, _, _)
+ | Typedtree.Tcl_apply (class_expr, _) -> tt_name_of_class_expr class_expr
(*
| Typedtree.Tclass_fun (_, _, class_expr, _) -> tt_name_of_class_expr class_expr
| Typedtree.Tclass_let (_,_,_, class_expr) -> tt_name_of_class_expr class_expr
@@ -427,7 +428,7 @@ module Analyser =
*)
let rec tt_analyse_method_expression env current_method_name comment_opt ?(first=true) exp =
match exp.Typedtree.exp_desc with
- Typedtree.Texp_function (pat_exp_list, _) ->
+ Typedtree.Texp_function (_, pat_exp_list, _) ->
(
match pat_exp_list with
[] ->
@@ -467,7 +468,7 @@ module Analyser =
(
(
match body.exp_desc with
- Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, body2) ->
+ Typedtree.Texp_let (_, ({pat_desc = Typedtree.Tpat_var (id, _) } , exp) :: _, body2) ->
let name = Name.from_ident id in
let new_param = Simple_name
{ sn_name = name ;
@@ -513,8 +514,10 @@ module Analyser =
ele_coms
in
(acc_inher, acc_fields @ ele_comments)
-
- | (Parsetree.Pcf_inher (_, p_clexp, _)) :: q ->
+ | item :: q ->
+ let loc = item.Parsetree.pcf_loc in
+ match item.Parsetree.pcf_desc with
+ | (Parsetree.Pcf_inher (_, p_clexp, _)) ->
let tt_clexp =
let n = List.length acc_inher in
try Typedtree_search.get_nth_inherit_class_expr tt_cls n
@@ -541,8 +544,8 @@ module Analyser =
p_clexp.Parsetree.pcl_loc.Location.loc_end.Lexing.pos_cnum
q
- | ((Parsetree.Pcf_val (label, mutable_flag, _, _, loc) |
- Parsetree.Pcf_valvirt (label, mutable_flag, _, loc) ) as x) :: q ->
+ | ((Parsetree.Pcf_val ({ txt = label }, mutable_flag, _, _) |
+ Parsetree.Pcf_valvirt ({ txt = label }, mutable_flag, _) ) as x) ->
let virt = match x with Parsetree.Pcf_val _ -> false | _ -> true in
let complete_name = Name.concat current_class_name label in
let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
@@ -572,7 +575,7 @@ module Analyser =
in
iter acc_inher (acc_fields @ ele_comments @ [ Class_attribute att ]) loc.Location.loc_end.Lexing.pos_cnum q
- | (Parsetree.Pcf_virt (label, private_flag, _, loc)) :: q ->
+ | (Parsetree.Pcf_virt ({ txt = label }, private_flag, _)) ->
let complete_name = Name.concat current_class_name label in
let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
let met_type =
@@ -606,7 +609,7 @@ module Analyser =
iter acc_inher (acc_fields @ ele_comments @ [ Class_method met ]) loc.Location.loc_end.Lexing.pos_cnum q
- | (Parsetree.Pcf_meth (label, private_flag, _, _, loc)) :: q ->
+ | (Parsetree.Pcf_meth ({ txt = label }, private_flag, _, _)) ->
let complete_name = Name.concat current_class_name label in
let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
let exp =
@@ -640,14 +643,14 @@ module Analyser =
iter acc_inher (acc_fields @ ele_comments @ [ Class_method met ]) loc.Location.loc_end.Lexing.pos_cnum q
- | Parsetree.Pcf_cstr (_, _, loc) :: q ->
+ | Parsetree.Pcf_constr (_, _) ->
(* don't give a $*%@ ! *)
iter acc_inher acc_fields loc.Location.loc_end.Lexing.pos_cnum q
- | (Parsetree.Pcf_init exp) :: q ->
+ | (Parsetree.Pcf_init exp) ->
iter acc_inher acc_fields exp.Parsetree.pexp_loc.Location.loc_end.Lexing.pos_cnum q
in
- iter [] [] last_pos (snd p_cls)
+ iter [] [] last_pos (p_cls.Parsetree.pcstr_fields)
(** Analysis of a [Parsetree.class_expr] and a [Typedtree.class_expr] to get a a couple (class parameters, class kind). *)
let rec analyse_class_kind env current_class_name comment_opt last_pos p_class_expr tt_class_exp table =
@@ -655,17 +658,17 @@ module Analyser =
(Parsetree.Pcl_constr (lid, _), tt_class_exp_desc ) ->
let name =
match tt_class_exp_desc with
- Typedtree.Tclass_ident p -> Name.from_path p
+ Typedtree.Tcl_ident (p,_,_) -> Name.from_path p
| _ ->
(* we try to get the name from the environment. *)
(* A VOIR : dommage qu'on n'ait pas un Tclass_ident :-( m�me quand on a class tutu = toto *)
- Name.from_longident lid
+ Name.from_longident lid.txt
in
(* On n'a pas ici les param�tres de type sous forme de Types.type_expr,
par contre on peut les trouver dans le class_type *)
let params =
match tt_class_exp.Typedtree.cl_type with
- Types.Tcty_constr (p2, type_exp_list, cltyp) ->
+ Types.Cty_constr (p2, type_exp_list, cltyp) ->
(* cltyp is the class type for [type_exp_list] p *)
type_exp_list
| _ ->
@@ -679,11 +682,11 @@ module Analyser =
cco_type_parameters = List.map (Odoc_env.subst_type env) params ;
} )
- | (Parsetree.Pcl_structure p_class_structure, Typedtree.Tclass_structure tt_class_structure) ->
+ | (Parsetree.Pcl_structure p_class_structure, Typedtree.Tcl_structure tt_class_structure) ->
(* we need the class signature to get the type of methods in analyse_class_structure *)
let tt_class_sig =
match tt_class_exp.Typedtree.cl_type with
- Types.Tcty_signature class_sig -> class_sig
+ Types.Cty_signature class_sig -> class_sig
| _ -> raise (Failure "analyse_class_kind: no class signature for a class structure.")
in
let (inherited_classes, class_elements) = analyse_class_structure
@@ -700,16 +703,16 @@ module Analyser =
Class_structure (inherited_classes, class_elements) )
| (Parsetree.Pcl_fun (label, expression_opt, pattern, p_class_expr2),
- Typedtree.Tclass_fun (pat, ident_exp_list, tt_class_expr2, partial)) ->
+ Typedtree.Tcl_fun (_, pat, ident_exp_list, tt_class_expr2, partial)) ->
(* we check that this is not an optional parameter with
a default value. In this case, we look for the good parameter pattern *)
let (parameter, next_tt_class_exp) =
match pat.Typedtree.pat_desc with
- Typedtree.Tpat_var ident when Name.from_ident ident = "*opt*" ->
+ Typedtree.Tpat_var (ident, _) when Name.from_ident ident = "*opt*" ->
(
- (* there must be a Tclass_let just after *)
+ (* there must be a Tcl_let just after *)
match tt_class_expr2.Typedtree.cl_desc with
- Typedtree.Tclass_let (_, ({pat_desc = Typedtree.Tpat_var id } , exp) :: _, _, tt_class_expr3) ->
+ Typedtree.Tcl_let (_, ({pat_desc = Typedtree.Tpat_var (id,_) } , exp) :: _, _, tt_class_expr3) ->
let name = Name.from_ident id in
let new_param = Simple_name
{ sn_name = name ;
@@ -739,23 +742,23 @@ module Analyser =
in
(parameter :: params, k)
- | (Parsetree.Pcl_apply (p_class_expr2, _), Tclass_apply (tt_class_expr2, exp_opt_optional_list)) ->
+ | (Parsetree.Pcl_apply (p_class_expr2, _), Tcl_apply (tt_class_expr2, exp_opt_optional_list)) ->
let applied_name =
(* we want an ident, or else the class applied will appear in the form object ... end,
because if the class applied has no name, the code is kinda ugly, isn't it ? *)
match tt_class_expr2.Typedtree.cl_desc with
- Typedtree.Tclass_ident p -> Name.from_path p (* A VOIR : obtenir le nom complet *)
+ Typedtree.Tcl_ident (p,_,_) -> Name.from_path p (* A VOIR : obtenir le nom complet *)
| _ ->
(* A VOIR : dommage qu'on n'ait pas un Tclass_ident :-( m�me quand on a class tutu = toto *)
match p_class_expr2.Parsetree.pcl_desc with
Parsetree.Pcl_constr (lid, _) ->
(* we try to get the name from the environment. *)
- Name.from_longident lid
+ Name.from_longident lid.txt
| _ ->
Odoc_messages.object_end
in
let param_exps = List.fold_left
- (fun acc -> fun (exp_opt, _) ->
+ (fun acc -> fun (_, exp_opt, _) ->
match exp_opt with
None -> acc
| Some e -> acc @ [e])
@@ -778,14 +781,14 @@ module Analyser =
capp_params_code = params_code ;
} )
- | (Parsetree.Pcl_let (_, _, p_class_expr2), Typedtree.Tclass_let (_, _, _, tt_class_expr2)) ->
+ | (Parsetree.Pcl_let (_, _, p_class_expr2), Typedtree.Tcl_let (_, _, _, tt_class_expr2)) ->
(* we don't care about these lets *)
analyse_class_kind
env current_class_name comment_opt last_pos p_class_expr2
tt_class_expr2 table
| (Parsetree.Pcl_constraint (p_class_expr2, p_class_type2),
- Typedtree.Tclass_constraint (tt_class_expr2, _, _, _)) ->
+ Typedtree.Tcl_constraint (tt_class_expr2, _, _, _, _)) ->
let (l, class_kind) = analyse_class_kind
env current_class_name comment_opt last_pos p_class_expr2
tt_class_expr2 table
@@ -810,7 +813,7 @@ module Analyser =
(** Analysis of a [Parsetree.class_declaration] and a [Typedtree.class_expr] to return a [t_class].*)
let analyse_class env current_module_name comment_opt p_class_decl tt_type_params tt_class_exp table =
let name = p_class_decl.Parsetree.pci_name in
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let pos_start = p_class_decl.Parsetree.pci_expr.Parsetree.pcl_loc.Location.loc_start.Lexing.pos_cnum in
let type_parameters = tt_type_params in
let virt = p_class_decl.Parsetree.pci_virt = Asttypes.Virtual in
@@ -842,8 +845,8 @@ module Analyser =
is not an ident of a constraint on an ident. *)
let rec tt_name_from_module_expr mod_expr =
match mod_expr.Typedtree.mod_desc with
- Typedtree.Tmod_ident p -> Name.from_path p
- | Typedtree.Tmod_constraint (m_exp, _, _) -> tt_name_from_module_expr m_exp
+ Typedtree.Tmod_ident (p,_) -> Name.from_path p
+ | Typedtree.Tmod_constraint (m_exp, _, _, _) -> tt_name_from_module_expr m_exp
| Typedtree.Tmod_structure _
| Typedtree.Tmod_functor _
| Typedtree.Tmod_apply _
@@ -853,7 +856,7 @@ module Analyser =
(** Get the list of included modules in a module structure of a typed tree. *)
let tt_get_included_module_list tt_structure =
let f acc item =
- match item with
+ match item.str_desc with
Typedtree.Tstr_include (mod_expr, _) ->
acc @ [
{ (* A VOIR : chercher dans les modules et les module types, avec quel env ? *)
@@ -865,7 +868,7 @@ module Analyser =
| _ ->
acc
in
- List.fold_left f [] tt_structure
+ List.fold_left f [] tt_structure.str_items
(** This function takes a [module element list] of a module and replaces the "dummy" included modules with
the ones found in typed tree structure of the module. *)
@@ -888,7 +891,7 @@ module Analyser =
and the module has a "structure" kind. *)
let rec filter_module_with_module_type_constraint m mt =
match m.m_kind, mt with
- Module_struct l, Types.Tmty_signature lsig ->
+ Module_struct l, Types.Mty_signature lsig ->
m.m_kind <- Module_struct (filter_module_elements_with_module_type_constraint l lsig);
m.m_type <- mt;
| _ -> ()
@@ -898,7 +901,7 @@ module Analyser =
and the module type has a "structure" kind. *)
and filter_module_type_with_module_type_constraint mtyp mt =
match mtyp.mt_kind, mt with
- Some Module_type_struct l, Types.Tmty_signature lsig ->
+ Some Module_type_struct l, Types.Mty_signature lsig ->
mtyp.mt_kind <- Some (Module_type_struct (filter_module_elements_with_module_type_constraint l lsig));
mtyp.mt_type <- Some mt;
| _ -> ()
@@ -908,7 +911,7 @@ module Analyser =
let f = match ele with
Element_module m ->
(function
- Types.Tsig_module (ident,t,_) ->
+ Types.Sig_module (ident,t,_) ->
let n1 = Name.simple m.m_name
and n2 = Ident.name ident in
(
@@ -919,7 +922,7 @@ module Analyser =
| _ -> false)
| Element_module_type mt ->
(function
- Types.Tsig_modtype (ident,Types.Tmodtype_manifest t) ->
+ Types.Sig_modtype (ident,Types.Modtype_manifest t) ->
let n1 = Name.simple mt.mt_name
and n2 = Ident.name ident in
(
@@ -930,14 +933,14 @@ module Analyser =
| _ -> false)
| Element_value v ->
(function
- Types.Tsig_value (ident,_) ->
+ Types.Sig_value (ident,_) ->
let n1 = Name.simple v.val_name
and n2 = Ident.name ident in
n1 = n2
| _ -> false)
| Element_type t ->
(function
- Types.Tsig_type (ident,_,_) ->
+ Types.Sig_type (ident,_,_) ->
(* A VOIR: il est possible que le d�tail du type soit cach� *)
let n1 = Name.simple t.ty_name
and n2 = Ident.name ident in
@@ -945,21 +948,21 @@ module Analyser =
| _ -> false)
| Element_exception e ->
(function
- Types.Tsig_exception (ident,_) ->
+ Types.Sig_exception (ident,_) ->
let n1 = Name.simple e.ex_name
and n2 = Ident.name ident in
n1 = n2
| _ -> false)
| Element_class c ->
(function
- Types.Tsig_class (ident,_,_) ->
+ Types.Sig_class (ident,_,_) ->
let n1 = Name.simple c.cl_name
and n2 = Ident.name ident in
n1 = n2
| _ -> false)
| Element_class_type ct ->
(function
- Types.Tsig_cltype (ident,_,_) ->
+ Types.Sig_class_type (ident,_,_) ->
let n1 = Name.simple ct.clt_name
and n2 = Ident.name ident in
n1 = n2
@@ -974,7 +977,7 @@ module Analyser =
(** Analysis of a parse tree structure with a typed tree, to return module elements.*)
let rec analyse_structure env current_module_name last_pos pos_limit parsetree typedtree =
print_DEBUG "Odoc_ast:analyse_struture";
- let (table, table_values) = Typedtree_search.tables typedtree in
+ let (table, table_values) = Typedtree_search.tables typedtree.str_items in
let rec iter env last_pos = function
[] ->
let s = get_string_of_file last_pos pos_limit in
@@ -1047,7 +1050,7 @@ module Analyser =
iter new_last_pos acc_env acc q
| Some name ->
try
- let pat_exp = Typedtree_search.search_value table_values name in
+ let pat_exp = Typedtree_search.search_value table_values name.txt in
let (info_opt, ele_comments) =
(* we already have the optional comment for the first value. *)
if first then
@@ -1085,7 +1088,7 @@ module Analyser =
let (new_env, l_ele) = iter ~first: true loc.Location.loc_start.Lexing.pos_cnum env [] pat_exp_list in
(0, new_env, l_ele)
- | Parsetree.Pstr_primitive (name_pre, val_desc) ->
+ | Parsetree.Pstr_primitive ({ txt = name_pre }, val_desc) ->
(* of string * value_description *)
print_DEBUG ("Parsetree.Pstr_primitive ("^name_pre^", ["^(String.concat ", " val_desc.Parsetree.pval_prim)^"]");
let typ = Typedtree_search.search_primitive table name_pre in
@@ -1109,7 +1112,7 @@ module Analyser =
(* we start by extending the environment *)
let new_env =
List.fold_left
- (fun acc_env -> fun (name, _) ->
+ (fun acc_env -> fun ({ txt = name }, _) ->
let complete_name = Name.concat current_module_name name in
Odoc_env.add_type acc_env complete_name
)
@@ -1119,7 +1122,7 @@ module Analyser =
let rec f ?(first=false) maybe_more_acc last_pos name_type_decl_list =
match name_type_decl_list with
[] -> (maybe_more_acc, [])
- | (name, type_decl) :: q ->
+ | ({ txt = name }, type_decl) :: q ->
let complete_name = Name.concat current_module_name name in
let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in
let loc_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum in
@@ -1130,21 +1133,22 @@ module Analyser =
in
let (maybe_more, name_comment_list) =
Sig.name_comment_from_type_kind
- loc_end
- pos_limit2
- type_decl.Parsetree.ptype_kind
- in
- let tt_type_decl =
- try Typedtree_search.search_type_declaration table name
- with Not_found -> raise (Failure (Odoc_messages.type_not_found_in_typedtree complete_name))
- in
- let (com_opt, ele_comments) = (* the comment for the first type was already retrieved *)
- if first then
- (comment_opt , [])
- else
- get_comments_in_module last_pos loc_start
- in
- let kind = Sig.get_type_kind
+ loc_end
+ pos_limit2
+ type_decl.Parsetree.ptype_kind
+ in
+ let tt_type_decl =
+ try Typedtree_search.search_type_declaration table name
+ with Not_found -> raise (Failure (Odoc_messages.type_not_found_in_typedtree complete_name))
+ in
+ let tt_type_decl = tt_type_decl.Typedtree.typ_type in
+ let (com_opt, ele_comments) = (* the comment for the first type was already retrieved *)
+ if first then
+ (comment_opt , [])
+ else
+ get_comments_in_module last_pos loc_start
+ in
+ let kind = Sig.get_type_kind
new_env name_comment_list
tt_type_decl.Types.type_kind
in
@@ -1191,10 +1195,10 @@ module Analyser =
| Parsetree.Pstr_exception (name, excep_decl) ->
(* a new exception is defined *)
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
(* we get the exception declaration in the typed tree *)
let tt_excep_decl =
- try Typedtree_search.search_exception table name
+ try Typedtree_search.search_exception table name.txt
with Not_found ->
raise (Failure (Odoc_messages.exception_not_found_in_typedtree complete_name))
in
@@ -1205,7 +1209,9 @@ module Analyser =
{
ex_name = complete_name ;
ex_info = comment_opt ;
- ex_args = List.map (Odoc_env.subst_type new_env) tt_excep_decl.exn_args ;
+ ex_args = List.map (fun ctyp ->
+ Odoc_env.subst_type new_env ctyp.ctyp_type)
+ tt_excep_decl.exn_params ;
ex_alias = None ;
ex_loc = { loc_impl = Some (!file_name, loc.Location.loc_start.Lexing.pos_cnum) ; loc_inter = None } ;
ex_code =
@@ -1219,12 +1225,12 @@ module Analyser =
in
(0, new_env, [ Element_exception new_ex ])
- | Parsetree.Pstr_exn_rebind (name, _) ->
+ | Parsetree.Pstr_exn_rebind (name, _) ->
(* a new exception is defined *)
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
(* we get the exception rebind in the typed tree *)
let tt_path =
- try Typedtree_search.search_exception_rebind table name
+ try Typedtree_search.search_exception_rebind table name.txt
with Not_found ->
raise (Failure (Odoc_messages.exception_not_found_in_typedtree complete_name))
in
@@ -1246,11 +1252,11 @@ module Analyser =
(
(* of string * module_expr *)
try
- let tt_module_expr = Typedtree_search.search_module table name in
+ let tt_module_expr = Typedtree_search.search_module table name.txt in
let new_module_pre = analyse_module
env
current_module_name
- name
+ name.txt
comment_opt
module_expr
tt_module_expr
@@ -1271,7 +1277,7 @@ module Analyser =
let new_env2 =
match new_module.m_type with
(* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *)
- Types.Tmty_signature s ->
+ Types.Mty_signature s ->
Odoc_env.add_signature new_env new_module.m_name
~rel: (Name.simple new_module.m_name) s
| _ ->
@@ -1280,7 +1286,7 @@ module Analyser =
(0, new_env2, [ Element_module new_module ])
with
Not_found ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
raise (Failure (Odoc_messages.module_not_found_in_typedtree complete_name))
)
@@ -1290,22 +1296,22 @@ module Analyser =
let new_env =
List.fold_left
(fun acc_env (name, _, mod_exp) ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let e = Odoc_env.add_module acc_env complete_name in
let tt_mod_exp =
- try Typedtree_search.search_module table name
+ try Typedtree_search.search_module table name.txt
with Not_found -> raise (Failure (Odoc_messages.module_not_found_in_typedtree complete_name))
in
let new_module = analyse_module
e
current_module_name
- name
+ name.txt
None
mod_exp
tt_mod_exp
in
match new_module.m_type with
- Types.Tmty_signature s ->
+ Types.Mty_signature s ->
Odoc_env.add_signature e new_module.m_name
~rel: (Name.simple new_module.m_name) s
| _ ->
@@ -1318,11 +1324,11 @@ module Analyser =
match name_mod_exp_list with
[] -> []
| (name, _, mod_exp) :: q ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let loc_start = mod_exp.Parsetree.pmod_loc.Location.loc_start.Lexing.pos_cnum in
let loc_end = mod_exp.Parsetree.pmod_loc.Location.loc_end.Lexing.pos_cnum in
let tt_mod_exp =
- try Typedtree_search.search_module table name
+ try Typedtree_search.search_module table name.txt
with Not_found -> raise (Failure (Odoc_messages.module_not_found_in_typedtree complete_name))
in
let (com_opt, ele_comments) = (* the comment for the first type was already retrieved *)
@@ -1334,7 +1340,7 @@ module Analyser =
let new_module = analyse_module
new_env
current_module_name
- name
+ name.txt
com_opt
mod_exp
tt_mod_exp
@@ -1346,20 +1352,20 @@ module Analyser =
(0, new_env, eles)
| Parsetree.Pstr_modtype (name, modtype) ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let tt_module_type =
- try Typedtree_search.search_module_type table name
+ try Typedtree_search.search_module_type table name.txt
with Not_found ->
raise (Failure (Odoc_messages.module_type_not_found_in_typedtree complete_name))
in
let kind = Sig.analyse_module_type_kind env complete_name
- modtype tt_module_type
+ modtype tt_module_type.mty_type
in
let mt =
{
mt_name = complete_name ;
mt_info = comment_opt ;
- mt_type = Some tt_module_type ;
+ mt_type = Some tt_module_type.mty_type ;
mt_is_interface = false ;
mt_file = !file_name ;
mt_kind = Some kind ;
@@ -1368,9 +1374,9 @@ module Analyser =
in
let new_env = Odoc_env.add_module_type env mt.mt_name in
let new_env2 =
- match tt_module_type with
+ match tt_module_type.mty_type with
(* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on n'aurait pas la signature *)
- Types.Tmty_signature s ->
+ Types.Mty_signature s ->
Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s
| _ ->
new_env
@@ -1393,7 +1399,7 @@ module Analyser =
let new_env =
List.fold_left
(fun acc_env -> fun class_decl ->
- let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name in
+ let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name.txt in
Odoc_env.add_class acc_env complete_name
)
env
@@ -1405,9 +1411,9 @@ module Analyser =
[]
| class_decl :: q ->
let (tt_class_exp, tt_type_params) =
- try Typedtree_search.search_class_exp table class_decl.Parsetree.pci_name
+ try Typedtree_search.search_class_exp table class_decl.Parsetree.pci_name.txt
with Not_found ->
- let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name in
+ let complete_name = Name.concat current_module_name class_decl.Parsetree.pci_name.txt in
raise (Failure (Odoc_messages.class_not_found_in_typedtree complete_name))
in
let (com_opt, ele_comments) =
@@ -1435,7 +1441,7 @@ module Analyser =
let new_env =
List.fold_left
(fun acc_env -> fun class_type_decl ->
- let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in
+ let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name.txt in
Odoc_env.add_class_type acc_env complete_name
)
env
@@ -1447,13 +1453,14 @@ module Analyser =
[]
| class_type_decl :: q ->
let name = class_type_decl.Parsetree.pci_name in
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let virt = class_type_decl.Parsetree.pci_virt = Asttypes.Virtual in
let tt_cltype_declaration =
- try Typedtree_search.search_class_type_declaration table name
+ try Typedtree_search.search_class_type_declaration table name.txt
with Not_found ->
raise (Failure (Odoc_messages.class_type_not_found_in_typedtree complete_name))
- in
+ in
+ let tt_cltype_declaration = tt_cltype_declaration.ci_type_decl in
let type_params = tt_cltype_declaration.Types.clty_params in
let kind = Sig.analyse_class_type_kind
new_env
@@ -1533,7 +1540,7 @@ module Analyser =
}
in
match (p_module_expr.Parsetree.pmod_desc, tt_module_expr.Typedtree.mod_desc) with
- (Parsetree.Pmod_ident longident, Typedtree.Tmod_ident path) ->
+ (Parsetree.Pmod_ident longident, Typedtree.Tmod_ident (path, _)) ->
let alias_name = Odoc_env.full_module_name env (Name.from_path path) in
{ m_base with m_kind = Module_alias { ma_name = alias_name ;
ma_module = None ; } }
@@ -1546,19 +1553,19 @@ module Analyser =
{ m_base with m_kind = Module_struct elements2 }
| (Parsetree.Pmod_functor (_, pmodule_type, p_module_expr2),
- Typedtree.Tmod_functor (ident, mtyp, tt_module_expr2)) ->
+ Typedtree.Tmod_functor (ident, _, mtyp, tt_module_expr2)) ->
let loc_start = pmodule_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let loc_end = pmodule_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let mp_type_code = get_string_of_file loc_start loc_end in
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
let mp_name = Name.from_ident ident in
let mp_kind = Sig.analyse_module_type_kind env
- current_module_name pmodule_type mtyp
+ current_module_name pmodule_type mtyp.mty_type
in
let param =
{
mp_name = mp_name ;
- mp_type = Odoc_env.subst_module_type env mtyp ;
+ mp_type = Odoc_env.subst_module_type env mtyp.mty_type ;
mp_type_code = mp_type_code ;
mp_kind = mp_kind ;
}
@@ -1581,7 +1588,7 @@ module Analyser =
Typedtree.Tmod_apply (tt_module_expr1, tt_module_expr2, _))
| (Parsetree.Pmod_apply (p_module_expr1, p_module_expr2),
Typedtree.Tmod_constraint
- ({ Typedtree.mod_desc = Typedtree.Tmod_apply (tt_module_expr1, tt_module_expr2, _)},
+ ({ Typedtree.mod_desc = Typedtree.Tmod_apply (tt_module_expr1, tt_module_expr2, _)}, _,
_, _)
) ->
let m1 = analyse_module
@@ -1603,7 +1610,7 @@ module Analyser =
{ m_base with m_kind = Module_apply (m1.m_kind, m2.m_kind) }
| (Parsetree.Pmod_constraint (p_module_expr2, p_modtype),
- Typedtree.Tmod_constraint (tt_module_expr2, tt_modtype, _)) ->
+ Typedtree.Tmod_constraint (tt_module_expr2, tt_modtype, _, _)) ->
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_constraint + Typedtree.Tmod_constraint "^module_name);
let m_base2 = analyse_module
env
@@ -1629,7 +1636,7 @@ module Analyser =
| (Parsetree.Pmod_structure p_structure,
Typedtree.Tmod_constraint
({ Typedtree.mod_desc = Typedtree.Tmod_structure tt_structure},
- tt_modtype, _)
+ tt_modtype, _, _)
) ->
(* needed for recursive modules *)
@@ -1643,7 +1650,7 @@ module Analyser =
m_kind = Module_struct elements2 ;
}
- | (Parsetree.Pmod_unpack (p_exp),
+ | (Parsetree.Pmod_unpack p_exp,
Typedtree.Tmod_unpack (t_exp, tt_modtype)) ->
print_DEBUG ("Odoc_ast: case Parsetree.Pmod_unpack + Typedtree.Tmod_unpack "^module_name);
let code =
@@ -1657,7 +1664,7 @@ module Analyser =
(* let name = Odoc_env.full_module_type_name env (Name.from_path (fst pkg_type)) in *)
let name =
match tt_modtype with
- | Tmty_ident p ->
+ | Mty_ident p ->
Odoc_env.full_module_type_name env (Name.from_path p)
| _ -> ""
in
@@ -1720,7 +1727,7 @@ module Analyser =
let kind = Module_struct elements2 in
{
m_name = mod_name ;
- m_type = Types.Tmty_signature [] ;
+ m_type = Types.Mty_signature [] ;
m_info = info_opt ;
m_is_interface = false ;
m_file = !file_name ;
diff --git a/ocamldoc/odoc_ast.mli b/ocamldoc/odoc_ast.mli
index 48ba98bfb..d7c111f85 100644
--- a/ocamldoc/odoc_ast.mli
+++ b/ocamldoc/odoc_ast.mli
@@ -20,7 +20,7 @@ module Typedtree_search :
sig
type ele
- type tab = (ele, Typedtree.structure_item) Hashtbl.t
+ type tab = (ele, Typedtree.structure_item_desc) Hashtbl.t
type tab_values = (Odoc_name.t, Typedtree.pattern * Typedtree.expression) Hashtbl.t
(** Create hash tables used to search by some of the functions below. *)
@@ -34,12 +34,12 @@ module Typedtree_search :
(** This function returns the [Types.module_type] associated to the given module type name,
in the given table.
@raise Not_found if the module type was not found.*)
- val search_module_type : tab -> string -> Types.module_type
+ val search_module_type : tab -> string -> Typedtree.module_type
(** This function returns the [Types.exception_declaration] associated to the given exception name,
in the given table.
@raise Not_found if the exception was not found.*)
- val search_exception : tab -> string -> Types.exception_declaration
+ val search_exception : tab -> string -> Typedtree.exception_declaration
(** This function returns the [Path.t] associated to the given exception rebind name,
in the table.
@@ -49,7 +49,7 @@ module Typedtree_search :
(** This function returns the [Typedtree.type_declaration] associated to the given type name,
in the given table.
@raise Not_found if the type was not found. *)
- val search_type_declaration : tab -> string -> Types.type_declaration
+ val search_type_declaration : tab -> string -> Typedtree.type_declaration
(** This function returns the [Typedtree.class_expr] and type parameters
associated to the given class name, in the given table.
@@ -59,7 +59,7 @@ module Typedtree_search :
(** This function returns the [Types.cltype_declaration] associated to the given class type name,
in the given table.
@raise Not_found if the class type was not found. *)
- val search_class_type_declaration : tab -> string -> Types.cltype_declaration
+ val search_class_type_declaration : tab -> string -> Typedtree.class_type_declaration
(** This function returns the couple (pat, exp) for the given value name, in the
given table of values.
diff --git a/ocamldoc/odoc_env.ml b/ocamldoc/odoc_env.ml
index a108cf416..ef0bb63b6 100644
--- a/ocamldoc/odoc_env.ml
+++ b/ocamldoc/odoc_env.ml
@@ -51,30 +51,30 @@ let rec add_signature env root ?rel signat =
in
let f env item =
match item with
- Types.Tsig_value (ident, _) -> { env with env_values = (rel_name ident, qualify ident) :: env.env_values }
- | Types.Tsig_type (ident,_,_) -> { env with env_types = (rel_name ident, qualify ident) :: env.env_types }
- | Types.Tsig_exception (ident, _) -> { env with env_exceptions = (rel_name ident, qualify ident) :: env.env_exceptions }
- | Types.Tsig_module (ident, modtype, _) ->
+ Types.Sig_value (ident, _) -> { env with env_values = (rel_name ident, qualify ident) :: env.env_values }
+ | Types.Sig_type (ident,_,_) -> { env with env_types = (rel_name ident, qualify ident) :: env.env_types }
+ | Types.Sig_exception (ident, _) -> { env with env_exceptions = (rel_name ident, qualify ident) :: env.env_exceptions }
+ | Types.Sig_module (ident, modtype, _) ->
let env2 =
match modtype with (* A VOIR : le cas o� c'est un identificateur, dans ce cas on n'a pas de signature *)
- Types.Tmty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s
+ Types.Mty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s
| _ -> env
in
{ env2 with env_modules = (rel_name ident, qualify ident) :: env2.env_modules }
- | Types.Tsig_modtype (ident, modtype_decl) ->
+ | Types.Sig_modtype (ident, modtype_decl) ->
let env2 =
match modtype_decl with
- Types.Tmodtype_abstract ->
+ Types.Modtype_abstract ->
env
- | Types.Tmodtype_manifest modtype ->
+ | Types.Modtype_manifest modtype ->
match modtype with
(* A VOIR : le cas o� c'est un identificateur, dans ce cas on n'a pas de signature *)
- Types.Tmty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s
+ Types.Mty_signature s -> add_signature env (qualify ident) ~rel: (rel_name ident) s
| _ -> env
in
{ env2 with env_module_types = (rel_name ident, qualify ident) :: env2.env_module_types }
- | Types.Tsig_class (ident, _, _) -> { env with env_classes = (rel_name ident, qualify ident) :: env.env_classes }
- | Types.Tsig_cltype (ident, _, _) -> { env with env_class_types = (rel_name ident, qualify ident) :: env.env_class_types }
+ | Types.Sig_class (ident, _, _) -> { env with env_classes = (rel_name ident, qualify ident) :: env.env_classes }
+ | Types.Sig_class_type (ident, _, _) -> { env with env_class_types = (rel_name ident, qualify ident) :: env.env_class_types }
in
List.fold_left f env signat
@@ -218,31 +218,31 @@ let subst_type env t =
let subst_module_type env t =
let rec iter t =
match t with
- Types.Tmty_ident p ->
+ Types.Mty_ident p ->
let new_p = Odoc_name.to_path (full_module_type_name env (Odoc_name.from_path p)) in
- Types.Tmty_ident new_p
- | Types.Tmty_signature _ ->
+ Types.Mty_ident new_p
+ | Types.Mty_signature _ ->
t
- | Types.Tmty_functor (id, mt1, mt2) ->
- Types.Tmty_functor (id, iter mt1, iter mt2)
+ | Types.Mty_functor (id, mt1, mt2) ->
+ Types.Mty_functor (id, iter mt1, iter mt2)
in
iter t
let subst_class_type env t =
let rec iter t =
match t with
- Types.Tcty_constr (p,texp_list,ct) ->
+ Types.Cty_constr (p,texp_list,ct) ->
let new_p = Odoc_name.to_path (full_type_name env (Odoc_name.from_path p)) in
let new_texp_list = List.map (subst_type env) texp_list in
let new_ct = iter ct in
- Types.Tcty_constr (new_p, new_texp_list, new_ct)
- | Types.Tcty_signature cs ->
+ Types.Cty_constr (new_p, new_texp_list, new_ct)
+ | Types.Cty_signature cs ->
(* on ne s'occupe pas des vals et methods *)
t
- | Types.Tcty_fun (l, texp, ct) ->
+ | Types.Cty_fun (l, texp, ct) ->
let new_texp = subst_type env texp in
let new_ct = iter ct in
- Types.Tcty_fun (l, new_texp, new_ct)
+ Types.Cty_fun (l, new_texp, new_ct)
in
iter t
diff --git a/ocamldoc/odoc_module.ml b/ocamldoc/odoc_module.ml
index cc1fe02ca..0cbc2cc6a 100644
--- a/ocamldoc/odoc_module.ml
+++ b/ocamldoc/odoc_module.ml
@@ -238,7 +238,7 @@ let rec module_elements ?(trans=true) m =
module_elements ~trans: trans
{ m_name = "" ;
m_info = None ;
- m_type = Types.Tmty_signature [] ;
+ m_type = Types.Mty_signature [] ;
m_is_interface = false ; m_file = "" ; m_kind = k ;
m_loc = Odoc_types.dummy_loc ;
m_top_deps = [] ;
diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml
index 5cc8e038c..2c4832741 100644
--- a/ocamldoc/odoc_print.ml
+++ b/ocamldoc/odoc_print.ml
@@ -55,15 +55,15 @@ exception Use_code of string
let simpl_module_type ?code t =
let rec iter t =
match t with
- Types.Tmty_ident p -> t
- | Types.Tmty_signature _ ->
+ Types.Mty_ident p -> t
+ | Types.Mty_signature _ ->
(
match code with
- None -> Types.Tmty_signature []
+ None -> Types.Mty_signature []
| Some s -> raise (Use_code s)
)
- | Types.Tmty_functor (id, mt1, mt2) ->
- Types.Tmty_functor (id, iter mt1, iter mt2)
+ | Types.Mty_functor (id, mt1, mt2) ->
+ Types.Mty_functor (id, iter mt1, iter mt2)
in
iter t
@@ -80,20 +80,20 @@ let string_of_module_type ?code ?(complete=false) t =
let simpl_class_type t =
let rec iter t =
match t with
- Types.Tcty_constr (p,texp_list,ct) -> t
- | Types.Tcty_signature cs ->
+ Types.Cty_constr (p,texp_list,ct) -> t
+ | Types.Cty_signature cs ->
(* on vire les vals et methods pour ne pas qu'elles soient imprim�es
quand on affichera le type *)
let tnil = { Types.desc = Types.Tnil ; Types.level = 0; Types.id = 0 } in
- Types.Tcty_signature { Types.cty_self = { cs.Types.cty_self with
+ Types.Cty_signature { Types.cty_self = { cs.Types.cty_self with
Types.desc = Types.Tobject (tnil, ref None) };
Types.cty_vars = Types.Vars.empty ;
Types.cty_concr = Types.Concr.empty ;
Types.cty_inher = []
}
- | Types.Tcty_fun (l, texp, ct) ->
+ | Types.Cty_fun (l, texp, ct) ->
let new_ct = iter ct in
- Types.Tcty_fun (l, texp, new_ct)
+ Types.Cty_fun (l, texp, new_ct)
in
iter t
diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml
index a6989c25c..74de957ed 100644
--- a/ocamldoc/odoc_sig.ml
+++ b/ocamldoc/odoc_sig.ml
@@ -47,19 +47,19 @@ module Signature_search =
let add_to_hash table signat =
match signat with
- Types.Tsig_value (ident, _) ->
+ Types.Sig_value (ident, _) ->
Hashtbl.add table (V (Name.from_ident ident)) signat
- | Types.Tsig_exception (ident, _) ->
+ | Types.Sig_exception (ident, _) ->
Hashtbl.add table (E (Name.from_ident ident)) signat
- | Types.Tsig_type (ident, _, _) ->
+ | Types.Sig_type (ident, _, _) ->
Hashtbl.add table (T (Name.from_ident ident)) signat
- | Types.Tsig_class (ident, _, _) ->
+ | Types.Sig_class (ident, _, _) ->
Hashtbl.add table (C (Name.from_ident ident)) signat
- | Types.Tsig_cltype (ident, _, _) ->
+ | Types.Sig_class_type (ident, _, _) ->
Hashtbl.add table (CT (Name.from_ident ident)) signat
- | Types.Tsig_module (ident, _, _) ->
+ | Types.Sig_module (ident, _, _) ->
Hashtbl.add table (M (Name.from_ident ident)) signat
- | Types.Tsig_modtype (ident,_) ->
+ | Types.Sig_modtype (ident,_) ->
Hashtbl.add table (MT (Name.from_ident ident)) signat
let table signat =
@@ -69,40 +69,40 @@ module Signature_search =
let search_value table name =
match Hashtbl.find table (V name) with
- | (Types.Tsig_value (_, val_desc)) -> val_desc.Types.val_type
+ | (Types.Sig_value (_, val_desc)) -> val_desc.Types.val_type
| _ -> assert false
let search_exception table name =
match Hashtbl.find table (E name) with
- | (Types.Tsig_exception (_, type_expr_list)) ->
+ | (Types.Sig_exception (_, type_expr_list)) ->
type_expr_list
| _ -> assert false
let search_type table name =
match Hashtbl.find table (T name) with
- | (Types.Tsig_type (_, type_decl, _)) -> type_decl
+ | (Types.Sig_type (_, type_decl, _)) -> type_decl
| _ -> assert false
let search_class table name =
match Hashtbl.find table (C name) with
- | (Types.Tsig_class (_, class_decl, _)) -> class_decl
+ | (Types.Sig_class (_, class_decl, _)) -> class_decl
| _ -> assert false
let search_class_type table name =
match Hashtbl.find table (CT name) with
- | (Types.Tsig_cltype (_, cltype_decl, _)) -> cltype_decl
+ | (Types.Sig_class_type (_, cltype_decl, _)) -> cltype_decl
| _ -> assert false
let search_module table name =
match Hashtbl.find table (M name) with
- | (Types.Tsig_module (ident, module_type, _)) -> module_type
+ | (Types.Sig_module (ident, module_type, _)) -> module_type
| _ -> assert false
let search_module_type table name =
match Hashtbl.find table (MT name) with
- | (Types.Tsig_modtype (_, Types.Tmodtype_manifest module_type)) ->
+ | (Types.Sig_modtype (_, Types.Modtype_manifest module_type)) ->
Some module_type
- | (Types.Tsig_modtype (_, Types.Tmodtype_abstract)) ->
+ | (Types.Sig_modtype (_, Types.Modtype_abstract)) ->
None
| _ -> assert false
@@ -185,14 +185,14 @@ module Analyser =
pos_limit
in
let (len, comment_opt) = My_ir.just_after_special !file_name s in
- (len, acc @ [ (name, comment_opt) ])
+ (len, acc @ [ (name.txt, comment_opt) ])
| (name, _, _, loc) :: (name2, core_type_list2, ret_type2, loc2)
:: q ->
let pos_end_first = loc.Location.loc_end.Lexing.pos_cnum in
let pos_start_second = loc2.Location.loc_start.Lexing.pos_cnum in
let s = get_string_of_file pos_end_first pos_start_second in
let (_,comment_opt) = My_ir.just_after_special !file_name s in
- f (acc @ [name, comment_opt])
+ f (acc @ [name.txt, comment_opt])
((name2, core_type_list2, ret_type2, loc2) :: q)
in
f [] cons_core_type_list_list
@@ -205,13 +205,13 @@ module Analyser =
let pos = ct.Parsetree.ptyp_loc.Location.loc_end.Lexing.pos_cnum in
let s = get_string_of_file pos pos_end in
let (_,comment_opt) = My_ir.just_after_special !file_name s in
- [name, comment_opt]
+ [name.txt, comment_opt]
| (name,_,ct,xxloc) :: ((name2,_,ct2,xxloc2) as ele2) :: q ->
let pos = ct.Parsetree.ptyp_loc.Location.loc_end.Lexing.pos_cnum in
let pos2 = ct2.Parsetree.ptyp_loc.Location.loc_start.Lexing.pos_cnum in
let s = get_string_of_file pos pos2 in
let (_,comment_opt) = My_ir.just_after_special !file_name s in
- (name, comment_opt) :: (f (ele2 :: q))
+ (name.txt, comment_opt) :: (f (ele2 :: q))
in
(0, f name_mutable_type_list)
@@ -221,6 +221,7 @@ module Analyser =
Odoc_type.Type_abstract
| Types.Type_variant l ->
let f (constructor_name, type_expr_list, ret_type) =
+ let constructor_name = Ident.name constructor_name in
let comment_opt =
try
match List.assoc constructor_name name_comment_list with
@@ -239,6 +240,7 @@ module Analyser =
| Types.Type_record (l, _) ->
let f (field_name, mutable_flag, type_expr) =
+ let field_name = Ident.name field_name in
let comment_opt =
try
match List.assoc field_name name_comment_list with
@@ -262,12 +264,13 @@ module Analyser =
let get_pos_limit2 q =
match q with
[] -> pos_limit
- | ele2 :: _ ->
- match ele2 with
- Parsetree.Pctf_val (_, _, _, _, loc)
- | Parsetree.Pctf_virt (_, _, _, loc)
- | Parsetree.Pctf_meth (_, _, _, loc)
- | Parsetree.Pctf_cstr (_, _, loc) -> loc.Location.loc_start.Lexing.pos_cnum
+ | ele2 :: _ ->
+ let loc = ele2.Parsetree.pctf_loc in
+ match ele2.Parsetree.pctf_desc with
+ Parsetree.Pctf_val (_, _, _, _)
+ | Parsetree.Pctf_virt (_, _, _)
+ | Parsetree.Pctf_meth (_, _, _)
+ | Parsetree.Pctf_cstr (_, _) -> loc.Location.loc_start.Lexing.pos_cnum
| Parsetree.Pctf_inher class_type ->
class_type.Parsetree.pcty_loc.Location.loc_start.Lexing.pos_cnum
in
@@ -325,7 +328,11 @@ module Analyser =
in
([], ele_comments)
- | Parsetree.Pctf_val (name, mutable_flag, virtual_flag, _, loc) :: q ->
+ | item :: q ->
+ let loc = item.Parsetree.pctf_loc in
+ match item.Parsetree.pctf_desc with
+
+ | Parsetree.Pctf_val (name, mutable_flag, virtual_flag, _) ->
(* of (string * mutable_flag * core_type option * Location.t)*)
let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
let complete_name = Name.concat current_class_name name in
@@ -362,7 +369,7 @@ module Analyser =
let (inher_l, eles) = f (pos_end + maybe_more) q in
(inher_l, eles_comments @ ((Class_attribute att) :: eles))
- | Parsetree.Pctf_virt (name, private_flag, _, loc) :: q ->
+ | Parsetree.Pctf_virt (name, private_flag, _) ->
(* of (string * private_flag * core_type * Location.t) *)
let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
let (met, maybe_more) = get_method name comment_opt private_flag loc q in
@@ -370,21 +377,21 @@ module Analyser =
let (inher_l, eles) = f (loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q in
(inher_l, eles_comments @ ((Class_method met2) :: eles))
- | Parsetree.Pctf_meth (name, private_flag, _, loc) :: q ->
+ | Parsetree.Pctf_meth (name, private_flag, _) ->
(* of (string * private_flag * core_type * Location.t) *)
let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
let (met, maybe_more) = get_method name comment_opt private_flag loc q in
let (inher_l, eles) = f (loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q in
(inher_l, eles_comments @ ((Class_method met) :: eles))
- | (Parsetree.Pctf_cstr (_, _, loc)) :: q ->
+ | (Parsetree.Pctf_cstr (_, _)) ->
(* of (core_type * core_type * Location.t) *)
(* A VOIR : cela correspond aux contraintes, non ? on ne les garde pas pour l'instant *)
let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in
let (inher_l, eles) = f loc.Location.loc_end.Lexing.pos_cnum q in
(inher_l, eles_comments @ eles)
- | Parsetree.Pctf_inher class_type :: q ->
+ | Parsetree.Pctf_inher class_type ->
let loc = class_type.Parsetree.pcty_loc in
let (comment_opt, eles_comments) =
get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum
@@ -402,7 +409,7 @@ module Analyser =
match class_type.Parsetree.pcty_desc with
Parsetree.Pcty_constr (longident, _) ->
(*of Longident.t * core_type list*)
- let name = Name.from_longident longident in
+ let name = Name.from_longident longident.txt in
let ic =
{
ic_name = Odoc_env.full_class_or_class_type_name env name ;
@@ -414,7 +421,7 @@ module Analyser =
| Parsetree.Pcty_signature _
| Parsetree.Pcty_fun _ ->
- (* we don't have a name for the class signature, so we call it "object ... end" *)
+ (* we don't have a name for the class signature, so we call it "object ... end" *)
{
ic_name = Odoc_messages.object_end ;
ic_class = None ;
@@ -485,11 +492,11 @@ module Analyser =
match sig_item_desc with
Parsetree.Psig_value (name_pre, value_desc) ->
let type_expr =
- try Signature_search.search_value table name_pre
+ try Signature_search.search_value table name_pre.txt
with Not_found ->
- raise (Failure (Odoc_messages.value_not_found current_module_name name_pre))
+ raise (Failure (Odoc_messages.value_not_found current_module_name name_pre.txt))
in
- let name = Name.parens_if_infix name_pre in
+ let name = Name.parens_if_infix name_pre.txt in
let subst_typ = Odoc_env.subst_type env type_expr in
let v =
{
@@ -516,13 +523,13 @@ module Analyser =
| Parsetree.Psig_exception (name, exception_decl) ->
let types_excep_decl =
- try Signature_search.search_exception table name
+ try Signature_search.search_exception table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.exception_not_found current_module_name name))
+ raise (Failure (Odoc_messages.exception_not_found current_module_name name.txt))
in
let e =
{
- ex_name = Name.concat current_module_name name ;
+ ex_name = Name.concat current_module_name name.txt ;
ex_info = comment_opt ;
ex_args = List.map (Odoc_env.subst_type env) types_excep_decl.exn_args ;
ex_alias = None ;
@@ -550,7 +557,7 @@ module Analyser =
let new_env =
List.fold_left
(fun acc_env -> fun (name, _) ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
Odoc_env.add_type acc_env complete_name
)
env
@@ -572,7 +579,7 @@ module Analyser =
let pos_limit2 =
match q with
[] -> pos_limit
- | (_, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum
+ | ( _, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum
in
let (maybe_more, name_comment_list) =
name_comment_from_type_kind
@@ -580,14 +587,14 @@ module Analyser =
pos_limit2
type_decl.Parsetree.ptype_kind
in
- print_DEBUG ("Type "^name^" : "^(match assoc_com with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c));
+ print_DEBUG ("Type "^name.txt^" : "^(match assoc_com with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c));
let f_DEBUG (name, c_opt) = print_DEBUG ("constructor/field "^name^": "^(match c_opt with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)) in
List.iter f_DEBUG name_comment_list;
(* get the information for the type in the signature *)
let sig_type_decl =
- try Signature_search.search_type table name
+ try Signature_search.search_type table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.type_not_found current_module_name name))
+ raise (Failure (Odoc_messages.type_not_found current_module_name name.txt))
in
(* get the type kind with the associated comments *)
let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in
@@ -596,7 +603,7 @@ module Analyser =
(* associate the comments to each constructor and build the [Type.t_type] *)
let new_type =
{
- ty_name = Name.concat current_module_name name ;
+ ty_name = Name.concat current_module_name name.txt ;
ty_info = assoc_com ;
ty_parameters =
List.map2 (fun p (co,cn,_) ->
@@ -651,12 +658,12 @@ module Analyser =
(0, env, ele_comments)
| Parsetree.Psig_module (name, module_type) ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
(* get the the module type in the signature by the module name *)
let sig_module_type =
- try Signature_search.search_module table name
+ try Signature_search.search_module table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.module_not_found current_module_name name))
+ raise (Failure (Odoc_messages.module_not_found current_module_name name.txt))
in
let module_kind = analyse_module_kind env complete_name module_type sig_module_type in
let code_intf =
@@ -692,7 +699,7 @@ module Analyser =
let new_env = Odoc_env.add_module env new_module.m_name in
let new_env2 =
match new_module.m_type with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *)
- Types.Tmty_signature s -> Odoc_env.add_signature new_env new_module.m_name ~rel: (Name.simple new_module.m_name) s
+ Types.Mty_signature s -> Odoc_env.add_signature new_env new_module.m_name ~rel: (Name.simple new_module.m_name) s
| _ -> new_env
in
(maybe_more, new_env2, [ Element_module new_module ])
@@ -701,7 +708,7 @@ module Analyser =
(* we start by extending the environment *)
let new_env =
List.fold_left
- (fun acc_env -> fun (name, _) ->
+ (fun acc_env -> fun ({ txt = name }, _) ->
let complete_name = Name.concat current_module_name name in
let e = Odoc_env.add_module acc_env complete_name in
(* get the information for the module in the signature *)
@@ -712,7 +719,7 @@ module Analyser =
in
match sig_module_type with
(* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *)
- Types.Tmty_signature s ->
+ Types.Mty_signature s ->
Odoc_env.add_signature e complete_name ~rel: name s
| _ ->
print_DEBUG "not a Tmty_signature";
@@ -726,7 +733,7 @@ module Analyser =
[] ->
(acc_maybe_more, [])
| (name, modtype) :: q ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let loc_start = modtype.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let loc_end = modtype.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let (assoc_com, ele_comments) =
@@ -744,9 +751,9 @@ module Analyser =
in
(* get the information for the module in the signature *)
let sig_module_type =
- try Signature_search.search_module table name
+ try Signature_search.search_module table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.module_not_found current_module_name name))
+ raise (Failure (Odoc_messages.module_not_found current_module_name name.txt))
in
(* associate the comments to each constructor and build the [Type.t_type] *)
let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in
@@ -792,11 +799,11 @@ module Analyser =
(maybe_more, new_env, mods)
| Parsetree.Psig_modtype (name, pmodtype_decl) ->
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let sig_mtype =
- try Signature_search.search_module_type table name
+ try Signature_search.search_module_type table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.module_type_not_found current_module_name name))
+ raise (Failure (Odoc_messages.module_type_not_found current_module_name name.txt))
in
let module_type_kind =
match pmodtype_decl with
@@ -827,7 +834,7 @@ module Analyser =
let new_env = Odoc_env.add_module_type env mt.mt_name in
let new_env2 =
match sig_mtype with (* A VOIR : cela peut-il �tre Tmty_ident ? dans ce cas, on aurait pas la signature *)
- Some (Types.Tmty_signature s) -> Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s
+ Some (Types.Mty_signature s) -> Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s
| _ -> new_env
in
(maybe_more, new_env2, [ Element_module_type mt ])
@@ -835,7 +842,7 @@ module Analyser =
| Parsetree.Psig_include module_type ->
let rec f = function
Parsetree.Pmty_ident longident ->
- Name.from_longident longident
+ Name.from_longident longident.txt
| Parsetree.Pmty_signature _ ->
"??"
| Parsetree.Pmty_functor _ ->
@@ -844,7 +851,7 @@ module Analyser =
f mt.Parsetree.pmty_desc
| Parsetree.Pmty_typeof mexpr ->
match mexpr.Parsetree.pmod_desc with
- Parsetree.Pmod_ident longident -> Name.from_longident longident
+ Parsetree.Pmod_ident longident -> Name.from_longident longident.txt
| _ -> "??"
in
let name = f module_type.Parsetree.pmty_desc in
@@ -863,7 +870,7 @@ module Analyser =
let new_env =
List.fold_left
(fun acc_env -> fun class_desc ->
- let complete_name = Name.concat current_module_name class_desc.Parsetree.pci_name in
+ let complete_name = Name.concat current_module_name class_desc.Parsetree.pci_name.txt in
Odoc_env.add_class acc_env complete_name
)
env
@@ -889,11 +896,11 @@ module Analyser =
| cd :: _ -> cd.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum
in
let name = class_desc.Parsetree.pci_name in
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let sig_class_decl =
- try Signature_search.search_class table name
+ try Signature_search.search_class table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.class_not_found current_module_name name))
+ raise (Failure (Odoc_messages.class_not_found current_module_name name.txt))
in
let sig_class_type = sig_class_decl.Types.cty_type in
let (parameters, class_kind) =
@@ -939,7 +946,7 @@ module Analyser =
let new_env =
List.fold_left
(fun acc_env -> fun class_type_decl ->
- let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in
+ let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name.txt in
Odoc_env.add_class_type acc_env complete_name
)
env
@@ -965,11 +972,11 @@ module Analyser =
| ct_decl2 :: _ -> ct_decl2.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum
in
let name = ct_decl.Parsetree.pci_name in
- let complete_name = Name.concat current_module_name name in
+ let complete_name = Name.concat current_module_name name.txt in
let sig_cltype_decl =
- try Signature_search.search_class_type table name
+ try Signature_search.search_class_type table name.txt
with Not_found ->
- raise (Failure (Odoc_messages.class_type_not_found current_module_name name))
+ raise (Failure (Odoc_messages.class_type_not_found current_module_name name.txt))
in
let sig_class_type = sig_cltype_decl.Types.clty_type in
let kind = analyse_class_type_kind
@@ -1013,8 +1020,8 @@ module Analyser =
Parsetree.Pmty_ident longident ->
let name =
match sig_module_type with
- Types.Tmty_ident path -> Name.from_path path
- | _ -> Name.from_longident longident
+ Types.Mty_ident path -> Name.from_path path
+ | _ -> Name.from_longident longident.txt
(* A VOIR cela arrive quand on fait module type F : functor ... -> Toto, Toto n'est pas un ident mais une structure *)
in
Module_type_alias { mta_name = Odoc_env.full_module_type_name env name ;
@@ -1024,23 +1031,23 @@ module Analyser =
(
(* we must have a signature in the module type *)
match sig_module_type with
- Types.Tmty_signature signat ->
+ Types.Mty_signature signat ->
let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in
Module_type_struct elements
| _ ->
- raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
+ raise (Failure "Parsetree.Pmty_signature signature but not Types.Mty_signature signat")
)
- | Parsetree.Pmty_functor (_,pmodule_type2, module_type2) ->
+ | Parsetree.Pmty_functor (_, pmodule_type2, module_type2) ->
(
let loc_start = pmodule_type2.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let loc_end = pmodule_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let mp_type_code = get_string_of_file loc_start loc_end in
print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code);
match sig_module_type with
- Types.Tmty_functor (ident, param_module_type, body_module_type) ->
+ Types.Mty_functor (ident, param_module_type, body_module_type) ->
let mp_kind = analyse_module_type_kind env
current_module_name pmodule_type2 param_module_type
in
@@ -1061,7 +1068,7 @@ module Analyser =
| _ ->
(* if we're here something's wrong *)
- raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _")
+ raise (Failure "Parsetree.Pmty_functor _ but not Types.Mty_functor _")
)
| Parsetree.Pmty_with (module_type2, _) ->
@@ -1090,7 +1097,7 @@ module Analyser =
| Parsetree.Pmty_signature signature ->
(
match sig_module_type with
- Types.Tmty_signature signat ->
+ Types.Mty_signature signat ->
Module_struct
(analyse_parsetree
env
@@ -1102,12 +1109,12 @@ module Analyser =
)
| _ ->
(* if we're here something's wrong *)
- raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat")
+ raise (Failure "Parsetree.Pmty_signature signature but not Types.Mty_signature signat")
)
- | Parsetree.Pmty_functor (_,pmodule_type2,module_type2) (* of string * module_type * module_type *) ->
+ | Parsetree.Pmty_functor (_, pmodule_type2,module_type2) (* of string * module_type * module_type *) ->
(
match sig_module_type with
- Types.Tmty_functor (ident, param_module_type, body_module_type) ->
+ Types.Mty_functor (ident, param_module_type, body_module_type) ->
let loc_start = pmodule_type2.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in
let loc_end = pmodule_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in
let mp_type_code = get_string_of_file loc_start loc_end in
@@ -1132,7 +1139,7 @@ module Analyser =
| _ ->
(* if we're here something's wrong *)
- raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _")
+ raise (Failure "Parsetree.Pmty_functor _ but not Types.Mty_functor _")
)
| Parsetree.Pmty_with (module_type2, _) ->
(*of module_type * (Longident.t * with_constraint) list*)
@@ -1154,8 +1161,8 @@ module Analyser =
and analyse_class_kind env current_class_name last_pos parse_class_type sig_class_type =
match parse_class_type.Parsetree.pcty_desc, sig_class_type with
(Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *),
- Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) ->
- print_DEBUG "Tcty_constr _";
+ Types.Cty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) ->
+ print_DEBUG "Cty_constr _";
let path_name = Name.from_path p in
let name = Odoc_env.full_class_or_class_type_name env path_name in
let k =
@@ -1168,7 +1175,7 @@ module Analyser =
in
([], k)
- | (Parsetree.Pcty_signature (_, class_type_field_list), Types.Tcty_signature class_signature) ->
+ | (Parsetree.Pcty_signature { Parsetree.pcsig_fields = class_type_field_list }, Types.Cty_signature class_signature) ->
(* we get the elements of the class in class_type_field_list *)
let (inher_l, ele) = analyse_class_elements env current_class_name
last_pos
@@ -1178,7 +1185,7 @@ module Analyser =
in
([], Class_structure (inher_l, ele))
- | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Tcty_fun (label, type_expr, class_type)) ->
+ | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Cty_fun (label, type_expr, class_type)) ->
(* label = string. Dans les signatures, pas de nom de param�tres � l'int�rieur des tuples *)
(* si label = "", pas de label. ici on a l'information pour savoir si on a un label explicite. *)
if parse_label = label then
@@ -1205,8 +1212,8 @@ module Analyser =
and analyse_class_type_kind env current_class_name last_pos parse_class_type sig_class_type =
match parse_class_type.Parsetree.pcty_desc, sig_class_type with
(Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *),
- Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) ->
- print_DEBUG "Tcty_constr _";
+ Types.Cty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) ->
+ print_DEBUG "Cty_constr _";
let k =
Class_type
{
@@ -1217,7 +1224,9 @@ module Analyser =
in
k
- | (Parsetree.Pcty_signature (_, class_type_field_list), Types.Tcty_signature class_signature) ->
+ | (Parsetree.Pcty_signature {
+ Parsetree.pcsig_fields = class_type_field_list;
+ }, Types.Cty_signature class_signature) ->
(* we get the elements of the class in class_type_field_list *)
let (inher_l, ele) = analyse_class_elements env current_class_name
last_pos
@@ -1227,11 +1236,11 @@ module Analyser =
in
Class_signature (inher_l, ele)
- | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Tcty_fun (label, type_expr, class_type)) ->
- raise (Failure "analyse_class_type_kind : Parsetree.Pcty_fun (...) with Types.Tcty_fun (...)")
+ | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Cty_fun (label, type_expr, class_type)) ->
+ raise (Failure "analyse_class_type_kind : Parsetree.Pcty_fun (...) with Types.Cty_fun (...)")
(*
| (Parsetree.Pcty_constr (longident, _) (*of Longident.t * core_type list *),
- Types.Tcty_signature class_signature) ->
+ Types.Cty_signature class_signature) ->
(* A VOIR : c'est pour le cas des contraintes de classes :
class type cons = object
method m : int
@@ -1290,7 +1299,7 @@ module Analyser =
in
{
m_name = mod_name ;
- m_type = Types.Tmty_signature signat ;
+ m_type = Types.Mty_signature signat ;
m_info = info_opt ;
m_is_interface = true ;
m_file = !file_name ;
diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli
index 65ee128fc..5717dc1f9 100644
--- a/ocamldoc/odoc_sig.mli
+++ b/ocamldoc/odoc_sig.mli
@@ -46,7 +46,7 @@ module Signature_search :
(** This function returns the Types.cltype_declaration for the class type whose name is given,
in the given table.
@raise Not_found if error.*)
- val search_class_type : tab -> string -> Types.cltype_declaration
+ val search_class_type : tab -> string -> Types.class_type_declaration
(** This function returns the Types.module_type for the module whose name is given,
in the given table.
diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml
index d420c0597..0360e3f0e 100644
--- a/ocamldoc/odoc_str.ml
+++ b/ocamldoc/odoc_str.ml
@@ -126,7 +126,7 @@ let string_of_class_type_param_list l =
let string_of_class_params c =
let b = Buffer.create 256 in
let rec iter = function
- Types.Tcty_fun (label, t, ctype) ->
+ Types.Cty_fun (label, t, ctype) ->
let parent = is_arrow_type t in
Printf.bprintf b "%s%s%s%s -> "
(
@@ -144,8 +144,8 @@ let string_of_class_params c =
)
(if parent then ")" else "");
iter ctype
- | Types.Tcty_signature _
- | Types.Tcty_constr _ -> ()
+ | Types.Cty_signature _
+ | Types.Cty_constr _ -> ()
in
iter c.Odoc_class.cl_type;
Buffer.contents b
diff --git a/ocamldoc/odoc_text_parser.mly b/ocamldoc/odoc_text_parser.mly
index 478cfa074..55909141b 100644
--- a/ocamldoc/odoc_text_parser.mly
+++ b/ocamldoc/odoc_text_parser.mly
@@ -80,8 +80,9 @@ let print_DEBUG s = print_string s; print_newline ()
%token <string> Char
/* Start Symbols */
-%start main
+%start main located_element_list
%type <Odoc_types.text> main
+%type <(int * int * Odoc_types.text_element) list> located_element_list
%%
main:
@@ -98,6 +99,16 @@ text_element_list:
| text_element text_element_list { $1 :: $2 }
;
+located_element_list:
+ located_element { [ $1 ] }
+| located_element located_element_list { $1 :: $2 }
+;
+
+located_element:
+ text_element { Parsing.symbol_start (), Parsing.symbol_end (), $1}
+;
+
+
ele_ref_kind:
ELE_REF { None }
| VAL_REF { Some RK_value }
diff --git a/otherlibs/dynlink/Makefile b/otherlibs/dynlink/Makefile
index 83e96c56b..63df023bb 100644
--- a/otherlibs/dynlink/Makefile
+++ b/otherlibs/dynlink/Makefile
@@ -33,7 +33,7 @@ COMPILEROBJS=\
../../typing/ident.cmo ../../typing/path.cmo \
../../typing/primitive.cmo ../../typing/types.cmo \
../../typing/btype.cmo ../../typing/subst.cmo ../../typing/predef.cmo \
- ../../typing/datarepr.cmo ../../typing/env.cmo \
+ ../../typing/datarepr.cmo ../../typing/cmi_format.cmo ../../typing/env.cmo \
../../bytecomp/lambda.cmo ../../bytecomp/instruct.cmo \
../../bytecomp/cmo_format.cmi ../../bytecomp/opcodes.cmo \
../../bytecomp/runtimedef.cmo ../../bytecomp/bytesections.cmo \
diff --git a/otherlibs/dynlink/dynlink.ml b/otherlibs/dynlink/dynlink.ml
index 7415ae6c2..ee136fe2c 100644
--- a/otherlibs/dynlink/dynlink.ml
+++ b/otherlibs/dynlink/dynlink.ml
@@ -126,13 +126,13 @@ let digest_interface unit loadpath =
close_in ic;
raise(Error(Corrupted_interface filename))
end;
- ignore (input_value ic);
+ let cmi = Cmi_format.input_cmi ic in
+ close_in ic;
let crc =
- match input_value ic with
+ match cmi.Cmi_format.cmi_crcs with
(_, crc) :: _ -> crc
| _ -> raise(Error(Corrupted_interface filename))
in
- close_in ic;
crc
with End_of_file | Failure _ ->
close_in ic;
@@ -190,7 +190,7 @@ let load_compunit ic file_name file_digest compunit =
| _ -> assert false in
raise(Error(Linking_error (file_name, new_error)))
end;
- (* PR#5215: identify this code fragment by
+ (* PR#5215: identify this code fragment by
digest of file contents + unit name.
Unit name is needed for .cma files, which produce several code fragments.*)
let digest = Digest.string (file_digest ^ compunit.cu_name) in
diff --git a/otherlibs/dynlink/dynlinkaux.mlpack b/otherlibs/dynlink/dynlinkaux.mlpack
index 783e624af..67b9538e8 100644
--- a/otherlibs/dynlink/dynlinkaux.mlpack
+++ b/otherlibs/dynlink/dynlinkaux.mlpack
@@ -1,5 +1,5 @@
Misc Config Clflags Tbl Consistbl
-Terminfo Warnings Asttypes Linenum Location Longident
+Terminfo Warnings Asttypes Location Longident
Ident Path Primitive Types Btype Subst Predef
-Datarepr Env Lambda Instruct Cmo_format Opcodes
+Datarepr Cmi_format Env Lambda Instruct Cmo_format Opcodes
Runtimedef Bytesections Dll Meta Symtable
diff --git a/otherlibs/labltk/browser/.depend b/otherlibs/labltk/browser/.depend
index 4a0040b3b..9903879db 100644
--- a/otherlibs/labltk/browser/.depend
+++ b/otherlibs/labltk/browser/.depend
@@ -1,101 +1,265 @@
-editor.cmo : viewer.cmi typecheck.cmi shell.cmi setpath.cmi searchpos.cmi \
- searchid.cmi mytypes.cmi lexical.cmi jg_toplevel.cmo jg_tk.cmo \
- jg_text.cmi jg_message.cmi jg_menu.cmo jg_button.cmo jg_bind.cmi \
- fileselect.cmi editor.cmi
-editor.cmx : viewer.cmx typecheck.cmx shell.cmx setpath.cmx searchpos.cmx \
- searchid.cmx mytypes.cmi lexical.cmx jg_toplevel.cmx jg_tk.cmx \
- jg_text.cmx jg_message.cmx jg_menu.cmx jg_button.cmx jg_bind.cmx \
- fileselect.cmx editor.cmi
-fileselect.cmo : useunix.cmi setpath.cmi list2.cmo jg_toplevel.cmo \
- jg_memo.cmi jg_entry.cmo jg_box.cmo fileselect.cmi
-fileselect.cmx : useunix.cmx setpath.cmx list2.cmx jg_toplevel.cmx \
- jg_memo.cmx jg_entry.cmx jg_box.cmx fileselect.cmi
+editor.cmo : ../labltk/wm.cmi ../labltk/winfo.cmi ../support/widget.cmi \
+ viewer.cmi ../../../typing/types.cmi typecheck.cmi ../labltk/toplevel.cmi \
+ ../labltk/tk.cmo ../support/timer.cmi ../support/textvariable.cmi \
+ ../labltk/text.cmi shell.cmi setpath.cmi ../labltk/selection.cmi \
+ searchpos.cmi searchid.cmi ../support/protocol.cmi \
+ ../../../parsing/parsetree.cmi ../../../parsing/parser.cmi \
+ ../labltk/pack.cmi mytypes.cmi ../labltk/menu.cmi \
+ ../../../parsing/longident.cmi ../../../parsing/location.cmi \
+ ../labltk/listbox.cmi lexical.cmi ../../../parsing/lexer.cmi \
+ ../labltk/label.cmi jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_message.cmi \
+ jg_menu.cmo jg_button.cmo jg_bind.cmi ../../../typing/ident.cmi \
+ ../labltk/frame.cmi ../labltk/focus.cmi fileselect.cmi \
+ ../../../typing/env.cmi ../labltk/entry.cmi ../labltk/clipboard.cmi \
+ ../../../utils/clflags.cmi ../labltk/checkbutton.cmi ../labltk/button.cmi \
+ editor.cmi
+editor.cmx : ../labltk/wm.cmx ../labltk/winfo.cmx ../support/widget.cmx \
+ viewer.cmx ../../../typing/types.cmx typecheck.cmx ../labltk/toplevel.cmx \
+ ../labltk/tk.cmx ../support/timer.cmx ../support/textvariable.cmx \
+ ../labltk/text.cmx shell.cmx setpath.cmx ../labltk/selection.cmx \
+ searchpos.cmx searchid.cmx ../support/protocol.cmx \
+ ../../../parsing/parsetree.cmi ../../../parsing/parser.cmx \
+ ../labltk/pack.cmx mytypes.cmi ../labltk/menu.cmx \
+ ../../../parsing/longident.cmx ../../../parsing/location.cmx \
+ ../labltk/listbox.cmx lexical.cmx ../../../parsing/lexer.cmx \
+ ../labltk/label.cmx jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_message.cmx \
+ jg_menu.cmx jg_button.cmx jg_bind.cmx ../../../typing/ident.cmx \
+ ../labltk/frame.cmx ../labltk/focus.cmx fileselect.cmx \
+ ../../../typing/env.cmx ../labltk/entry.cmx ../labltk/clipboard.cmx \
+ ../../../utils/clflags.cmx ../labltk/checkbutton.cmx ../labltk/button.cmx \
+ editor.cmi
+fileselect.cmo : useunix.cmi ../labltk/tkwait.cmi ../labltk/tk.cmo \
+ ../support/textvariable.cmi setpath.cmi ../labltk/pack.cmi \
+ ../../../utils/misc.cmi ../labltk/listbox.cmi list2.cmo \
+ ../labltk/label.cmi jg_toplevel.cmo jg_memo.cmi jg_entry.cmo jg_box.cmo \
+ ../labltk/grab.cmi ../labltk/frame.cmi ../labltk/focus.cmi \
+ ../../../utils/config.cmi ../labltk/checkbutton.cmi ../labltk/button.cmi \
+ fileselect.cmi
+fileselect.cmx : useunix.cmx ../labltk/tkwait.cmx ../labltk/tk.cmx \
+ ../support/textvariable.cmx setpath.cmx ../labltk/pack.cmx \
+ ../../../utils/misc.cmx ../labltk/listbox.cmx list2.cmx \
+ ../labltk/label.cmx jg_toplevel.cmx jg_memo.cmx jg_entry.cmx jg_box.cmx \
+ ../labltk/grab.cmx ../labltk/frame.cmx ../labltk/focus.cmx \
+ ../../../utils/config.cmx ../labltk/checkbutton.cmx ../labltk/button.cmx \
+ fileselect.cmi
help.cmo :
help.cmx :
-jg_bind.cmo : jg_bind.cmi
-jg_bind.cmx : jg_bind.cmi
-jg_box.cmo : jg_completion.cmi jg_bind.cmi
-jg_box.cmx : jg_completion.cmx jg_bind.cmx
-jg_button.cmo :
-jg_button.cmx :
-jg_completion.cmo : jg_completion.cmi
-jg_completion.cmx : jg_completion.cmi
-jg_config.cmo : jg_tk.cmo jg_config.cmi
-jg_config.cmx : jg_tk.cmx jg_config.cmi
-jg_entry.cmo : jg_bind.cmi
-jg_entry.cmx : jg_bind.cmx
+jg_bind.cmo : ../labltk/tk.cmo ../labltk/focus.cmi ../labltk/button.cmi \
+ jg_bind.cmi
+jg_bind.cmx : ../labltk/tk.cmx ../labltk/focus.cmx ../labltk/button.cmx \
+ jg_bind.cmi
+jg_box.cmo : ../labltk/winfo.cmi ../labltk/tk.cmo ../labltk/scrollbar.cmi \
+ ../labltk/listbox.cmi jg_completion.cmi jg_bind.cmi ../labltk/frame.cmi
+jg_box.cmx : ../labltk/winfo.cmx ../labltk/tk.cmx ../labltk/scrollbar.cmx \
+ ../labltk/listbox.cmx jg_completion.cmx jg_bind.cmx ../labltk/frame.cmx
+jg_button.cmo : ../labltk/tk.cmo ../labltk/button.cmi
+jg_button.cmx : ../labltk/tk.cmx ../labltk/button.cmx
+jg_completion.cmo : ../support/timer.cmi jg_completion.cmi
+jg_completion.cmx : ../support/timer.cmx jg_completion.cmi
+jg_config.cmo : ../support/widget.cmi ../labltk/option.cmi jg_tk.cmo \
+ jg_config.cmi
+jg_config.cmx : ../support/widget.cmx ../labltk/option.cmx jg_tk.cmx \
+ jg_config.cmi
+jg_entry.cmo : ../labltk/tk.cmo jg_bind.cmi ../labltk/entry.cmi
+jg_entry.cmx : ../labltk/tk.cmx jg_bind.cmx ../labltk/entry.cmx
jg_memo.cmo : jg_memo.cmi
jg_memo.cmx : jg_memo.cmi
-jg_menu.cmo :
-jg_menu.cmx :
-jg_message.cmo : jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_bind.cmi \
- jg_message.cmi
-jg_message.cmx : jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_bind.cmx \
- jg_message.cmi
-jg_multibox.cmo : jg_completion.cmi jg_bind.cmi jg_multibox.cmi
-jg_multibox.cmx : jg_completion.cmx jg_bind.cmx jg_multibox.cmi
-jg_text.cmo : jg_toplevel.cmo jg_tk.cmo jg_button.cmo jg_bind.cmi \
- jg_text.cmi
-jg_text.cmx : jg_toplevel.cmx jg_tk.cmx jg_button.cmx jg_bind.cmx \
- jg_text.cmi
-jg_tk.cmo :
-jg_tk.cmx :
-jg_toplevel.cmo :
-jg_toplevel.cmx :
-lexical.cmo : jg_tk.cmo lexical.cmi
-lexical.cmx : jg_tk.cmx lexical.cmi
+jg_menu.cmo : ../labltk/toplevel.cmi ../labltk/tk.cmo ../labltk/menu.cmi
+jg_menu.cmx : ../labltk/toplevel.cmx ../labltk/tk.cmx ../labltk/menu.cmx
+jg_message.cmo : ../labltk/wm.cmi ../labltk/tkwait.cmi ../labltk/tk.cmo \
+ ../support/textvariable.cmi ../labltk/text.cmi ../labltk/message.cmi \
+ jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_bind.cmi ../labltk/grab.cmi \
+ ../labltk/frame.cmi ../labltk/button.cmi jg_message.cmi
+jg_message.cmx : ../labltk/wm.cmx ../labltk/tkwait.cmx ../labltk/tk.cmx \
+ ../support/textvariable.cmx ../labltk/text.cmx ../labltk/message.cmx \
+ jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_bind.cmx ../labltk/grab.cmx \
+ ../labltk/frame.cmx ../labltk/button.cmx jg_message.cmi
+jg_multibox.cmo : ../labltk/tk.cmo ../labltk/scrollbar.cmi \
+ ../labltk/listbox.cmi jg_completion.cmi jg_bind.cmi ../labltk/focus.cmi \
+ jg_multibox.cmi
+jg_multibox.cmx : ../labltk/tk.cmx ../labltk/scrollbar.cmx \
+ ../labltk/listbox.cmx jg_completion.cmx jg_bind.cmx ../labltk/focus.cmx \
+ jg_multibox.cmi
+jg_text.cmo : ../labltk/wm.cmi ../labltk/winfo.cmi ../labltk/tk.cmo \
+ ../support/textvariable.cmi ../labltk/text.cmi ../labltk/scrollbar.cmi \
+ ../labltk/radiobutton.cmi ../support/protocol.cmi ../labltk/label.cmi \
+ jg_toplevel.cmo jg_tk.cmo jg_button.cmo jg_bind.cmi ../labltk/frame.cmi \
+ ../labltk/focus.cmi ../labltk/entry.cmi ../labltk/button.cmi jg_text.cmi
+jg_text.cmx : ../labltk/wm.cmx ../labltk/winfo.cmx ../labltk/tk.cmx \
+ ../support/textvariable.cmx ../labltk/text.cmx ../labltk/scrollbar.cmx \
+ ../labltk/radiobutton.cmx ../support/protocol.cmx ../labltk/label.cmx \
+ jg_toplevel.cmx jg_tk.cmx jg_button.cmx jg_bind.cmx ../labltk/frame.cmx \
+ ../labltk/focus.cmx ../labltk/entry.cmx ../labltk/button.cmx jg_text.cmi
+jg_tk.cmo : ../labltk/tk.cmo
+jg_tk.cmx : ../labltk/tk.cmx
+jg_toplevel.cmo : ../labltk/wm.cmi ../support/widget.cmi \
+ ../labltk/toplevel.cmi ../labltk/tk.cmo
+jg_toplevel.cmx : ../labltk/wm.cmx ../support/widget.cmx \
+ ../labltk/toplevel.cmx ../labltk/tk.cmx
+lexical.cmo : ../labltk/tk.cmo ../labltk/text.cmi \
+ ../../../parsing/parser.cmi ../../../parsing/location.cmi \
+ ../../../parsing/lexer.cmi jg_tk.cmo lexical.cmi
+lexical.cmx : ../labltk/tk.cmx ../labltk/text.cmx \
+ ../../../parsing/parser.cmx ../../../parsing/location.cmx \
+ ../../../parsing/lexer.cmx jg_tk.cmx lexical.cmi
list2.cmo :
list2.cmx :
-main.cmo : viewer.cmi shell.cmi searchpos.cmi searchid.cmi jg_config.cmi \
- editor.cmi
-main.cmx : viewer.cmx shell.cmx searchpos.cmx searchid.cmx jg_config.cmx \
- editor.cmx
-searchid.cmo : list2.cmo searchid.cmi
-searchid.cmx : list2.cmx searchid.cmi
-searchpos.cmo : searchid.cmi lexical.cmi jg_tk.cmo jg_text.cmi \
- jg_message.cmi jg_memo.cmi jg_bind.cmi searchpos.cmi
-searchpos.cmx : searchid.cmx lexical.cmx jg_tk.cmx jg_text.cmx \
- jg_message.cmx jg_memo.cmx jg_bind.cmx searchpos.cmi
-setpath.cmo : useunix.cmi list2.cmo jg_toplevel.cmo jg_button.cmo jg_box.cmo \
- jg_bind.cmi setpath.cmi
-setpath.cmx : useunix.cmx list2.cmx jg_toplevel.cmx jg_button.cmx jg_box.cmx \
- jg_bind.cmx setpath.cmi
-shell.cmo : list2.cmo lexical.cmi jg_toplevel.cmo jg_tk.cmo jg_text.cmi \
- jg_message.cmi jg_menu.cmo jg_memo.cmi fileselect.cmi dummy.cmi shell.cmi
-shell.cmx : list2.cmx lexical.cmx jg_toplevel.cmx jg_tk.cmx jg_text.cmx \
- jg_message.cmx jg_menu.cmx jg_memo.cmx fileselect.cmx dummy.cmi shell.cmi
-typecheck.cmo : mytypes.cmi jg_tk.cmo jg_text.cmi jg_message.cmi \
- typecheck.cmi
-typecheck.cmx : mytypes.cmi jg_tk.cmx jg_text.cmx jg_message.cmx \
- typecheck.cmi
+main.cmo : ../../../utils/warnings.cmi viewer.cmi ../labltk/tk.cmo shell.cmi \
+ searchpos.cmi searchid.cmi ../support/protocol.cmi \
+ ../../../utils/misc.cmi ../labltk/message.cmi jg_config.cmi \
+ ../../../typing/env.cmi editor.cmi ../../../utils/config.cmi \
+ ../../../utils/clflags.cmi ../labltk/button.cmi
+main.cmx : ../../../utils/warnings.cmx viewer.cmx ../labltk/tk.cmx shell.cmx \
+ searchpos.cmx searchid.cmx ../support/protocol.cmx \
+ ../../../utils/misc.cmx ../labltk/message.cmx jg_config.cmx \
+ ../../../typing/env.cmx editor.cmx ../../../utils/config.cmx \
+ ../../../utils/clflags.cmx ../labltk/button.cmx
+searchid.cmo : ../../../typing/typetexp.cmi ../../../typing/types.cmi \
+ ../../../typing/typemod.cmi ../../../typing/typedtree.cmi \
+ ../../../parsing/syntaxerr.cmi ../../../typing/path.cmi \
+ ../../../parsing/parsetree.cmi ../../../parsing/parse.cmi \
+ ../../../parsing/longident.cmi ../../../parsing/location.cmi list2.cmo \
+ ../../../parsing/lexer.cmi ../../../typing/ident.cmi \
+ ../../../typing/env.cmi ../../../typing/ctype.cmi \
+ ../../../typing/btype.cmi ../../../parsing/asttypes.cmi searchid.cmi
+searchid.cmx : ../../../typing/typetexp.cmx ../../../typing/types.cmx \
+ ../../../typing/typemod.cmx ../../../typing/typedtree.cmx \
+ ../../../parsing/syntaxerr.cmx ../../../typing/path.cmx \
+ ../../../parsing/parsetree.cmi ../../../parsing/parse.cmx \
+ ../../../parsing/longident.cmx ../../../parsing/location.cmx list2.cmx \
+ ../../../parsing/lexer.cmx ../../../typing/ident.cmx \
+ ../../../typing/env.cmx ../../../typing/ctype.cmx \
+ ../../../typing/btype.cmx ../../../parsing/asttypes.cmi searchid.cmi
+searchpos.cmo : ../labltk/wm.cmi ../labltk/winfo.cmi ../support/widget.cmi \
+ ../../../typing/typetexp.cmi ../../../typing/types.cmi \
+ ../../../typing/typemod.cmi ../../../typing/typedtree.cmi \
+ ../../../typing/typedecl.cmi ../../../typing/typeclass.cmi \
+ ../labltk/tk.cmo ../labltk/text.cmi ../../../parsing/syntaxerr.cmi \
+ ../support/support.cmi ../../../typing/stypes.cmi searchid.cmi \
+ ../../../typing/printtyp.cmi ../../../typing/path.cmi \
+ ../../../parsing/parsetree.cmi ../../../parsing/parse.cmi \
+ ../labltk/pack.cmi ../labltk/option.cmi ../../../utils/misc.cmi \
+ ../labltk/menu.cmi ../../../parsing/longident.cmi \
+ ../../../parsing/location.cmi lexical.cmi ../../../parsing/lexer.cmi \
+ ../labltk/label.cmi jg_tk.cmo jg_text.cmi jg_message.cmi jg_memo.cmi \
+ jg_bind.cmi ../../../typing/ident.cmi ../../../typing/env.cmi \
+ ../../../typing/ctype.cmi ../../../utils/config.cmi ../labltk/button.cmi \
+ ../../../parsing/asttypes.cmi searchpos.cmi
+searchpos.cmx : ../labltk/wm.cmx ../labltk/winfo.cmx ../support/widget.cmx \
+ ../../../typing/typetexp.cmx ../../../typing/types.cmx \
+ ../../../typing/typemod.cmx ../../../typing/typedtree.cmx \
+ ../../../typing/typedecl.cmx ../../../typing/typeclass.cmx \
+ ../labltk/tk.cmx ../labltk/text.cmx ../../../parsing/syntaxerr.cmx \
+ ../support/support.cmx ../../../typing/stypes.cmx searchid.cmx \
+ ../../../typing/printtyp.cmx ../../../typing/path.cmx \
+ ../../../parsing/parsetree.cmi ../../../parsing/parse.cmx \
+ ../labltk/pack.cmx ../labltk/option.cmx ../../../utils/misc.cmx \
+ ../labltk/menu.cmx ../../../parsing/longident.cmx \
+ ../../../parsing/location.cmx lexical.cmx ../../../parsing/lexer.cmx \
+ ../labltk/label.cmx jg_tk.cmx jg_text.cmx jg_message.cmx jg_memo.cmx \
+ jg_bind.cmx ../../../typing/ident.cmx ../../../typing/env.cmx \
+ ../../../typing/ctype.cmx ../../../utils/config.cmx ../labltk/button.cmx \
+ ../../../parsing/asttypes.cmi searchpos.cmi
+setpath.cmo : useunix.cmi ../labltk/tk.cmo ../support/textvariable.cmi \
+ ../support/protocol.cmi ../labltk/listbox.cmi list2.cmo \
+ ../labltk/label.cmi jg_toplevel.cmo jg_button.cmo jg_box.cmo jg_bind.cmi \
+ ../labltk/frame.cmi ../labltk/entry.cmi ../../../utils/config.cmi \
+ ../labltk/button.cmi setpath.cmi
+setpath.cmx : useunix.cmx ../labltk/tk.cmx ../support/textvariable.cmx \
+ ../support/protocol.cmx ../labltk/listbox.cmx list2.cmx \
+ ../labltk/label.cmx jg_toplevel.cmx jg_button.cmx jg_box.cmx jg_bind.cmx \
+ ../labltk/frame.cmx ../labltk/entry.cmx ../../../utils/config.cmx \
+ ../labltk/button.cmx setpath.cmi
+shell.cmo : ../labltk/winfo.cmi ../../../utils/warnings.cmi \
+ ../labltk/toplevel.cmi ../labltk/tk.cmo ../support/timer.cmi \
+ ../labltk/text.cmi ../labltk/menu.cmi list2.cmo lexical.cmi \
+ jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_message.cmi jg_menu.cmo \
+ jg_memo.cmi fileselect.cmi ../support/fileevent.cmi dummy.cmi \
+ ../../../utils/config.cmi ../../../utils/clflags.cmi shell.cmi
+shell.cmx : ../labltk/winfo.cmx ../../../utils/warnings.cmx \
+ ../labltk/toplevel.cmx ../labltk/tk.cmx ../support/timer.cmx \
+ ../labltk/text.cmx ../labltk/menu.cmx list2.cmx lexical.cmx \
+ jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_message.cmx jg_menu.cmx \
+ jg_memo.cmx fileselect.cmx ../support/fileevent.cmx dummy.cmi \
+ ../../../utils/config.cmx ../../../utils/clflags.cmx shell.cmi
+typecheck.cmo : ../../../typing/typetexp.cmi ../../../typing/typemod.cmi \
+ ../../../typing/typedtree.cmi ../../../typing/typedecl.cmi \
+ ../../../typing/typecore.cmi ../../../typing/typeclass.cmi \
+ ../labltk/tk.cmo ../labltk/text.cmi ../../../parsing/syntaxerr.cmi \
+ ../../../typing/stypes.cmi ../../../parsing/parsetree.cmi \
+ ../../../parsing/parse.cmi mytypes.cmi ../../../utils/misc.cmi \
+ ../../../parsing/location.cmi ../../../parsing/lexer.cmi jg_tk.cmo \
+ jg_text.cmi jg_message.cmi ../../../typing/includemod.cmi \
+ ../../../typing/env.cmi ../../../typing/ctype.cmi \
+ ../../../utils/config.cmi ../../../typing/cmi_format.cmi \
+ ../../../utils/clflags.cmi ../../../utils/ccomp.cmi typecheck.cmi
+typecheck.cmx : ../../../typing/typetexp.cmx ../../../typing/typemod.cmx \
+ ../../../typing/typedtree.cmx ../../../typing/typedecl.cmx \
+ ../../../typing/typecore.cmx ../../../typing/typeclass.cmx \
+ ../labltk/tk.cmx ../labltk/text.cmx ../../../parsing/syntaxerr.cmx \
+ ../../../typing/stypes.cmx ../../../parsing/parsetree.cmi \
+ ../../../parsing/parse.cmx mytypes.cmi ../../../utils/misc.cmx \
+ ../../../parsing/location.cmx ../../../parsing/lexer.cmx jg_tk.cmx \
+ jg_text.cmx jg_message.cmx ../../../typing/includemod.cmx \
+ ../../../typing/env.cmx ../../../typing/ctype.cmx \
+ ../../../utils/config.cmx ../../../typing/cmi_format.cmx \
+ ../../../utils/clflags.cmx ../../../utils/ccomp.cmx typecheck.cmi
useunix.cmo : useunix.cmi
useunix.cmx : useunix.cmi
-viewer.cmo : useunix.cmi shell.cmi setpath.cmi searchpos.cmi searchid.cmi \
- mytypes.cmi jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_multibox.cmi \
- jg_message.cmi jg_menu.cmo jg_entry.cmo jg_completion.cmi jg_button.cmo \
- jg_box.cmo jg_bind.cmi help.cmo viewer.cmi
-viewer.cmx : useunix.cmx shell.cmx setpath.cmx searchpos.cmx searchid.cmx \
- mytypes.cmi jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_multibox.cmx \
- jg_message.cmx jg_menu.cmx jg_entry.cmx jg_completion.cmx jg_button.cmx \
- jg_box.cmx jg_bind.cmx help.cmx viewer.cmi
+viewer.cmo : ../labltk/wm.cmi useunix.cmi ../../../typing/types.cmi \
+ ../../../typing/typedtree.cmi ../labltk/toplevel.cmi ../labltk/tk.cmo \
+ ../support/textvariable.cmi ../labltk/text.cmi shell.cmi setpath.cmi \
+ searchpos.cmi searchid.cmi ../labltk/radiobutton.cmi \
+ ../support/protocol.cmi ../../../typing/predef.cmi \
+ ../../../typing/path.cmi ../labltk/pack.cmi mytypes.cmi \
+ ../labltk/menu.cmi ../../../parsing/longident.cmi \
+ ../../../parsing/location.cmi ../labltk/listbox.cmi ../labltk/label.cmi \
+ jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_multibox.cmi jg_message.cmi \
+ jg_menu.cmo jg_entry.cmo jg_completion.cmi jg_button.cmo jg_box.cmo \
+ jg_bind.cmi ../../../typing/ident.cmi help.cmo ../labltk/frame.cmi \
+ ../labltk/focus.cmi ../../../typing/env.cmi ../labltk/entry.cmi \
+ ../../../utils/config.cmi ../../../typing/cmi_format.cmi \
+ ../labltk/button.cmi viewer.cmi
+viewer.cmx : ../labltk/wm.cmx useunix.cmx ../../../typing/types.cmx \
+ ../../../typing/typedtree.cmx ../labltk/toplevel.cmx ../labltk/tk.cmx \
+ ../support/textvariable.cmx ../labltk/text.cmx shell.cmx setpath.cmx \
+ searchpos.cmx searchid.cmx ../labltk/radiobutton.cmx \
+ ../support/protocol.cmx ../../../typing/predef.cmx \
+ ../../../typing/path.cmx ../labltk/pack.cmx mytypes.cmi \
+ ../labltk/menu.cmx ../../../parsing/longident.cmx \
+ ../../../parsing/location.cmx ../labltk/listbox.cmx ../labltk/label.cmx \
+ jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_multibox.cmx jg_message.cmx \
+ jg_menu.cmx jg_entry.cmx jg_completion.cmx jg_button.cmx jg_box.cmx \
+ jg_bind.cmx ../../../typing/ident.cmx help.cmx ../labltk/frame.cmx \
+ ../labltk/focus.cmx ../../../typing/env.cmx ../labltk/entry.cmx \
+ ../../../utils/config.cmx ../../../typing/cmi_format.cmx \
+ ../labltk/button.cmx viewer.cmi
dummy.cmi :
dummyUnix.cmi :
dummyWin.cmi :
-editor.cmi :
+editor.cmi : ../support/widget.cmi
fileselect.cmi :
-jg_bind.cmi :
+jg_bind.cmi : ../support/widget.cmi
jg_completion.cmi :
jg_config.cmi :
jg_memo.cmi :
-jg_message.cmi :
-jg_multibox.cmi :
-jg_text.cmi :
-lexical.cmi :
-mytypes.cmi : shell.cmi
-searchid.cmi :
-searchpos.cmi :
-setpath.cmi :
-shell.cmi :
-typecheck.cmi : mytypes.cmi
+jg_message.cmi : ../support/widget.cmi
+jg_multibox.cmi : ../support/widget.cmi ../labltk/tk.cmo
+jg_text.cmi : ../support/widget.cmi ../labltk/tk.cmo
+lexical.cmi : ../support/widget.cmi ../labltk/tk.cmo
+mytypes.cmi : ../support/widget.cmi ../../../typing/types.cmi \
+ ../../../typing/typedtree.cmi ../support/textvariable.cmi \
+ ../../../typing/stypes.cmi shell.cmi ../../../parsing/parsetree.cmi
+searchid.cmi : ../../../typing/path.cmi ../../../parsing/parsetree.cmi \
+ ../../../parsing/longident.cmi ../../../typing/env.cmi
+searchpos.cmi : ../support/widget.cmi ../../../typing/types.cmi \
+ ../../../typing/typedtree.cmi ../../../typing/stypes.cmi \
+ ../../../typing/path.cmi ../../../parsing/parsetree.cmi \
+ ../../../parsing/longident.cmi ../../../parsing/location.cmi \
+ ../../../typing/env.cmi
+setpath.cmi : ../support/widget.cmi
+shell.cmi : ../support/widget.cmi
+typecheck.cmi : ../support/widget.cmi mytypes.cmi
useunix.cmi :
-viewer.cmi :
+viewer.cmi : ../support/widget.cmi ../../../parsing/longident.cmi \
+ ../../../typing/env.cmi
diff --git a/otherlibs/labltk/browser/Makefile.shared b/otherlibs/labltk/browser/Makefile.shared
index 6199e012f..53a4f0bb0 100644
--- a/otherlibs/labltk/browser/Makefile.shared
+++ b/otherlibs/labltk/browser/Makefile.shared
@@ -69,7 +69,7 @@ clean:
rm -f *.cm? ocamlbrowser$(EXE) dummy.mli *~ *.orig *.$(O) help.ml
depend: help.ml
- $(CAMLDEP) *.ml *.mli > .depend
+ $(CAMLDEP) $(LABLTKLIB) $(OCAMLTOPLIB) *.ml *.mli > .depend
shell.cmo: dummy.cmi
setpath.cmo fileselect.cmo lexical.cmi searchid.cmi typecheck.cmi: $(TOPDIR)/compilerlibs/ocamlcommon.cma
diff --git a/otherlibs/labltk/browser/editor.ml b/otherlibs/labltk/browser/editor.ml
index a9f7e6eac..90241c6b1 100644
--- a/otherlibs/labltk/browser/editor.ml
+++ b/otherlibs/labltk/browser/editor.ml
@@ -618,7 +618,7 @@ class editor ~top ~menus = object (self)
(try Filename.chop_extension basename with _ -> basename) in
let env =
Env.add_module (Ident.create modname)
- (Types.Tmty_signature txt.signature)
+ (Types.Mty_signature txt.signature)
Env.initial
in Viewer.view_defined (Longident.Lident modname) ~env ~show_all:true
end;
diff --git a/otherlibs/labltk/browser/mytypes.mli b/otherlibs/labltk/browser/mytypes.mli
index b4deead23..217fc111c 100644
--- a/otherlibs/labltk/browser/mytypes.mli
+++ b/otherlibs/labltk/browser/mytypes.mli
@@ -22,7 +22,7 @@ type edit_window =
frame: frame widget;
modified: Textvariable.textVariable;
mutable shell: (string * Shell.shell) option;
- mutable structure: Typedtree.structure;
+ mutable structure: Typedtree.structure_item list;
mutable type_info: Stypes.annotation list;
mutable signature: Types.signature;
mutable psignature: Parsetree.signature;
diff --git a/otherlibs/labltk/browser/searchid.ml b/otherlibs/labltk/browser/searchid.ml
index e624eca98..ab66f0f03 100644
--- a/otherlibs/labltk/browser/searchid.ml
+++ b/otherlibs/labltk/browser/searchid.ml
@@ -14,6 +14,7 @@
(* $Id$ *)
+open Asttypes
open StdLabels
open Location
open Longident
@@ -218,9 +219,9 @@ let rec search_type_in_signature t ~sign ~prefix ~mode =
and lid_of_id id = mklid (prefix @ [Ident.name id]) in
List2.flat_map sign ~f:
begin fun item -> match item with
- Tsig_value (id, vd) ->
+ Sig_value (id, vd) ->
if matches vd.val_type then [lid_of_id id, Pvalue] else []
- | Tsig_type (id, td, _) ->
+ | Sig_type (id, td, _) ->
if
matches (newconstr (Pident id) td.type_params) ||
begin match td.type_manifest with
@@ -239,23 +240,23 @@ let rec search_type_in_signature t ~sign ~prefix ~mode =
List.exists l ~f:(fun (_, _, t) -> matches t)
end
then [lid_of_id id, Ptype] else []
- | Tsig_exception (id, l) ->
+ | Sig_exception (id, l) ->
if List.exists l.exn_args ~f:matches
then [lid_of_id id, Pconstructor]
else []
- | Tsig_module (id, Tmty_signature sign, _) ->
+ | Sig_module (id, Mty_signature sign, _) ->
search_type_in_signature t ~sign ~mode
~prefix:(prefix @ [Ident.name id])
- | Tsig_module _ -> []
- | Tsig_modtype _ -> []
- | Tsig_class (id, cl, _) ->
+ | Sig_module _ -> []
+ | Sig_modtype _ -> []
+ | Sig_class (id, cl, _) ->
let self = self_type cl.cty_type in
if matches self
|| (match cl.cty_new with None -> false | Some ty -> matches ty)
(* || List.exists (get_fields ~prefix ~sign self)
~f:(fun (_,_,ty_field) -> matches ty_field) *)
then [lid_of_id id, Pclass] else []
- | Tsig_cltype (id, cl, _) ->
+ | Sig_class_type (id, cl, _) ->
let self = self_type cl.clty_type in
if matches self
(* || List.exists (get_fields ~prefix ~sign self)
@@ -273,7 +274,7 @@ let search_all_types t ~mode =
begin fun modname ->
let mlid = Lident modname in
try match lookup_module mlid initial with
- _, Tmty_signature sign ->
+ _, Mty_signature sign ->
List2.flat_map tl
~f:(search_type_in_signature ~sign ~prefix:[modname] ~mode)
| _ -> []
@@ -286,12 +287,12 @@ let search_string_type text ~mode =
try
let sexp = Parse.interface (Lexing.from_string ("val z : " ^ text)) in
let sign =
- try Typemod.transl_signature !start_env sexp with _ ->
+ try (Typemod.transl_signature !start_env sexp).sig_type with _ ->
let env = List.fold_left !module_list ~init:initial ~f:
begin fun acc m ->
try open_pers_signature m acc with Env.Error _ -> acc
end in
- try Typemod.transl_signature env sexp
+ try (Typemod.transl_signature env sexp).sig_type
with Env.Error err -> []
| Typemod.Error (l,_) ->
let start_c = l.loc_start.Lexing.pos_cnum in
@@ -302,7 +303,7 @@ let search_string_type text ~mode =
let end_c = l.loc_end.Lexing.pos_cnum in
raise (Error (start_c - 8, end_c - 8))
in match sign with
- [Tsig_value (_, vd)] ->
+ [ Sig_value (_, vd) ] ->
search_all_types vd.val_type ~mode
| _ -> []
with
@@ -355,20 +356,20 @@ let search_pattern_symbol text =
let l = List.map !module_list ~f:
begin fun modname -> Lident modname,
try match lookup_module (Lident modname) initial with
- _, Tmty_signature sign ->
+ _, Mty_signature sign ->
List2.flat_map sign ~f:
begin function
- Tsig_value (i, _) when check i -> [i, Pvalue]
- | Tsig_type (i, _, _) when check i -> [i, Ptype]
- | Tsig_exception (i, _) when check i -> [i, Pconstructor]
- | Tsig_module (i, _, _) when check i -> [i, Pmodule]
- | Tsig_modtype (i, _) when check i -> [i, Pmodtype]
- | Tsig_class (i, cl, _) when check i
+ Sig_value (i, _) when check i -> [i, Pvalue]
+ | Sig_type (i, _, _) when check i -> [i, Ptype]
+ | Sig_exception (i, _) when check i -> [i, Pconstructor]
+ | Sig_module (i, _, _) when check i -> [i, Pmodule]
+ | Sig_modtype (i, _) when check i -> [i, Pmodtype]
+ | Sig_class (i, cl, _) when check i
|| List.exists
(get_fields ~prefix:[modname] ~sign (self_type cl.cty_type))
~f:(fun (name,_,_) -> check_match ~pattern (explode name))
-> [i, Pclass]
- | Tsig_cltype (i, cl, _) when check i
+ | Sig_class_type (i, cl, _) when check i
|| List.exists
(get_fields ~prefix:[modname] ~sign (self_type cl.clty_type))
~f:(fun (name,_,_) -> check_match ~pattern (explode name))
@@ -412,8 +413,8 @@ open Parsetree
let rec bound_variables pat =
match pat.ppat_desc with
Ppat_any | Ppat_constant _ | Ppat_type _ | Ppat_unpack _ -> []
- | Ppat_var s -> [s]
- | Ppat_alias (pat,s) -> s :: bound_variables pat
+ | Ppat_var s -> [s.txt]
+ | Ppat_alias (pat,s) -> s.txt :: bound_variables pat
| Ppat_tuple l -> List2.flat_map l ~f:bound_variables
| Ppat_construct (_,None,_) -> []
| Ppat_construct (_,Some pat,_) -> bound_variables pat
@@ -437,7 +438,7 @@ let search_structure str ~name ~kind ~prefix =
List.fold_left ~init:[] str ~f:
begin fun acc item ->
match item.pstr_desc with
- Pstr_module (s, mexp) when s = modu ->
+ Pstr_module (s, mexp) when s.txt = modu ->
loc := mexp.pmod_loc.loc_start.Lexing.pos_cnum;
begin match mexp.pmod_desc with
Pmod_structure str -> str
@@ -457,27 +458,27 @@ let search_structure str ~name ~kind ~prefix =
then loc := pat.ppat_loc.loc_start.Lexing.pos_cnum
end;
false
- | Pstr_primitive (s, _) when kind = Pvalue -> name = s
+ | Pstr_primitive (s, _) when kind = Pvalue -> name = s.txt
| Pstr_type l when kind = Ptype ->
List.iter l ~f:
begin fun (s, td) ->
- if s = name then loc := td.ptype_loc.loc_start.Lexing.pos_cnum
+ if s.txt = name then loc := td.ptype_loc.loc_start.Lexing.pos_cnum
end;
false
- | Pstr_exception (s, _) when kind = Pconstructor -> name = s
- | Pstr_module (s, _) when kind = Pmodule -> name = s
- | Pstr_modtype (s, _) when kind = Pmodtype -> name = s
+ | Pstr_exception (s, _) when kind = Pconstructor -> name = s.txt
+ | Pstr_module (s, _) when kind = Pmodule -> name = s.txt
+ | Pstr_modtype (s, _) when kind = Pmodtype -> name = s.txt
| Pstr_class l when kind = Pclass || kind = Ptype || kind = Pcltype ->
List.iter l ~f:
begin fun c ->
- if c.pci_name = name
+ if c.pci_name.txt = name
then loc := c.pci_loc.loc_start.Lexing.pos_cnum
end;
false
| Pstr_class_type l when kind = Pcltype || kind = Ptype ->
List.iter l ~f:
begin fun c ->
- if c.pci_name = name
+ if c.pci_name.txt = name
then loc := c.pci_loc.loc_start.Lexing.pos_cnum
end;
false
@@ -487,6 +488,8 @@ let search_structure str ~name ~kind ~prefix =
!loc
let search_signature sign ~name ~kind ~prefix =
+ ignore (name = "");
+ ignore (prefix = [""]);
let loc = ref 0 in
let rec search_module_type sign ~prefix =
match prefix with [] -> sign
@@ -495,7 +498,7 @@ let search_signature sign ~name ~kind ~prefix =
List.fold_left ~init:[] sign ~f:
begin fun acc item ->
match item.psig_desc with
- Psig_module (s, mtyp) when s = modu ->
+ Psig_module (s, mtyp) when s.txt = modu ->
loc := mtyp.pmty_loc.loc_start.Lexing.pos_cnum;
begin match mtyp.pmty_desc with
Pmty_signature sign -> sign
@@ -508,27 +511,27 @@ let search_signature sign ~name ~kind ~prefix =
List.iter (search_module_type sign ~prefix) ~f:
begin fun item ->
if match item.psig_desc with
- Psig_value (s, _) when kind = Pvalue -> name = s
+ Psig_value (s, _) when kind = Pvalue -> name = s.txt
| Psig_type l when kind = Ptype ->
List.iter l ~f:
begin fun (s, td) ->
- if s = name then loc := td.ptype_loc.loc_start.Lexing.pos_cnum
+ if s.txt = name then loc := td.ptype_loc.loc_start.Lexing.pos_cnum
end;
false
- | Psig_exception (s, _) when kind = Pconstructor -> name = s
- | Psig_module (s, _) when kind = Pmodule -> name = s
- | Psig_modtype (s, _) when kind = Pmodtype -> name = s
+ | Psig_exception (s, _) when kind = Pconstructor -> name = s.txt
+ | Psig_module (s, _) when kind = Pmodule -> name = s.txt
+ | Psig_modtype (s, _) when kind = Pmodtype -> name = s.txt
| Psig_class l when kind = Pclass || kind = Ptype || kind = Pcltype ->
List.iter l ~f:
begin fun c ->
- if c.pci_name = name
+ if c.pci_name.txt = name
then loc := c.pci_loc.loc_start.Lexing.pos_cnum
end;
false
| Psig_class_type l when kind = Ptype || kind = Pcltype ->
List.iter l ~f:
begin fun c ->
- if c.pci_name = name
+ if c.pci_name.txt = name
then loc := c.pci_loc.loc_start.Lexing.pos_cnum
end;
false
diff --git a/otherlibs/labltk/browser/searchpos.ml b/otherlibs/labltk/browser/searchpos.ml
index 2d4b68947..2ae702adc 100644
--- a/otherlibs/labltk/browser/searchpos.ml
+++ b/otherlibs/labltk/browser/searchpos.ml
@@ -14,6 +14,7 @@
(* $Id$ *)
+open Asttypes
open StdLabels
open Support
open Tk
@@ -118,7 +119,7 @@ let rec search_pos_type t ~pos ~env =
List.iter tl ~f:(search_pos_type ~pos ~env)
| Ptyp_constr (lid, tl) ->
List.iter tl ~f:(search_pos_type ~pos ~env);
- add_found_sig (`Type, lid) ~env ~loc:t.ptyp_loc
+ add_found_sig (`Type, lid.txt) ~env ~loc:t.ptyp_loc
| Ptyp_object fl ->
List.iter fl ~f:
begin function
@@ -127,7 +128,7 @@ let rec search_pos_type t ~pos ~env =
end
| Ptyp_class (lid, tl, _) ->
List.iter tl ~f:(search_pos_type ~pos ~env);
- add_found_sig (`Type, lid) ~env ~loc:t.ptyp_loc
+ add_found_sig (`Type, lid.txt) ~env ~loc:t.ptyp_loc
| Ptyp_alias (t, _)
| Ptyp_poly (_, t) -> search_pos_type ~pos ~env t
| Ptyp_package (_, stl) ->
@@ -138,23 +139,23 @@ let rec search_pos_class_type cl ~pos ~env =
if in_loc cl.pcty_loc ~pos then
begin match cl.pcty_desc with
Pcty_constr (lid, _) ->
- add_found_sig (`Class, lid) ~env ~loc:cl.pcty_loc
- | Pcty_signature (_, cfl) ->
- List.iter cfl ~f:
- begin function
+ add_found_sig (`Class, lid.txt) ~env ~loc:cl.pcty_loc
+ | Pcty_signature cl ->
+ List.iter cl.pcsig_fields ~f: (fun fl ->
+ begin match fl.pctf_desc with
Pctf_inher cty -> search_pos_class_type cty ~pos ~env
- | Pctf_val (_, _, _, ty, loc) ->
- if in_loc loc ~pos then search_pos_type ty ~pos ~env
- | Pctf_virt (_, _, ty, loc) ->
- if in_loc loc ~pos then search_pos_type ty ~pos ~env
- | Pctf_meth (_, _, ty, loc) ->
- if in_loc loc ~pos then search_pos_type ty ~pos ~env
- | Pctf_cstr (ty1, ty2, loc) ->
- if in_loc loc ~pos then begin
+ | Pctf_val (_, _, _, ty) ->
+ if in_loc fl.pctf_loc ~pos then search_pos_type ty ~pos ~env
+ | Pctf_virt (_, _, ty) ->
+ if in_loc fl.pctf_loc ~pos then search_pos_type ty ~pos ~env
+ | Pctf_meth (_, _, ty) ->
+ if in_loc fl.pctf_loc ~pos then search_pos_type ty ~pos ~env
+ | Pctf_cstr (ty1, ty2) ->
+ if in_loc fl.pctf_loc ~pos then begin
search_pos_type ty1 ~pos ~env;
search_pos_type ty2 ~pos ~env
end
- end
+ end)
| Pcty_fun (_, ty, cty) ->
search_pos_type ty ~pos ~env;
search_pos_class_type cty ~pos ~env
@@ -187,13 +188,13 @@ let rec search_pos_signature l ~pos ~env =
begin fun env pt ->
let env = match pt.psig_desc with
Psig_open id ->
- let path, mt = lookup_module id env in
+ let path, mt = lookup_module id.txt env in
begin match mt with
- Tmty_signature sign -> open_signature path sign env
+ Mty_signature sign -> open_signature path sign env
| _ -> env
end
| sign_item ->
- try add_signature (Typemod.transl_signature env [pt]) env
+ try add_signature (Typemod.transl_signature env [pt]).sig_type env
with Typemod.Error _ | Typeclass.Error _
| Typetexp.Error _ | Typedecl.Error _ -> env
in
@@ -219,7 +220,7 @@ let rec search_pos_signature l ~pos ~env =
List.iter l
~f:(fun ci -> search_pos_class_type ci.pci_expr ~pos ~env)
(* The last cases should not happen in generated interfaces *)
- | Psig_open lid -> add_found_sig (`Module, lid) ~env ~loc:pt.psig_loc
+ | Psig_open lid -> add_found_sig (`Module, lid.txt) ~env ~loc:pt.psig_loc
| Psig_include t -> search_pos_module t ~pos ~env
end;
env
@@ -228,7 +229,7 @@ let rec search_pos_signature l ~pos ~env =
and search_pos_module m ~pos ~env =
if in_loc m.pmty_loc ~pos then begin
begin match m.pmty_desc with
- Pmty_ident lid -> add_found_sig (`Modtype, lid) ~env ~loc:m.pmty_loc
+ Pmty_ident lid -> add_found_sig (`Modtype, lid.txt) ~env ~loc:m.pmty_loc
| Pmty_signature sg -> search_pos_signature sg ~pos ~env
| Pmty_functor (_ , m1, m2) ->
search_pos_module m1 ~pos ~env;
@@ -240,7 +241,7 @@ and search_pos_module m ~pos ~env =
_, Pwith_type t -> search_pos_type_decl t ~pos ~env
| _ -> ()
end
- | Pmty_typeof md ->
+ | Pmty_typeof md ->
() (* TODO? *)
end
end
@@ -292,13 +293,13 @@ let edit_source ~file ~path ~sign =
[item] ->
let id, kind =
match item with
- Tsig_value (id, _) -> id, Pvalue
- | Tsig_type (id, _, _) -> id, Ptype
- | Tsig_exception (id, _) -> id, Pconstructor
- | Tsig_module (id, _, _) -> id, Pmodule
- | Tsig_modtype (id, _) -> id, Pmodtype
- | Tsig_class (id, _, _) -> id, Pclass
- | Tsig_cltype (id, _, _) -> id, Pcltype
+ Sig_value (id, _) -> id, Pvalue
+ | Sig_type (id, _, _) -> id, Ptype
+ | Sig_exception (id, _) -> id, Pconstructor
+ | Sig_module (id, _, _) -> id, Pmodule
+ | Sig_modtype (id, _) -> id, Pmodtype
+ | Sig_class (id, _, _) -> id, Pclass
+ | Sig_class_type (id, _, _) -> id, Pcltype
in
let prefix = List.tl (list_of_path path) and name = Ident.name id in
let pos =
@@ -319,7 +320,7 @@ let edit_source ~file ~path ~sign =
(* List of windows to destroy by Close All *)
let top_widgets = ref []
-let dummy_item = Tsig_modtype (Ident.create "dummy", Tmodtype_abstract)
+let dummy_item = Sig_modtype (Ident.create "dummy", Modtype_abstract)
let rec view_signature ?title ?path ?(env = !start_env) ?(detach=false) sign =
let env =
@@ -441,11 +442,11 @@ and view_signature_item sign ~path ~env =
and view_module path ~env =
match find_module path env with
- Tmty_signature sign ->
+ Mty_signature sign ->
!view_defined_ref (Searchid.longident_of_path path) ~env
| modtype ->
let id = ident_of_path path ~default:"M" in
- view_signature_item [Tsig_module (id, modtype, Trec_not)] ~path ~env
+ view_signature_item [Sig_module (id, modtype, Trec_not)] ~path ~env
and view_module_id id ~env =
let path, _ = lookup_module id env in
@@ -458,12 +459,12 @@ and view_type_decl path ~env =
{desc = Tobject _} ->
let clt = find_cltype path env in
view_signature_item ~path ~env
- [Tsig_cltype(ident_of_path path ~default:"ct", clt, Trec_first);
+ [Sig_class_type(ident_of_path path ~default:"ct", clt, Trec_first);
dummy_item; dummy_item]
| _ -> raise Not_found
with Not_found ->
view_signature_item ~path ~env
- [Tsig_type(ident_of_path path ~default:"t", td, Trec_first)]
+ [Sig_type(ident_of_path path ~default:"t", td, Trec_first)]
and view_type_id li ~env =
let path, decl = lookup_type li env in
@@ -472,19 +473,19 @@ and view_type_id li ~env =
and view_class_id li ~env =
let path, cl = lookup_class li env in
view_signature_item ~path ~env
- [Tsig_class(ident_of_path path ~default:"c", cl, Trec_first);
+ [Sig_class(ident_of_path path ~default:"c", cl, Trec_first);
dummy_item; dummy_item; dummy_item]
and view_cltype_id li ~env =
let path, clt = lookup_cltype li env in
view_signature_item ~path ~env
- [Tsig_cltype(ident_of_path path ~default:"ct", clt, Trec_first);
+ [Sig_class_type(ident_of_path path ~default:"ct", clt, Trec_first);
dummy_item; dummy_item]
and view_modtype_id li ~env =
let path, td = lookup_modtype li env in
view_signature_item ~path ~env
- [Tsig_modtype(ident_of_path path ~default:"S", td)]
+ [Sig_modtype(ident_of_path path ~default:"S", td)]
and view_expr_type ?title ?path ?env ?(name="noname") t =
let title =
@@ -496,8 +497,8 @@ and view_expr_type ?title ?path ?env ?(name="noname") t =
| Some path -> parent_path path, ident_of_path path ~default:name
in
view_signature ~title ?path ?env
- [Tsig_value (id, {val_type = t; val_kind = Val_reg;
- val_loc = Location.none})]
+ [Sig_value (id, {val_type = t; val_kind = Val_reg;
+ Types.val_loc = Location.none})]
and view_decl lid ~kind ~env =
match kind with
@@ -577,7 +578,7 @@ let view_type kind ~env =
begin try
let vd = find_value path env in
view_signature_item ~path ~env
- [Tsig_value(ident_of_path path ~default:"v", vd)]
+ [Sig_value(ident_of_path path ~default:"v", vd)]
with Not_found ->
view_expr_type ty ~path ~env
end
@@ -587,19 +588,19 @@ let view_type kind ~env =
| `New path ->
let cl = find_class path env in
view_signature_item ~path ~env
- [Tsig_class(ident_of_path path ~default:"c", cl, Trec_first)]
+ [Sig_class(ident_of_path path ~default:"c", cl, Trec_first)]
end
| `Class (path, cty) ->
let cld = { cty_params = []; cty_variance = []; cty_type = cty;
cty_path = path; cty_new = None } in
view_signature_item ~path ~env
- [Tsig_class(ident_of_path path ~default:"c", cld, Trec_first)]
+ [Sig_class(ident_of_path path ~default:"c", cld, Trec_first)]
| `Module (path, mty) ->
match mty with
- Tmty_signature sign -> view_signature sign ~path ~env
+ Mty_signature sign -> view_signature sign ~path ~env
| modtype ->
view_signature_item ~path ~env
- [Tsig_module(ident_of_path path ~default:"M", mty, Trec_not)]
+ [Sig_module(ident_of_path path ~default:"M", mty, Trec_not)]
let view_type_menu kind ~env ~parent =
let title =
@@ -661,7 +662,7 @@ let add_found_str = add_found ~found:found_str
let rec search_pos_structure ~pos str =
List.iter str ~f:
- begin function
+ begin function str -> match str.str_desc with
Tstr_eval exp -> search_pos_expr exp ~pos
| Tstr_value (rec_flag, l) ->
List.iter l ~f:
@@ -671,56 +672,59 @@ let rec search_pos_structure ~pos str =
search_pos_pat pat ~pos ~env;
search_pos_expr exp ~pos
end
- | Tstr_primitive (_, vd) ->()
+ | Tstr_primitive (_, _, vd) ->()
| Tstr_type _ -> ()
| Tstr_exception _ -> ()
- | Tstr_exn_rebind(_, _) -> ()
- | Tstr_module (_, m) -> search_pos_module_expr m ~pos
+ | Tstr_exn_rebind(_, _, _, _) -> ()
+ | Tstr_module (_, _, m) -> search_pos_module_expr m ~pos
| Tstr_recmodule bindings ->
- List.iter bindings ~f:(fun (_, m) -> search_pos_module_expr m ~pos)
+ List.iter bindings ~f:(fun (_, _, _, m) -> search_pos_module_expr m ~pos)
| Tstr_modtype _ -> ()
| Tstr_open _ -> ()
| Tstr_class l ->
- List.iter l ~f:(fun (id, _, _, cl, _) -> search_pos_class_expr cl ~pos)
- | Tstr_cltype _ -> ()
+ List.iter l ~f:(fun (cl, _, _) -> search_pos_class_expr cl.ci_expr ~pos)
+ | Tstr_class_type _ -> ()
| Tstr_include (m, _) -> search_pos_module_expr m ~pos
end
and search_pos_class_structure ~pos cls =
- List.iter cls.cl_field ~f:
- begin function
- Cf_inher (cl, _, _) ->
+ List.iter cls.cstr_fields ~f:
+ begin function cf -> match cf.cf_desc with
+ Tcf_inher (_, cl, _, _, _) ->
search_pos_class_expr cl ~pos
- | Cf_val (_, _, Some exp, _) -> search_pos_expr exp ~pos
- | Cf_val _ -> ()
- | Cf_meth (_, exp) -> search_pos_expr exp ~pos
- | Cf_init exp -> search_pos_expr exp ~pos
+ | Tcf_val (_, _, _, _, Tcfk_concrete exp, _) -> search_pos_expr exp ~pos
+ | Tcf_val _ -> ()
+ | Tcf_meth (_, _, _, Tcfk_concrete exp, _) -> search_pos_expr exp ~pos
+ | Tcf_init exp -> search_pos_expr exp ~pos
+ | Tcf_constr _
+ | Tcf_meth _
+ -> assert false (* TODO !!!!!!!!!!!!!!!!! *)
end
and search_pos_class_expr ~pos cl =
if in_loc cl.cl_loc ~pos then begin
begin match cl.cl_desc with
- Tclass_ident path ->
+ Tcl_ident (path, _, _) ->
add_found_str (`Class (path, cl.cl_type))
~env:!start_env ~loc:cl.cl_loc
- | Tclass_structure cls ->
+ | Tcl_structure cls ->
search_pos_class_structure ~pos cls
- | Tclass_fun (pat, iel, cl, _) ->
+ | Tcl_fun (_, pat, iel, cl, _) ->
search_pos_pat pat ~pos ~env:pat.pat_env;
- List.iter iel ~f:(fun (_,exp) -> search_pos_expr exp ~pos);
+ List.iter iel ~f:(fun (_,_, exp) -> search_pos_expr exp ~pos);
search_pos_class_expr cl ~pos
- | Tclass_apply (cl, el) ->
+ | Tcl_apply (cl, el) ->
search_pos_class_expr cl ~pos;
- List.iter el ~f:(fun (x,_) -> Misc.may (search_pos_expr ~pos) x)
- | Tclass_let (_, pel, iel, cl) ->
+ List.iter el ~f:(fun (_, x,_) -> Misc.may (search_pos_expr ~pos) x)
+ | Tcl_let (_, pel, iel, cl) ->
List.iter pel ~f:
begin fun (pat, exp) ->
search_pos_pat pat ~pos ~env:exp.exp_env;
search_pos_expr exp ~pos
end;
- List.iter iel ~f:(fun (_,exp) -> search_pos_expr exp ~pos);
+ List.iter iel ~f:(fun (_,_, exp) -> search_pos_expr exp ~pos);
search_pos_class_expr cl ~pos
- | Tclass_constraint (cl, _, _, _) ->
+ | Tcl_constraint (cl, _, _, _, _) ->
search_pos_class_expr cl ~pos
end;
add_found_str (`Class (Pident (Ident.create "c"), cl.cl_type))
@@ -730,7 +734,7 @@ and search_pos_class_expr ~pos cl =
and search_pos_expr ~pos exp =
if in_loc exp.exp_loc ~pos then begin
begin match exp.exp_desc with
- Texp_ident (path, _) ->
+ Texp_ident (path, _, _) ->
add_found_str (`Exp(`Val path, exp.exp_type))
~env:exp.exp_env ~loc:exp.exp_loc
| Texp_constant v ->
@@ -743,14 +747,14 @@ and search_pos_expr ~pos exp =
search_pos_expr exp' ~pos
end;
search_pos_expr exp ~pos
- | Texp_function (l, _) ->
+ | Texp_function (_, l, _) ->
List.iter l ~f:
begin fun (pat, exp) ->
search_pos_pat pat ~pos ~env:exp.exp_env;
search_pos_expr exp ~pos
end
| Texp_apply (exp, l) ->
- List.iter l ~f:(fun (x,_) -> Misc.may (search_pos_expr ~pos) x);
+ List.iter l ~f:(fun (_, x,_) -> Misc.may (search_pos_expr ~pos) x);
search_pos_expr exp ~pos
| Texp_match (exp, l, _) ->
search_pos_expr exp ~pos;
@@ -767,14 +771,14 @@ and search_pos_expr ~pos exp =
search_pos_expr exp ~pos
end
| Texp_tuple l -> List.iter l ~f:(search_pos_expr ~pos)
- | Texp_construct (_, l) -> List.iter l ~f:(search_pos_expr ~pos)
+ | Texp_construct (_, _, _, l,_) -> List.iter l ~f:(search_pos_expr ~pos)
| Texp_variant (_, None) -> ()
| Texp_variant (_, Some exp) -> search_pos_expr exp ~pos
| Texp_record (l, opt) ->
- List.iter l ~f:(fun (_, exp) -> search_pos_expr exp ~pos);
+ List.iter l ~f:(fun (_, _, _, exp) -> search_pos_expr exp ~pos);
(match opt with None -> () | Some exp -> search_pos_expr exp ~pos)
- | Texp_field (exp, _) -> search_pos_expr exp ~pos
- | Texp_setfield (a, _, b) ->
+ | Texp_field (exp, _, _, _) -> search_pos_expr exp ~pos
+ | Texp_setfield (a, _, _, _, b) ->
search_pos_expr a ~pos; search_pos_expr b ~pos
| Texp_array l -> List.iter l ~f:(search_pos_expr ~pos)
| Texp_ifthenelse (a, b, c) ->
@@ -786,24 +790,24 @@ and search_pos_expr ~pos exp =
search_pos_expr a ~pos; search_pos_expr b ~pos
| Texp_while (a,b) ->
search_pos_expr a ~pos; search_pos_expr b ~pos
- | Texp_for (_, a, b, _, c) ->
+ | Texp_for (_, _, a, b, _, c) ->
List.iter [a;b;c] ~f:(search_pos_expr ~pos)
| Texp_when (a, b) ->
search_pos_expr a ~pos; search_pos_expr b ~pos
- | Texp_send (exp, _) -> search_pos_expr exp ~pos
- | Texp_new (path, _) ->
+ | Texp_send (exp, _, _) -> search_pos_expr exp ~pos
+ | Texp_new (path, _, _) ->
add_found_str (`Exp(`New path, exp.exp_type))
~env:exp.exp_env ~loc:exp.exp_loc
- | Texp_instvar (_,path) ->
+ | Texp_instvar (_, path, _) ->
add_found_str (`Exp(`Var path, exp.exp_type))
~env:exp.exp_env ~loc:exp.exp_loc
- | Texp_setinstvar (_, path, exp) ->
+ | Texp_setinstvar (_, path, _, exp) ->
search_pos_expr exp ~pos;
add_found_str (`Exp(`Var path, exp.exp_type))
~env:exp.exp_env ~loc:exp.exp_loc
| Texp_override (_, l) ->
- List.iter l ~f:(fun (_, exp) -> search_pos_expr exp ~pos)
- | Texp_letmodule (id, modexp, exp) ->
+ List.iter l ~f:(fun (_, _, exp) -> search_pos_expr exp ~pos)
+ | Texp_letmodule (id, _, modexp, exp) ->
search_pos_module_expr modexp ~pos;
search_pos_expr exp ~pos
| Texp_assertfalse -> ()
@@ -811,10 +815,11 @@ and search_pos_expr ~pos exp =
search_pos_expr exp ~pos
| Texp_lazy exp ->
search_pos_expr exp ~pos
- | Texp_object (cls, _, _) ->
+ | Texp_object (cls, _) ->
search_pos_class_structure ~pos cls
| Texp_pack modexp ->
search_pos_module_expr modexp ~pos
+ | _ -> assert false (* TODO ................................... *)
end;
add_found_str (`Exp(`Expr, exp.exp_type)) ~env:exp.exp_env ~loc:exp.exp_loc
end
@@ -823,21 +828,21 @@ and search_pos_pat ~pos ~env pat =
if in_loc pat.pat_loc ~pos then begin
begin match pat.pat_desc with
Tpat_any -> ()
- | Tpat_var id ->
+ | Tpat_var (id, _) ->
add_found_str (`Exp(`Val (Pident id), pat.pat_type))
~env ~loc:pat.pat_loc
- | Tpat_alias (pat, _) -> search_pos_pat pat ~pos ~env
+ | Tpat_alias (pat, _, _) -> search_pos_pat pat ~pos ~env
| Tpat_lazy pat -> search_pos_pat pat ~pos ~env
| Tpat_constant _ ->
add_found_str (`Exp(`Const, pat.pat_type)) ~env ~loc:pat.pat_loc
| Tpat_tuple l ->
List.iter l ~f:(search_pos_pat ~pos ~env)
- | Tpat_construct (_, l) ->
+ | Tpat_construct (_, _, _, l, _) ->
List.iter l ~f:(search_pos_pat ~pos ~env)
| Tpat_variant (_, None, _) -> ()
| Tpat_variant (_, Some pat, _) -> search_pos_pat pat ~pos ~env
- | Tpat_record l ->
- List.iter l ~f:(fun (_, pat) -> search_pos_pat pat ~pos ~env)
+ | Tpat_record (l, _) ->
+ List.iter l ~f:(fun (_, _, _, pat) -> search_pos_pat pat ~pos ~env)
| Tpat_array l ->
List.iter l ~f:(search_pos_pat ~pos ~env)
| Tpat_or (a, b, None) ->
@@ -848,17 +853,17 @@ and search_pos_pat ~pos ~env pat =
add_found_str (`Exp(`Pat, pat.pat_type)) ~env ~loc:pat.pat_loc
end
-and search_pos_module_expr ~pos m =
+and search_pos_module_expr ~pos (m :module_expr) =
if in_loc m.mod_loc ~pos then begin
begin match m.mod_desc with
- Tmod_ident path ->
+ Tmod_ident (path, _) ->
add_found_str (`Module (path, m.mod_type))
~env:m.mod_env ~loc:m.mod_loc
- | Tmod_structure str -> search_pos_structure str ~pos
- | Tmod_functor (_, _, m) -> search_pos_module_expr m ~pos
+ | Tmod_structure str -> search_pos_structure str.str_items ~pos
+ | Tmod_functor (_, _, _, m) -> search_pos_module_expr m ~pos
| Tmod_apply (a, b, _) ->
search_pos_module_expr a ~pos; search_pos_module_expr b ~pos
- | Tmod_constraint (m, _, _) -> search_pos_module_expr m ~pos
+ | Tmod_constraint (m, _, _, _) -> search_pos_module_expr m ~pos
| Tmod_unpack (e, _) -> search_pos_expr e ~pos
end;
add_found_str (`Module (Pident (Ident.create "M"), m.mod_type))
diff --git a/otherlibs/labltk/browser/typecheck.ml b/otherlibs/labltk/browser/typecheck.ml
index ac861a6f2..f557105f1 100644
--- a/otherlibs/labltk/browser/typecheck.ml
+++ b/otherlibs/labltk/browser/typecheck.ml
@@ -17,6 +17,7 @@
open StdLabels
open Tk
open Parsetree
+open Typedtree
open Location
open Jg_tk
open Mytypes
@@ -105,7 +106,7 @@ let f txt =
let psign = parse_pp text ~ext:".mli"
~parse:Parse.interface ~wrap:(fun x -> x) in
txt.psignature <- psign;
- txt.signature <- Typemod.transl_signature !env psign
+ txt.signature <- (Typemod.transl_signature !env psign).sig_type;
else (* others are interpreted as .ml *)
@@ -115,7 +116,7 @@ let f txt =
begin function
Ptop_def pstr ->
let str, sign, env' = Typemod.type_structure !env pstr Location.none in
- txt.structure <- txt.structure @ str;
+ txt.structure <- txt.structure @ str.str_items;
txt.signature <- txt.signature @ sign;
env := env'
| Ptop_dir _ -> ()
@@ -156,6 +157,8 @@ let f txt =
Includemod.report_error Format.std_formatter errl; Location.none
| Env.Error err ->
Env.report_error Format.std_formatter err; Location.none
+ | Cmi_format.Error err ->
+ Cmi_format.report_error Format.std_formatter err; Location.none
| Ctype.Tags(l, l') ->
Format.printf "In this program,@ variant constructors@ `%s and `%s@ have same hash value.@." l l';
Location.none
diff --git a/otherlibs/labltk/browser/viewer.ml b/otherlibs/labltk/browser/viewer.ml
index 72b9c1d66..34ccfd7a2 100644
--- a/otherlibs/labltk/browser/viewer.ml
+++ b/otherlibs/labltk/browser/viewer.ml
@@ -61,20 +61,20 @@ let view_symbol ~kind ~env ?path id =
match kind with
Pvalue ->
let path, vd = lookup_value id env in
- view_signature_item ~path ~env [Tsig_value (Ident.create name, vd)]
+ view_signature_item ~path ~env [Sig_value (Ident.create name, vd)]
| Ptype -> view_type_id id ~env
- | Plabel -> let ld = lookup_label id env in
+ | Plabel -> let _,ld = lookup_label id env in
begin match ld.lbl_res.desc with
Tconstr (path, _, _) -> view_type_decl path ~env
| _ -> ()
end
| Pconstructor ->
- let cd = lookup_constructor id env in
+ let _,cd = lookup_constructor id env in
begin match cd.cstr_res.desc with
Tconstr (cpath, _, _) ->
if Path.same cpath Predef.path_exn then
view_signature ~title:(string_of_longident id) ~env ?path
- [Tsig_exception (Ident.create name, {exn_loc = Location.none; exn_args = cd.cstr_args})]
+ [Sig_exception (Ident.create name, {Types.exn_loc = Location.none; exn_args = cd.cstr_args})]
else
view_type_decl cpath ~env
| _ -> ()
@@ -217,23 +217,23 @@ let search_symbol () =
(* Display the contents of a module *)
let ident_of_decl ~modlid = function
- Tsig_value (id, _) -> Lident (Ident.name id), Pvalue
- | Tsig_type (id, _, _) -> Lident (Ident.name id), Ptype
- | Tsig_exception (id, _) -> Ldot (modlid, Ident.name id), Pconstructor
- | Tsig_module (id, _, _) -> Lident (Ident.name id), Pmodule
- | Tsig_modtype (id, _) -> Lident (Ident.name id), Pmodtype
- | Tsig_class (id, _, _) -> Lident (Ident.name id), Pclass
- | Tsig_cltype (id, _, _) -> Lident (Ident.name id), Pcltype
+ Sig_value (id, _) -> Lident (Ident.name id), Pvalue
+ | Sig_type (id, _, _) -> Lident (Ident.name id), Ptype
+ | Sig_exception (id, _) -> Ldot (modlid, Ident.name id), Pconstructor
+ | Sig_module (id, _, _) -> Lident (Ident.name id), Pmodule
+ | Sig_modtype (id, _) -> Lident (Ident.name id), Pmodtype
+ | Sig_class (id, _, _) -> Lident (Ident.name id), Pclass
+ | Sig_class_type (id, _, _) -> Lident (Ident.name id), Pcltype
let view_defined ~env ?(show_all=false) modlid =
- try match lookup_module modlid env with path, Tmty_signature sign ->
+ try match lookup_module modlid env with path, Mty_signature sign ->
let rec iter_sign sign idents =
match sign with
[] -> List.rev idents
| decl :: rem ->
let rem = match decl, rem with
- Tsig_class _, cty :: ty1 :: ty2 :: rem -> rem
- | Tsig_cltype _, ty1 :: ty2 :: rem -> rem
+ Sig_class _, cty :: ty1 :: ty2 :: rem -> rem
+ | Sig_class_type _, ty1 :: ty2 :: rem -> rem
| _, rem -> rem
in iter_sign rem (ident_of_decl ~modlid decl :: idents)
in
@@ -248,6 +248,10 @@ let view_defined ~env ?(show_all=false) modlid =
let tl, tw, finish = Jg_message.formatted ~title:"Error!" () in
Env.report_error Format.std_formatter err;
finish ()
+ | Cmi_format.Error err ->
+ let tl, tw, finish = Jg_message.formatted ~title:"Error!" () in
+ Cmi_format.report_error Format.std_formatter err;
+ finish ()
(* Manage toplevel windows *)
diff --git a/parsing/asttypes.mli b/parsing/asttypes.mli
index d23a87fb7..ecdfcc5fd 100644
--- a/parsing/asttypes.mli
+++ b/parsing/asttypes.mli
@@ -38,3 +38,8 @@ type override_flag = Override | Fresh
type closed_flag = Closed | Open
type label = string
+
+type 'a loc = 'a Location.loc = {
+ txt : 'a;
+ loc : Location.t;
+}
diff --git a/parsing/lexer.mli b/parsing/lexer.mli
index 175eedc90..d3dc035fe 100644
--- a/parsing/lexer.mli
+++ b/parsing/lexer.mli
@@ -14,15 +14,16 @@
(* The lexical analyzer *)
+val init : unit -> unit
val token: Lexing.lexbuf -> Parser.token
val skip_sharp_bang: Lexing.lexbuf -> unit
type error =
| Illegal_character of char
| Illegal_escape of string
- | Unterminated_comment
+ | Unterminated_comment of Location.t
| Unterminated_string
- | Unterminated_string_in_comment
+ | Unterminated_string_in_comment of Location.t
| Keyword_as_label of string
| Literal_overflow of string
;;
@@ -34,3 +35,9 @@ open Format
val report_error: formatter -> error -> unit
val in_comment : unit -> bool;;
+val in_string : unit -> bool;;
+
+
+val print_warnings : bool ref
+val comments : unit -> (string * Location.t) list
+val token_with_comments : Lexing.lexbuf -> Parser.token
diff --git a/parsing/lexer.mll b/parsing/lexer.mll
index e1b8c46eb..652382aa7 100644
--- a/parsing/lexer.mll
+++ b/parsing/lexer.mll
@@ -22,9 +22,9 @@ open Parser
type error =
| Illegal_character of char
| Illegal_escape of string
- | Unterminated_comment
+ | Unterminated_comment of Location.t
| Unterminated_string
- | Unterminated_string_in_comment
+ | Unterminated_string_in_comment of Location.t
| Keyword_as_label of string
| Literal_overflow of string
;;
@@ -113,6 +113,12 @@ let store_string_char c =
String.unsafe_set (!string_buff) (!string_index) c;
incr string_index
+let store_lexeme lexbuf =
+ let s = Lexing.lexeme lexbuf in
+ for i = 0 to String.length s - 1 do
+ store_string_char s.[i];
+ done
+
let get_stored_string () =
let s = String.sub (!string_buff) 0 (!string_index) in
string_buff := initial_string_buffer;
@@ -122,6 +128,9 @@ let get_stored_string () =
let string_start_loc = ref Location.none;;
let comment_start_loc = ref [];;
let in_comment () = !comment_start_loc <> [];;
+let is_in_string = ref false
+let in_string () = !is_in_string
+let print_warnings = ref true
(* To translate escape sequences *)
@@ -204,11 +213,11 @@ let report_error ppf = function
fprintf ppf "Illegal character (%s)" (Char.escaped c)
| Illegal_escape s ->
fprintf ppf "Illegal backslash escape in string or character (%s)" s
- | Unterminated_comment ->
+ | Unterminated_comment _ ->
fprintf ppf "Comment not terminated"
| Unterminated_string ->
fprintf ppf "String literal not terminated"
- | Unterminated_string_in_comment ->
+ | Unterminated_string_in_comment _ ->
fprintf ppf "This comment contains an unterminated string literal"
| Keyword_as_label kwd ->
fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd
@@ -299,9 +308,11 @@ rule token = parse
raise (Error(Literal_overflow "nativeint", Location.curr lexbuf)) }
| "\""
{ reset_string_buffer();
+ is_in_string := true;
let string_start = lexbuf.lex_start_p in
string_start_loc := Location.curr lexbuf;
string lexbuf;
+ is_in_string := false;
lexbuf.lex_start_p <- string_start;
STRING (get_stored_string()) }
| "'" newline "'"
@@ -321,15 +332,24 @@ rule token = parse
raise (Error(Illegal_escape esc, Location.curr lexbuf))
}
| "(*"
- { comment_start_loc := [Location.curr lexbuf];
- comment lexbuf;
- token lexbuf }
+ { let start_loc = Location.curr lexbuf in
+ comment_start_loc := [start_loc];
+ reset_string_buffer ();
+ let end_loc = comment lexbuf in
+ let s = get_stored_string () in
+ reset_string_buffer ();
+ COMMENT (s, { start_loc with Location.loc_end = end_loc.Location.loc_end })
+ }
| "(*)"
- { let loc = Location.curr lexbuf in
- Location.prerr_warning loc Warnings.Comment_start;
- comment_start_loc := [Location.curr lexbuf];
- comment lexbuf;
- token lexbuf
+ { let loc = Location.curr lexbuf in
+ if !print_warnings then
+ Location.prerr_warning loc Warnings.Comment_start;
+ comment_start_loc := [loc];
+ reset_string_buffer ();
+ let end_loc = comment lexbuf in
+ let s = get_stored_string () in
+ reset_string_buffer ();
+ COMMENT (s, { loc with Location.loc_end = end_loc.Location.loc_end })
}
| "*)"
{ let loc = Location.curr lexbuf in
@@ -411,53 +431,64 @@ rule token = parse
and comment = parse
"(*"
{ comment_start_loc := (Location.curr lexbuf) :: !comment_start_loc;
+ store_lexeme lexbuf;
comment lexbuf;
}
| "*)"
{ match !comment_start_loc with
| [] -> assert false
- | [_] -> comment_start_loc := [];
+ | [_] -> comment_start_loc := []; Location.curr lexbuf
| _ :: l -> comment_start_loc := l;
- comment lexbuf;
+ store_lexeme lexbuf;
+ comment lexbuf;
}
| "\""
- { reset_string_buffer();
+ {
string_start_loc := Location.curr lexbuf;
+ store_string_char '"';
+ is_in_string := true;
begin try string lexbuf
with Error (Unterminated_string, _) ->
match !comment_start_loc with
| [] -> assert false
- | loc :: _ -> comment_start_loc := [];
- raise (Error (Unterminated_string_in_comment, loc))
+ | loc :: _ ->
+ let start = List.hd (List.rev !comment_start_loc) in
+ comment_start_loc := [];
+ raise (Error (Unterminated_string_in_comment start, loc))
end;
- reset_string_buffer ();
+ is_in_string := false;
+ store_string_char '"';
comment lexbuf }
| "''"
- { comment lexbuf }
+ { store_lexeme lexbuf; comment lexbuf }
| "'" newline "'"
{ update_loc lexbuf None 1 false 1;
+ store_lexeme lexbuf;
comment lexbuf
}
| "'" [^ '\\' '\'' '\010' '\013' ] "'"
- { comment lexbuf }
+ { store_lexeme lexbuf; comment lexbuf }
| "'\\" ['\\' '"' '\'' 'n' 't' 'b' 'r' ' '] "'"
- { comment lexbuf }
+ { store_lexeme lexbuf; comment lexbuf }
| "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
- { comment lexbuf }
+ { store_lexeme lexbuf; comment lexbuf }
| "'\\" 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] "'"
- { comment lexbuf }
+ { store_lexeme lexbuf; comment lexbuf }
| eof
{ match !comment_start_loc with
| [] -> assert false
- | loc :: _ -> comment_start_loc := [];
- raise (Error (Unterminated_comment, loc))
+ | loc :: _ ->
+ let start = List.hd (List.rev !comment_start_loc) in
+ comment_start_loc := [];
+ raise (Error (Unterminated_comment start, loc))
}
| newline
{ update_loc lexbuf None 1 false 0;
+ store_lexeme lexbuf;
comment lexbuf
}
| _
- { comment lexbuf }
+ { store_lexeme lexbuf; comment lexbuf }
and string = parse
'"'
@@ -494,14 +525,12 @@ and string = parse
{ if not (in_comment ()) then
Location.prerr_warning (Location.curr lexbuf) Warnings.Eol_in_string;
update_loc lexbuf None 1 false 0;
- let s = Lexing.lexeme lexbuf in
- for i = 0 to String.length s - 1 do
- store_string_char s.[i];
- done;
+ store_lexeme lexbuf;
string lexbuf
}
| eof
- { raise (Error (Unterminated_string, !string_start_loc)) }
+ { is_in_string := false;
+ raise (Error (Unterminated_string, !string_start_loc)) }
| _
{ store_string_char(Lexing.lexeme_char lexbuf 0);
string lexbuf }
@@ -512,3 +541,21 @@ and skip_sharp_bang = parse
| "#!" [^ '\n']* '\n'
{ update_loc lexbuf None 1 false 0 }
| "" { () }
+
+{
+ let token_with_comments = token
+
+ let last_comments = ref []
+ let rec token lexbuf =
+ match token_with_comments lexbuf with
+ COMMENT (s, comment_loc) ->
+ last_comments := (s, comment_loc) :: !last_comments;
+ token lexbuf
+ | tok -> tok
+ let comments () = List.rev !last_comments
+ let init () =
+ is_in_string := false;
+ last_comments := [];
+ comment_start_loc := []
+
+}
diff --git a/parsing/location.ml b/parsing/location.ml
index 5be3b69c2..5141534fc 100644
--- a/parsing/location.ml
+++ b/parsing/location.ml
@@ -276,3 +276,11 @@ let prerr_warning loc w = print_warning loc err_formatter w;;
let echo_eof () =
print_newline ();
incr num_loc_lines
+
+type 'a loc = {
+ txt : 'a;
+ loc : t;
+}
+
+let mkloc txt loc = { txt ; loc }
+let mknoloc txt = mkloc txt none
diff --git a/parsing/location.mli b/parsing/location.mli
index 2b1a5a8fa..23c5c979b 100644
--- a/parsing/location.mli
+++ b/parsing/location.mli
@@ -41,6 +41,9 @@ val curr : Lexing.lexbuf -> t
val symbol_rloc: unit -> t
val symbol_gloc: unit -> t
+
+(** [rhs_loc n] returns the location of the symbol at position [n], starting
+ at 1, in the current parser rule. *)
val rhs_loc: int -> t
val input_name: string ref
@@ -57,6 +60,14 @@ val reset: unit -> unit
val highlight_locations: formatter -> t -> t -> bool
+type 'a loc = {
+ txt : 'a;
+ loc : t;
+}
+
+val mknoloc : 'a -> 'a loc
+val mkloc : 'a -> t -> 'a loc
+
val print: formatter -> t -> unit
val print_filename: formatter -> string -> unit
@@ -66,3 +77,4 @@ val show_filename: string -> string
val absname: bool ref
+
diff --git a/parsing/parse.ml b/parsing/parse.ml
index 9dcc3e41c..32066db32 100644
--- a/parsing/parse.ml
+++ b/parsing/parse.ml
@@ -22,9 +22,9 @@ let rec skip_phrase lexbuf =
Parser.SEMISEMI | Parser.EOF -> ()
| _ -> skip_phrase lexbuf
with
- | Lexer.Error (Lexer.Unterminated_comment, _) -> ()
+ | Lexer.Error (Lexer.Unterminated_comment _, _) -> ()
| Lexer.Error (Lexer.Unterminated_string, _) -> ()
- | Lexer.Error (Lexer.Unterminated_string_in_comment, _) -> ()
+ | Lexer.Error (Lexer.Unterminated_string_in_comment _, _) -> ()
| Lexer.Error (Lexer.Illegal_character _, _) -> skip_phrase lexbuf
;;
@@ -36,13 +36,14 @@ let maybe_skip_phrase lexbuf =
let wrap parsing_fun lexbuf =
try
+ Lexer.init ();
let ast = parsing_fun Lexer.token lexbuf in
Parsing.clear_parser();
ast
with
- | Lexer.Error(Lexer.Unterminated_comment, _) as err -> raise err
+ | Lexer.Error(Lexer.Unterminated_comment _, _) as err -> raise err
| Lexer.Error(Lexer.Unterminated_string, _) as err -> raise err
- | Lexer.Error(Lexer.Unterminated_string_in_comment, _) as err -> raise err
+ | Lexer.Error(Lexer.Unterminated_string_in_comment _, _) as err -> raise err
| Lexer.Error(Lexer.Illegal_character _, _) as err ->
if !Location.input_name = "//toplevel//" then skip_phrase lexbuf;
raise err
diff --git a/parsing/parser.mly b/parsing/parser.mly
index a5065b5cf..b563094c1 100644
--- a/parsing/parser.mly
+++ b/parsing/parser.mly
@@ -40,15 +40,24 @@ let mkclass d =
{ pcl_desc = d; pcl_loc = symbol_rloc() }
let mkcty d =
{ pcty_desc = d; pcty_loc = symbol_rloc() }
+let mkctf d =
+ { pctf_desc = d; pctf_loc = symbol_rloc () }
+let mkcf d =
+ { pcf_desc = d; pcf_loc = symbol_rloc () }
+let mkrhs rhs pos = mkloc rhs (rhs_loc pos)
+let mkoption d =
+ { ptyp_desc = Ptyp_constr(mknoloc (Ldot (Lident "*predef*", "option")), [d]);
+ ptyp_loc = d.ptyp_loc}
let reloc_pat x = { x with ppat_loc = symbol_rloc () };;
let reloc_exp x = { x with pexp_loc = symbol_rloc () };;
let mkoperator name pos =
- { pexp_desc = Pexp_ident(Lident name); pexp_loc = rhs_loc pos }
+ let loc = rhs_loc pos in
+ { pexp_desc = Pexp_ident(mkloc (Lident name) loc); pexp_loc = loc }
let mkpatvar name pos =
- { ppat_desc = Ppat_var name; ppat_loc = rhs_loc pos }
+ { ppat_desc = Ppat_var (mkrhs name pos); ppat_loc = rhs_loc pos }
(*
Ghost expressions and patterns:
@@ -73,9 +82,9 @@ let ghtyp d = { ptyp_desc = d; ptyp_loc = symbol_gloc () };;
let mkassert e =
match e with
- | { pexp_desc = Pexp_construct (Lident "false", None, false);
- pexp_loc = _ } ->
- mkexp (Pexp_assertfalse)
+ | {pexp_desc = Pexp_construct ({ txt = Lident "false" }, None , false);
+ pexp_loc = _ } ->
+ mkexp (Pexp_assertfalse)
| _ -> mkexp (Pexp_assert (e))
;;
@@ -113,9 +122,17 @@ let mkuplus name arg =
| _ ->
mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, ["", arg]))
+let mkexp_cons args loc =
+ {pexp_desc = Pexp_construct(mkloc (Lident "::") Location.none,
+ Some args, false); pexp_loc = loc}
+
+let mkpat_cons args loc =
+ {ppat_desc = Ppat_construct(mkloc (Lident "::") Location.none,
+ Some args, false); ppat_loc = loc}
+
let rec mktailexp = function
[] ->
- ghexp(Pexp_construct(Lident "[]", None, false))
+ ghexp(Pexp_construct(mkloc (Lident "[]") Location.none, None, false))
| e1 :: el ->
let exp_el = mktailexp el in
let l = {loc_start = e1.pexp_loc.loc_start;
@@ -123,11 +140,11 @@ let rec mktailexp = function
loc_ghost = true}
in
let arg = {pexp_desc = Pexp_tuple [e1; exp_el]; pexp_loc = l} in
- {pexp_desc = Pexp_construct(Lident "::", Some arg, false); pexp_loc = l}
+ mkexp_cons arg l
let rec mktailpat = function
[] ->
- ghpat(Ppat_construct(Lident "[]", None, false))
+ ghpat(Ppat_construct(mkloc (Lident "[]") Location.none, None, false))
| p1 :: pl ->
let pat_pl = mktailpat pl in
let l = {loc_start = p1.ppat_loc.loc_start;
@@ -135,13 +152,13 @@ let rec mktailpat = function
loc_ghost = true}
in
let arg = {ppat_desc = Ppat_tuple [p1; pat_pl]; ppat_loc = l} in
- {ppat_desc = Ppat_construct(Lident "::", Some arg, false); ppat_loc = l}
+ mkpat_cons arg l
let ghstrexp e =
{ pstr_desc = Pstr_eval e; pstr_loc = {e.pexp_loc with loc_ghost = true} }
let array_function str name =
- Ldot(Lident str, (if !Clflags.fast then "unsafe_" ^ name else name))
+ mknoloc (Ldot(Lident str, (if !Clflags.fast then "unsafe_" ^ name else name)))
let rec deep_mkrangepat c1 c2 =
if c1 = c2 then ghpat(Ppat_constant(Const_char c1)) else
@@ -161,7 +178,7 @@ let unclosed opening_name opening_num closing_name closing_num =
rhs_loc closing_num, closing_name)))
let bigarray_function str name =
- Ldot(Ldot(Lident "Bigarray", str), name)
+ mkloc (Ldot(Ldot(Lident "Bigarray", str), name)) Location.none
let bigarray_untuplify = function
{ pexp_desc = Pexp_tuple explist; pexp_loc = _ } -> explist
@@ -206,11 +223,11 @@ let lapply p1 p2 =
then Lapply(p1, p2)
else raise (Syntaxerr.Error(Syntaxerr.Applicative_path (symbol_rloc())))
-let exp_of_label lbl =
- mkexp (Pexp_ident(Lident(Longident.last lbl)))
+let exp_of_label lbl pos =
+ mkexp (Pexp_ident(mkrhs (Lident(Longident.last lbl)) pos))
-let pat_of_label lbl =
- mkpat (Ppat_var(Longident.last lbl))
+let pat_of_label lbl pos =
+ mkpat (Ppat_var (mkrhs (Longident.last lbl) pos))
let check_variable vl loc v =
if List.mem v vl then
@@ -227,7 +244,7 @@ let varify_constructors var_names t =
| Ptyp_arrow (label,core_type,core_type') ->
Ptyp_arrow(label, loop core_type, loop core_type')
| Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
- | Ptyp_constr(Lident s, []) when List.mem s var_names ->
+ | Ptyp_constr( { txt = Lident s }, []) when List.mem s var_names ->
Ptyp_var s
| Ptyp_constr(longident, lst) ->
Ptyp_constr(longident, List.map loop lst)
@@ -389,6 +406,7 @@ let wrap_type_annotation newtypes core_type body =
%token WHEN
%token WHILE
%token WITH
+%token <string * Location.t> COMMENT
/* Precedences and associativities.
@@ -461,7 +479,8 @@ The precedences must be listed from low to high.
%type <Parsetree.toplevel_phrase> toplevel_phrase
%start use_file /* for the #use directive */
%type <Parsetree.toplevel_phrase list> use_file
-
+%start any_longident
+%type <Longident.t> any_longident
%%
/* Entry points */
@@ -500,13 +519,13 @@ use_file_tail:
module_expr:
mod_longident
- { mkmod(Pmod_ident $1) }
+ { mkmod(Pmod_ident (mkrhs $1 1)) }
| STRUCT structure END
{ mkmod(Pmod_structure($2)) }
| STRUCT structure error
{ unclosed "struct" 1 "end" 3 }
| FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_expr
- { mkmod(Pmod_functor($3, $5, $8)) }
+ { mkmod(Pmod_functor(mkrhs $3 3, $5, $8)) }
| module_expr LPAREN module_expr RPAREN
{ mkmod(Pmod_apply($1, $3)) }
| module_expr LPAREN module_expr error
@@ -555,21 +574,22 @@ structure_item:
[{ ppat_desc = Ppat_any; ppat_loc = _ }, exp] -> mkstr(Pstr_eval exp)
| _ -> mkstr(Pstr_value($2, List.rev $3)) }
| EXTERNAL val_ident COLON core_type EQUAL primitive_declaration
- { mkstr(Pstr_primitive($2, {pval_type = $4; pval_prim = $6})) }
+ { mkstr(Pstr_primitive(mkrhs $2 2, {pval_type = $4; pval_prim = $6;
+ pval_loc = symbol_rloc ()})) }
| TYPE type_declarations
{ mkstr(Pstr_type(List.rev $2)) }
| EXCEPTION UIDENT constructor_arguments
- { mkstr(Pstr_exception($2, $3)) }
+ { mkstr(Pstr_exception(mkrhs $2 2, $3)) }
| EXCEPTION UIDENT EQUAL constr_longident
- { mkstr(Pstr_exn_rebind($2, $4)) }
+ { mkstr(Pstr_exn_rebind(mkrhs $2 2, mkloc $4 (rhs_loc 4))) }
| MODULE UIDENT module_binding
- { mkstr(Pstr_module($2, $3)) }
+ { mkstr(Pstr_module(mkrhs $2 2, $3)) }
| MODULE REC module_rec_bindings
{ mkstr(Pstr_recmodule(List.rev $3)) }
| MODULE TYPE ident EQUAL module_type
- { mkstr(Pstr_modtype($3, $5)) }
+ { mkstr(Pstr_modtype(mkrhs $3 3, $5)) }
| OPEN mod_longident
- { mkstr(Pstr_open $2) }
+ { mkstr(Pstr_open (mkrhs $2 2)) }
| CLASS class_declarations
{ mkstr(Pstr_class (List.rev $2)) }
| CLASS TYPE class_type_declarations
@@ -583,28 +603,28 @@ module_binding:
| COLON module_type EQUAL module_expr
{ mkmod(Pmod_constraint($4, $2)) }
| LPAREN UIDENT COLON module_type RPAREN module_binding
- { mkmod(Pmod_functor($2, $4, $6)) }
+ { mkmod(Pmod_functor(mkrhs $2 2, $4, $6)) }
;
module_rec_bindings:
module_rec_binding { [$1] }
| module_rec_bindings AND module_rec_binding { $3 :: $1 }
;
module_rec_binding:
- UIDENT COLON module_type EQUAL module_expr { ($1, $3, $5) }
+ UIDENT COLON module_type EQUAL module_expr { (mkrhs $1 1, $3, $5) }
;
/* Module types */
module_type:
mty_longident
- { mkmty(Pmty_ident $1) }
+ { mkmty(Pmty_ident (mkrhs $1 1)) }
| SIG signature END
{ mkmty(Pmty_signature(List.rev $2)) }
| SIG signature error
{ unclosed "sig" 1 "end" 3 }
| FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_type
%prec below_WITH
- { mkmty(Pmty_functor($3, $5, $8)) }
+ { mkmty(Pmty_functor(mkrhs $3 3, $5, $8)) }
| module_type WITH with_constraints
{ mkmty(Pmty_with($1, List.rev $3)) }
| MODULE TYPE OF module_expr
@@ -621,23 +641,25 @@ signature:
;
signature_item:
VAL val_ident COLON core_type
- { mksig(Psig_value($2, {pval_type = $4; pval_prim = []})) }
+ { mksig(Psig_value(mkrhs $2 2, {pval_type = $4; pval_prim = [];
+ pval_loc = symbol_rloc()})) }
| EXTERNAL val_ident COLON core_type EQUAL primitive_declaration
- { mksig(Psig_value($2, {pval_type = $4; pval_prim = $6})) }
+ { mksig(Psig_value(mkrhs $2 2, {pval_type = $4; pval_prim = $6;
+ pval_loc = symbol_rloc()})) }
| TYPE type_declarations
{ mksig(Psig_type(List.rev $2)) }
| EXCEPTION UIDENT constructor_arguments
- { mksig(Psig_exception($2, $3)) }
+ { mksig(Psig_exception(mkrhs $2 2, $3)) }
| MODULE UIDENT module_declaration
- { mksig(Psig_module($2, $3)) }
+ { mksig(Psig_module(mkrhs $2 2, $3)) }
| MODULE REC module_rec_declarations
{ mksig(Psig_recmodule(List.rev $3)) }
| MODULE TYPE ident
- { mksig(Psig_modtype($3, Pmodtype_abstract)) }
+ { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_abstract)) }
| MODULE TYPE ident EQUAL module_type
- { mksig(Psig_modtype($3, Pmodtype_manifest $5)) }
+ { mksig(Psig_modtype(mkrhs $3 3, Pmodtype_manifest $5)) }
| OPEN mod_longident
- { mksig(Psig_open $2) }
+ { mksig(Psig_open (mkrhs $2 2)) }
| INCLUDE module_type
{ mksig(Psig_include $2) }
| CLASS class_descriptions
@@ -650,14 +672,14 @@ module_declaration:
COLON module_type
{ $2 }
| LPAREN UIDENT COLON module_type RPAREN module_declaration
- { mkmty(Pmty_functor($2, $4, $6)) }
+ { mkmty(Pmty_functor(mkrhs $2 2, $4, $6)) }
;
module_rec_declarations:
module_rec_declaration { [$1] }
| module_rec_declarations AND module_rec_declaration { $3 :: $1 }
;
module_rec_declaration:
- UIDENT COLON module_type { ($1, $3) }
+ UIDENT COLON module_type { (mkrhs $1 1, $3) }
;
/* Class expressions */
@@ -670,7 +692,7 @@ class_declaration:
virtual_flag class_type_parameters LIDENT class_fun_binding
{ let params, variance = List.split (fst $2) in
{pci_virt = $1; pci_params = params, snd $2;
- pci_name = $3; pci_expr = $4; pci_variance = variance;
+ pci_name = mkrhs $3 3; pci_expr = $4; pci_variance = variance;
pci_loc = symbol_rloc ()} }
;
class_fun_binding:
@@ -703,9 +725,9 @@ class_expr:
;
class_simple_expr:
LBRACKET core_type_comma_list RBRACKET class_longident
- { mkclass(Pcl_constr($4, List.rev $2)) }
+ { mkclass(Pcl_constr(mkloc $4 (rhs_loc 4), List.rev $2)) }
| class_longident
- { mkclass(Pcl_constr($1, [])) }
+ { mkclass(Pcl_constr(mkrhs $1 1, [])) }
| OBJECT class_structure END
{ mkclass(Pcl_structure($2)) }
| OBJECT class_structure error
@@ -721,7 +743,7 @@ class_simple_expr:
;
class_structure:
class_self_pattern class_fields
- { $1, List.rev $2 }
+ { { pcstr_pat = $1; pcstr_fields = List.rev $2 } }
;
class_self_pattern:
LPAREN pattern RPAREN
@@ -734,20 +756,24 @@ class_self_pattern:
class_fields:
/* empty */
{ [] }
- | class_fields INHERIT override_flag class_expr parent_binder
- { Pcf_inher ($3, $4, $5) :: $1 }
- | class_fields VAL virtual_value
- { Pcf_valvirt $3 :: $1 }
- | class_fields VAL value
- { Pcf_val $3 :: $1 }
- | class_fields virtual_method
- { Pcf_virt $2 :: $1 }
- | class_fields concrete_method
- { Pcf_meth $2 :: $1 }
- | class_fields CONSTRAINT constrain
- { Pcf_cstr $3 :: $1 }
- | class_fields INITIALIZER seq_expr
- { Pcf_init $3 :: $1 }
+ | class_fields class_field
+ { $2 :: $1 }
+;
+class_field:
+ | INHERIT override_flag class_expr parent_binder
+ { mkcf (Pcf_inher ($2, $3, $4)) }
+ | VAL virtual_value
+ { mkcf (Pcf_valvirt $2) }
+ | VAL value
+ { mkcf (Pcf_val $2) }
+ | virtual_method
+ { mkcf (Pcf_virt $1) }
+ | concrete_method
+ { mkcf (Pcf_meth $1) }
+ | CONSTRAINT constrain_field
+ { mkcf (Pcf_constr $2) }
+ | INITIALIZER seq_expr
+ { mkcf (Pcf_init $2) }
;
parent_binder:
AS LIDENT
@@ -758,34 +784,33 @@ parent_binder:
virtual_value:
override_flag MUTABLE VIRTUAL label COLON core_type
{ if $1 = Override then syntax_error ();
- $4, Mutable, $6, symbol_rloc () }
+ mkloc $4 (rhs_loc 4), Mutable, $6 }
| VIRTUAL mutable_flag label COLON core_type
- { $3, $2, $5, symbol_rloc () }
+ { mkrhs $3 3, $2, $5 }
;
value:
override_flag mutable_flag label EQUAL seq_expr
- { $3, $2, $1, $5, symbol_rloc () }
+ { mkrhs $3 3, $2, $1, $5 }
| override_flag mutable_flag label type_constraint EQUAL seq_expr
- { $3, $2, $1, (let (t, t') = $4 in ghexp(Pexp_constraint($6, t, t'))),
- symbol_rloc () }
+ { mkrhs $3 3, $2, $1, (let (t, t') = $4 in ghexp(Pexp_constraint($6, t, t'))) },
;
virtual_method:
METHOD override_flag PRIVATE VIRTUAL label COLON poly_type
{ if $2 = Override then syntax_error ();
- $5, Private, $7, symbol_rloc () }
+ mkloc $5 (rhs_loc 5), Private, $7 }
| METHOD override_flag VIRTUAL private_flag label COLON poly_type
{ if $2 = Override then syntax_error ();
- $5, $4, $7, symbol_rloc () }
+ mkloc $5 (rhs_loc 5), $4, $7 }
;
concrete_method :
METHOD override_flag private_flag label strict_binding
- { $4, $3, $2, ghexp(Pexp_poly ($5, None)), symbol_rloc () }
+ { mkloc $4 (rhs_loc 4), $3, $2, ghexp(Pexp_poly ($5, None)) }
| METHOD override_flag private_flag label COLON poly_type EQUAL seq_expr
- { $4, $3, $2, ghexp(Pexp_poly($8,Some $6)), symbol_rloc () }
+ { mkloc $4 (rhs_loc 4), $3, $2, ghexp(Pexp_poly($8,Some $6)) }
| METHOD override_flag private_flag label COLON TYPE lident_list
DOT core_type EQUAL seq_expr
{ let exp, poly = wrap_type_annotation $7 $9 $11 in
- $4, $3, $2, ghexp(Pexp_poly(exp, Some poly)), symbol_rloc () }
+ mkloc $4 (rhs_loc 4), $3, $2, ghexp(Pexp_poly(exp, Some poly)) }
;
/* Class types */
@@ -794,17 +819,9 @@ class_type:
class_signature
{ $1 }
| QUESTION LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type
- { mkcty(Pcty_fun("?" ^ $2 ,
- {ptyp_desc =
- Ptyp_constr(Ldot (Lident "*predef*", "option"), [$4]);
- ptyp_loc = $4.ptyp_loc},
- $6)) }
+ { mkcty(Pcty_fun("?" ^ $2 , mkoption $4, $6)) }
| OPTLABEL simple_core_type_or_tuple MINUSGREATER class_type
- { mkcty(Pcty_fun("?" ^ $1 ,
- {ptyp_desc =
- Ptyp_constr(Ldot (Lident "*predef*", "option"), [$2]);
- ptyp_loc = $2.ptyp_loc},
- $4)) }
+ { mkcty(Pcty_fun("?" ^ $1, mkoption $2, $4)) }
| LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type
{ mkcty(Pcty_fun($1, $3, $5)) }
| simple_core_type_or_tuple MINUSGREATER class_type
@@ -812,9 +829,9 @@ class_type:
;
class_signature:
LBRACKET core_type_comma_list RBRACKET clty_longident
- { mkcty(Pcty_constr ($4, List.rev $2)) }
+ { mkcty(Pcty_constr (mkloc $4 (rhs_loc 4), List.rev $2)) }
| clty_longident
- { mkcty(Pcty_constr ($1, [])) }
+ { mkcty(Pcty_constr (mkrhs $1 1, [])) }
| OBJECT class_sig_body END
{ mkcty(Pcty_signature $2) }
| OBJECT class_sig_body error
@@ -822,7 +839,8 @@ class_signature:
;
class_sig_body:
class_self_type class_sig_fields
- { $1, List.rev $2 }
+ { { pcsig_self = $1; pcsig_fields = List.rev $2;
+ pcsig_loc = symbol_rloc(); } }
;
class_self_type:
LPAREN core_type RPAREN
@@ -832,32 +850,38 @@ class_self_type:
;
class_sig_fields:
/* empty */ { [] }
- | class_sig_fields INHERIT class_signature { Pctf_inher $3 :: $1 }
- | class_sig_fields VAL value_type { Pctf_val $3 :: $1 }
- | class_sig_fields virtual_method_type { Pctf_virt $2 :: $1 }
- | class_sig_fields method_type { Pctf_meth $2 :: $1 }
- | class_sig_fields CONSTRAINT constrain { Pctf_cstr $3 :: $1 }
+| class_sig_fields class_sig_field { $2 :: $1 }
+;
+class_sig_field:
+ INHERIT class_signature { mkctf (Pctf_inher $2) }
+ | VAL value_type { mkctf (Pctf_val $2) }
+ | virtual_method_type { mkctf (Pctf_virt $1) }
+ | method_type { mkctf (Pctf_meth $1) }
+ | CONSTRAINT constrain_field { mkctf (Pctf_cstr $2) }
;
value_type:
VIRTUAL mutable_flag label COLON core_type
- { $3, $2, Virtual, $5, symbol_rloc () }
+ { $3, $2, Virtual, $5 }
| MUTABLE virtual_flag label COLON core_type
- { $3, Mutable, $2, $5, symbol_rloc () }
+ { $3, Mutable, $2, $5 }
| label COLON core_type
- { $1, Immutable, Concrete, $3, symbol_rloc () }
+ { $1, Immutable, Concrete, $3 }
;
method_type:
METHOD private_flag label COLON poly_type
- { $3, $2, $5, symbol_rloc () }
+ { $3, $2, $5 }
;
virtual_method_type:
METHOD PRIVATE VIRTUAL label COLON poly_type
- { $4, Private, $6, symbol_rloc () }
+ { $4, Private, $6 }
| METHOD VIRTUAL private_flag label COLON poly_type
- { $4, $3, $6, symbol_rloc () }
+ { $4, $3, $6 }
;
constrain:
- core_type EQUAL core_type { $1, $3, symbol_rloc () }
+ core_type EQUAL core_type { $1, $3, symbol_rloc() }
+;
+constrain_field:
+ core_type EQUAL core_type { $1, $3 }
;
class_descriptions:
class_descriptions AND class_description { $3 :: $1 }
@@ -867,7 +891,7 @@ class_description:
virtual_flag class_type_parameters LIDENT COLON class_type
{ let params, variance = List.split (fst $2) in
{pci_virt = $1; pci_params = params, snd $2;
- pci_name = $3; pci_expr = $5; pci_variance = variance;
+ pci_name = mkrhs $3 3; pci_expr = $5; pci_variance = variance;
pci_loc = symbol_rloc ()} }
;
class_type_declarations:
@@ -878,7 +902,7 @@ class_type_declaration:
virtual_flag class_type_parameters LIDENT EQUAL class_signature
{ let params, variance = List.split (fst $2) in
{pci_virt = $1; pci_params = params, snd $2;
- pci_name = $3; pci_expr = $5; pci_variance = variance;
+ pci_name = mkrhs $3 3; pci_expr = $5; pci_variance = variance;
pci_loc = symbol_rloc ()} }
;
@@ -908,7 +932,7 @@ labeled_simple_pattern:
{ ("", None, $1) }
;
pattern_var:
- LIDENT { mkpat(Ppat_var $1) }
+ LIDENT { mkpat(Ppat_var (mkrhs $1 1)) }
| UNDERSCORE { mkpat Ppat_any }
;
opt_default:
@@ -922,7 +946,7 @@ label_let_pattern:
{ let (lab, pat) = $1 in (lab, mkpat(Ppat_constraint(pat, $3))) }
;
label_var:
- LIDENT { ($1, mkpat(Ppat_var $1)) }
+ LIDENT { ($1, mkpat(Ppat_var (mkrhs $1 1))) }
;
let_pattern:
pattern
@@ -938,9 +962,9 @@ expr:
| LET rec_flag let_bindings IN seq_expr
{ mkexp(Pexp_let($2, List.rev $3, $5)) }
| LET MODULE UIDENT module_binding IN seq_expr
- { mkexp(Pexp_letmodule($3, $4, $6)) }
+ { mkexp(Pexp_letmodule(mkrhs $3 3, $4, $6)) }
| LET OPEN mod_longident IN seq_expr
- { mkexp(Pexp_open($3, $5)) }
+ { mkexp(Pexp_open(mkrhs $3 3, $5)) }
| FUNCTION opt_bar match_cases
{ mkexp(Pexp_function("", None, List.rev $3)) }
| FUN labeled_simple_pattern fun_def
@@ -956,7 +980,7 @@ expr:
| expr_comma_list %prec below_COMMA
{ mkexp(Pexp_tuple(List.rev $1)) }
| constr_longident simple_expr %prec below_SHARP
- { mkexp(Pexp_construct($1, Some $2, false)) }
+ { mkexp(Pexp_construct(mkrhs $1 1, Some $2, false)) }
| name_tag simple_expr %prec below_SHARP
{ mkexp(Pexp_variant($1, Some $2)) }
| IF seq_expr THEN expr ELSE expr
@@ -966,15 +990,11 @@ expr:
| WHILE seq_expr DO seq_expr DONE
{ mkexp(Pexp_while($2, $4)) }
| FOR val_ident EQUAL seq_expr direction_flag seq_expr DO seq_expr DONE
- { mkexp(Pexp_for($2, $4, $6, $5, $8)) }
+ { mkexp(Pexp_for(mkrhs $2 2, $4, $6, $5, $8)) }
| expr COLONCOLON expr
- { mkexp(Pexp_construct(Lident "::",
- Some(ghexp(Pexp_tuple[$1;$3])),
- false)) }
+ { mkexp_cons (ghexp(Pexp_tuple[$1;$3])) (symbol_rloc()) }
| LPAREN COLONCOLON RPAREN LPAREN expr COMMA expr RPAREN
- { mkexp(Pexp_construct(Lident "::",
- Some(ghexp(Pexp_tuple[$5;$7])),
- false)) }
+ { mkexp_cons (ghexp(Pexp_tuple[$5;$7])) (symbol_rloc()) }
| expr INFIXOP0 expr
{ mkinfix $1 $2 $3 }
| expr INFIXOP1 expr
@@ -1016,7 +1036,7 @@ expr:
| additive expr %prec prec_unary_plus
{ mkuplus $1 $2 }
| simple_expr DOT label_longident LESSMINUS expr
- { mkexp(Pexp_setfield($1, $3, $5)) }
+ { mkexp(Pexp_setfield($1, mkrhs $3 3, $5)) }
| simple_expr DOT LPAREN seq_expr RPAREN LESSMINUS expr
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "set")),
["",$1; "",$4; "",$7])) }
@@ -1026,7 +1046,7 @@ expr:
| simple_expr DOT LBRACE expr RBRACE LESSMINUS expr
{ bigarray_set $1 $4 $7 }
| label LESSMINUS expr
- { mkexp(Pexp_setinstvar($1, $3)) }
+ { mkexp(Pexp_setinstvar(mkrhs $1 1, $3)) }
| ASSERT simple_expr %prec below_SHARP
{ mkassert $2 }
| LAZY simple_expr %prec below_SHARP
@@ -1038,11 +1058,11 @@ expr:
;
simple_expr:
val_longident
- { mkexp(Pexp_ident $1) }
+ { mkexp(Pexp_ident (mkrhs $1 1)) }
| constant
{ mkexp(Pexp_constant $1) }
| constr_longident %prec prec_constant_constructor
- { mkexp(Pexp_construct($1, None, false)) }
+ { mkexp(Pexp_construct(mkrhs $1 1, None, false)) }
| name_tag %prec prec_constant_constructor
{ mkexp(Pexp_variant($1, None)) }
| LPAREN seq_expr RPAREN
@@ -1052,15 +1072,15 @@ simple_expr:
| BEGIN seq_expr END
{ reloc_exp $2 }
| BEGIN END
- { mkexp (Pexp_construct (Lident "()", None, false)) }
+ { mkexp (Pexp_construct (mkloc (Lident "()") (symbol_rloc ()), None, false)) }
| BEGIN seq_expr error
{ unclosed "begin" 1 "end" 3 }
| LPAREN seq_expr type_constraint RPAREN
{ let (t, t') = $3 in mkexp(Pexp_constraint($2, t, t')) }
| simple_expr DOT label_longident
- { mkexp(Pexp_field($1, $3)) }
+ { mkexp(Pexp_field($1, mkrhs $3 3)) }
| mod_longident DOT LPAREN seq_expr RPAREN
- { mkexp(Pexp_open($1, $4)) }
+ { mkexp(Pexp_open(mkrhs $1 1, $4)) }
| mod_longident DOT LPAREN seq_expr error
{ unclosed "(" 3 ")" 5 }
| simple_expr DOT LPAREN seq_expr RPAREN
@@ -1096,7 +1116,7 @@ simple_expr:
| BANG simple_expr
{ mkexp(Pexp_apply(mkoperator "!" 1, ["",$2])) }
| NEW class_longident
- { mkexp(Pexp_new($2)) }
+ { mkexp(Pexp_new(mkrhs $2 2)) }
| LBRACELESS field_expr_list opt_semi GREATERRBRACE
{ mkexp(Pexp_override(List.rev $2)) }
| LBRACELESS field_expr_list opt_semi error
@@ -1136,7 +1156,7 @@ label_expr:
{ ("?" ^ $1, $2) }
;
label_ident:
- LIDENT { ($1, mkexp(Pexp_ident(Lident $1))) }
+ LIDENT { ($1, mkexp(Pexp_ident(mkrhs (Lident $1) 1))) }
;
let_bindings:
let_binding { [$1] }
@@ -1197,19 +1217,19 @@ record_expr:
;
lbl_expr_list:
label_longident EQUAL expr
- { [$1,$3] }
+ { [mkrhs $1 1,$3] }
| label_longident
- { [$1, exp_of_label $1] }
+ { [mkrhs $1 1, exp_of_label $1 1] }
| lbl_expr_list SEMI label_longident EQUAL expr
- { ($3, $5) :: $1 }
+ { (mkrhs $3 3, $5) :: $1 }
| lbl_expr_list SEMI label_longident
- { ($3, exp_of_label $3) :: $1 }
+ { (mkrhs $3 3, exp_of_label $3 3) :: $1 }
;
field_expr_list:
label EQUAL expr
- { [$1,$3] }
+ { [mkrhs $1 1,$3] }
| field_expr_list SEMI label EQUAL expr
- { ($3, $5) :: $1 }
+ { (mkrhs $3 3, $5) :: $1 }
;
expr_semi_list:
expr { [$1] }
@@ -1229,19 +1249,17 @@ pattern:
simple_pattern
{ $1 }
| pattern AS val_ident
- { mkpat(Ppat_alias($1, $3)) }
+ { mkpat(Ppat_alias($1, mkrhs $3 3)) }
| pattern_comma_list %prec below_COMMA
{ mkpat(Ppat_tuple(List.rev $1)) }
| constr_longident pattern %prec prec_constr_appl
- { mkpat(Ppat_construct($1, Some $2, false)) }
+ { mkpat(Ppat_construct(mkrhs $1 1, Some $2, false)) }
| name_tag pattern %prec prec_constr_appl
{ mkpat(Ppat_variant($1, Some $2)) }
| pattern COLONCOLON pattern
- { mkpat(Ppat_construct(Lident "::", Some(ghpat(Ppat_tuple[$1;$3])),
- false)) }
+ { mkpat_cons (ghpat(Ppat_tuple[$1;$3])) (symbol_rloc()) },
| LPAREN COLONCOLON RPAREN LPAREN pattern COMMA pattern RPAREN
- { mkpat(Ppat_construct(Lident "::", Some(ghpat(Ppat_tuple[$5;$7])),
- false)) }
+ { mkpat_cons (ghpat(Ppat_tuple[$5;$7])) (symbol_rloc()) }
| pattern BAR pattern
{ mkpat(Ppat_or($1, $3)) }
| LAZY simple_pattern
@@ -1249,7 +1267,7 @@ pattern:
;
simple_pattern:
val_ident %prec below_EQUAL
- { mkpat(Ppat_var $1) }
+ { mkpat(Ppat_var (mkrhs $1 1)) }
| UNDERSCORE
{ mkpat(Ppat_any) }
| signed_constant
@@ -1257,11 +1275,11 @@ simple_pattern:
| CHAR DOTDOT CHAR
{ mkrangepat $1 $3 }
| constr_longident
- { mkpat(Ppat_construct($1, None, false)) }
+ { mkpat(Ppat_construct(mkrhs $1 1, None, false)) }
| name_tag
{ mkpat(Ppat_variant($1, None)) }
| SHARP type_longident
- { mkpat(Ppat_type $2) }
+ { mkpat(Ppat_type (mkrhs $2 2)) }
| LBRACE lbl_pattern_list record_pattern_end RBRACE
{ mkpat(Ppat_record(List.rev $2, $3)) }
| LBRACE lbl_pattern_list opt_semi error
@@ -1285,9 +1303,9 @@ simple_pattern:
| LPAREN pattern COLON core_type error
{ unclosed "(" 1 ")" 5 }
| LPAREN MODULE UIDENT RPAREN
- { mkpat(Ppat_unpack $3) }
+ { mkpat(Ppat_unpack (mkrhs $3 3)) }
| LPAREN MODULE UIDENT COLON package_type RPAREN
- { mkpat(Ppat_constraint(mkpat(Ppat_unpack $3),ghtyp(Ptyp_package $5))) }
+ { mkpat(Ppat_constraint(mkpat(Ppat_unpack (mkrhs $3 3)),ghtyp(Ptyp_package $5))) }
| LPAREN MODULE UIDENT COLON package_type error
{ unclosed "(" 1 ")" 6 }
;
@@ -1301,10 +1319,10 @@ pattern_semi_list:
| pattern_semi_list SEMI pattern { $3 :: $1 }
;
lbl_pattern_list:
- label_longident EQUAL pattern { [($1, $3)] }
- | label_longident { [($1, pat_of_label $1)] }
- | lbl_pattern_list SEMI label_longident EQUAL pattern { ($3, $5) :: $1 }
- | lbl_pattern_list SEMI label_longident { ($3, pat_of_label $3) :: $1 }
+ label_longident EQUAL pattern { [(mkrhs $1 1, $3)] }
+ | label_longident { [(mkrhs $1 1, pat_of_label $1 1)] }
+ | lbl_pattern_list SEMI label_longident EQUAL pattern { (mkrhs $3 3, $5) :: $1 }
+ | lbl_pattern_list SEMI label_longident { (mkrhs $3 3, pat_of_label $3 3) :: $1 }
;
record_pattern_end:
opt_semi { Closed }
@@ -1329,7 +1347,7 @@ type_declaration:
optional_type_parameters LIDENT type_kind constraints
{ let (params, variance) = List.split $1 in
let (kind, private_flag, manifest) = $3 in
- ($2, {ptype_params = params;
+ (mkrhs $2 2, {ptype_params = params;
ptype_cstrs = List.rev $4;
ptype_kind = kind;
ptype_private = private_flag;
@@ -1367,7 +1385,7 @@ optional_type_parameters:
| LPAREN optional_type_parameter_list RPAREN { List.rev $2 }
;
optional_type_parameter:
- type_variance QUOTE ident { Some $3, $1 }
+ type_variance QUOTE ident { Some (mkrhs $3 3), $1 }
| type_variance UNDERSCORE { None, $1 }
;
optional_type_parameter_list:
@@ -1383,7 +1401,7 @@ type_parameters:
| LPAREN type_parameter_list RPAREN { List.rev $2 }
;
type_parameter:
- type_variance QUOTE ident { $3, $1 }
+ type_variance QUOTE ident { mkrhs $3 3, $1 }
;
type_variance:
/* empty */ { false, false }
@@ -1402,7 +1420,7 @@ constructor_declaration:
| constr_ident generalized_constructor_arguments
{ let arg_types,ret_type = $2 in
- ($1, arg_types,ret_type, symbol_rloc()) }
+ (mkrhs $1 1, arg_types,ret_type, symbol_rloc()) }
;
constructor_arguments:
@@ -1425,7 +1443,7 @@ label_declarations:
| label_declarations SEMI label_declaration { $3 :: $1 }
;
label_declaration:
- mutable_flag label COLON poly_type { ($2, $1, $4, symbol_rloc()) }
+ mutable_flag label COLON poly_type { (mkrhs $2 2, $1, $4, symbol_rloc()) }
;
/* "with" constraints (additional type equations over signature components) */
@@ -1437,7 +1455,7 @@ with_constraints:
with_constraint:
TYPE type_parameters label_longident with_type_binder core_type constraints
{ let params, variance = List.split $2 in
- ($3, Pwith_type {ptype_params = List.map (fun x -> Some x) params;
+ (mkrhs $3 3, Pwith_type {ptype_params = List.map (fun x -> Some x) params;
ptype_cstrs = List.rev $6;
ptype_kind = Ptype_abstract;
ptype_manifest = Some $5;
@@ -1448,7 +1466,7 @@ with_constraint:
functor applications in type path */
| TYPE type_parameters label_longident COLONEQUAL core_type
{ let params, variance = List.split $2 in
- ($3, Pwith_typesubst {ptype_params = List.map (fun x -> Some x) params;
+ (mkrhs $3 3, Pwith_typesubst {ptype_params = List.map (fun x -> Some x) params;
ptype_cstrs = [];
ptype_kind = Ptype_abstract;
ptype_manifest = Some $5;
@@ -1456,9 +1474,9 @@ with_constraint:
ptype_variance = variance;
ptype_loc = symbol_rloc()}) }
| MODULE mod_longident EQUAL mod_ext_longident
- { ($2, Pwith_module $4) }
+ { (mkrhs $2 2, Pwith_module (mkrhs $4 4)) }
| MODULE mod_longident COLONEQUAL mod_ext_longident
- { ($2, Pwith_modsubst $4) }
+ { (mkrhs $2 2, Pwith_modsubst (mkrhs $4 4)) }
;
with_type_binder:
EQUAL { Public }
@@ -1490,13 +1508,9 @@ core_type2:
simple_core_type_or_tuple
{ $1 }
| QUESTION LIDENT COLON core_type2 MINUSGREATER core_type2
- { mktyp(Ptyp_arrow("?" ^ $2 ,
- {ptyp_desc = Ptyp_constr(Ldot (Lident "*predef*", "option"), [$4]);
- ptyp_loc = $4.ptyp_loc}, $6)) }
+ { mktyp(Ptyp_arrow("?" ^ $2 , mkoption $4, $6)) }
| OPTLABEL core_type2 MINUSGREATER core_type2
- { mktyp(Ptyp_arrow("?" ^ $1 ,
- {ptyp_desc = Ptyp_constr(Ldot (Lident "*predef*", "option"), [$2]);
- ptyp_loc = $2.ptyp_loc}, $4)) }
+ { mktyp(Ptyp_arrow("?" ^ $1 , mkoption $2, $4)) }
| LIDENT COLON core_type2 MINUSGREATER core_type2
{ mktyp(Ptyp_arrow($1, $3, $5)) }
| core_type2 MINUSGREATER core_type2
@@ -1515,21 +1529,21 @@ simple_core_type2:
| UNDERSCORE
{ mktyp(Ptyp_any) }
| type_longident
- { mktyp(Ptyp_constr($1, [])) }
+ { mktyp(Ptyp_constr(mkrhs $1 1, [])) }
| simple_core_type2 type_longident
- { mktyp(Ptyp_constr($2, [$1])) }
+ { mktyp(Ptyp_constr(mkrhs $2 2, [$1])) }
| LPAREN core_type_comma_list RPAREN type_longident
- { mktyp(Ptyp_constr($4, List.rev $2)) }
+ { mktyp(Ptyp_constr(mkrhs $4 4, List.rev $2)) }
| LESS meth_list GREATER
{ mktyp(Ptyp_object $2) }
| LESS GREATER
{ mktyp(Ptyp_object []) }
| SHARP class_longident opt_present
- { mktyp(Ptyp_class($2, [], $3)) }
+ { mktyp(Ptyp_class(mkrhs $2 2, [], $3)) }
| simple_core_type2 SHARP class_longident opt_present
- { mktyp(Ptyp_class($3, [$1], $4)) }
+ { mktyp(Ptyp_class(mkrhs $3 3, [$1], $4)) }
| LPAREN core_type_comma_list RPAREN SHARP class_longident opt_present
- { mktyp(Ptyp_class($5, List.rev $2, $6)) }
+ { mktyp(Ptyp_class(mkrhs $5 5, List.rev $2, $6)) }
| LBRACKET tag_field RBRACKET
{ mktyp(Ptyp_variant([$2], true, None)) }
/* PR#3835: this is not LR(1), would need lookahead=2
@@ -1552,11 +1566,11 @@ simple_core_type2:
{ mktyp(Ptyp_package $3) }
;
package_type:
- mty_longident { ($1, []) }
- | mty_longident WITH package_type_cstrs { ($1, $3) }
+ mty_longident { (mkrhs $1 1, []) }
+ | mty_longident WITH package_type_cstrs { (mkrhs $1 1, $3) }
;
package_type_cstr:
- TYPE label_longident EQUAL core_type { ($2, $4) }
+ TYPE label_longident EQUAL core_type { (mkrhs $2 2, $4) }
;
package_type_cstrs:
package_type_cstr { [$1] }
@@ -1724,6 +1738,14 @@ class_longident:
LIDENT { Lident $1 }
| mod_longident DOT LIDENT { Ldot($1, $3) }
;
+any_longident:
+ val_ident { Lident $1 }
+ | mod_ext_longident DOT val_ident { Ldot ($1, $3) }
+ | mod_ext_longident { $1 }
+ | LBRACKET RBRACKET { Lident "[]" }
+ | LPAREN RPAREN { Lident "()" }
+ | FALSE { Lident "false" }
+ | TRUE { Lident "true" }
/* Toplevel directives */
diff --git a/parsing/parsetree.mli b/parsing/parsetree.mli
index 663ae7c55..eeca81acf 100644
--- a/parsing/parsetree.mli
+++ b/parsing/parsetree.mli
@@ -27,15 +27,16 @@ and core_type_desc =
| Ptyp_var of string
| Ptyp_arrow of label * core_type * core_type
| Ptyp_tuple of core_type list
- | Ptyp_constr of Longident.t * core_type list
+ | Ptyp_constr of Longident.t loc * core_type list
| Ptyp_object of core_field_type list
- | Ptyp_class of Longident.t * core_type list * label list
+ | Ptyp_class of Longident.t loc * core_type list * label list
| Ptyp_alias of core_type * string
| Ptyp_variant of row_field list * bool * label list option
| Ptyp_poly of string list * core_type
| Ptyp_package of package_type
-and package_type = Longident.t * (Longident.t * core_type) list
+
+and package_type = Longident.t loc * (Longident.t loc * core_type) list
and core_field_type =
{ pfield_desc: core_field_desc;
@@ -53,8 +54,8 @@ and row_field =
type 'a class_infos =
{ pci_virt: virtual_flag;
- pci_params: string list * Location.t;
- pci_name: string;
+ pci_params: string loc list * Location.t;
+ pci_name: string loc;
pci_expr: 'a;
pci_variance: (bool * bool) list;
pci_loc: Location.t }
@@ -67,26 +68,26 @@ type pattern =
and pattern_desc =
Ppat_any
- | Ppat_var of string
- | Ppat_alias of pattern * string
+ | Ppat_var of string loc
+ | Ppat_alias of pattern * string loc
| Ppat_constant of constant
| Ppat_tuple of pattern list
- | Ppat_construct of Longident.t * pattern option * bool
+ | Ppat_construct of Longident.t loc * pattern option * bool
| Ppat_variant of label * pattern option
- | Ppat_record of (Longident.t * pattern) list * closed_flag
+ | Ppat_record of (Longident.t loc * pattern) list * closed_flag
| Ppat_array of pattern list
| Ppat_or of pattern * pattern
| Ppat_constraint of pattern * core_type
- | Ppat_type of Longident.t
+ | Ppat_type of Longident.t loc
| Ppat_lazy of pattern
- | Ppat_unpack of string
+ | Ppat_unpack of string loc
type expression =
{ pexp_desc: expression_desc;
pexp_loc: Location.t }
and expression_desc =
- Pexp_ident of Longident.t
+ Pexp_ident of Longident.t loc
| Pexp_constant of constant
| Pexp_let of rec_flag * (pattern * expression) list * expression
| Pexp_function of label * expression option * (pattern * expression) list
@@ -94,23 +95,23 @@ and expression_desc =
| Pexp_match of expression * (pattern * expression) list
| Pexp_try of expression * (pattern * expression) list
| Pexp_tuple of expression list
- | Pexp_construct of Longident.t * expression option * bool
+ | Pexp_construct of Longident.t loc * expression option * bool
| Pexp_variant of label * expression option
- | Pexp_record of (Longident.t * expression) list * expression option
- | Pexp_field of expression * Longident.t
- | Pexp_setfield of expression * Longident.t * expression
+ | Pexp_record of (Longident.t loc * expression) list * expression option
+ | Pexp_field of expression * Longident.t loc
+ | Pexp_setfield of expression * Longident.t loc * expression
| Pexp_array of expression list
| Pexp_ifthenelse of expression * expression * expression option
| Pexp_sequence of expression * expression
| Pexp_while of expression * expression
- | Pexp_for of string * expression * expression * direction_flag * expression
+ | Pexp_for of string loc * expression * expression * direction_flag * expression
| Pexp_constraint of expression * core_type option * core_type option
| Pexp_when of expression * expression
| Pexp_send of expression * string
- | Pexp_new of Longident.t
- | Pexp_setinstvar of string * expression
- | Pexp_override of (string * expression) list
- | Pexp_letmodule of string * module_expr * expression
+ | Pexp_new of Longident.t loc
+ | Pexp_setinstvar of string loc * expression
+ | Pexp_override of (string loc * expression) list
+ | Pexp_letmodule of string loc * module_expr * expression
| Pexp_assert of expression
| Pexp_assertfalse
| Pexp_lazy of expression
@@ -118,18 +119,20 @@ and expression_desc =
| Pexp_object of class_structure
| Pexp_newtype of string * expression
| Pexp_pack of module_expr
- | Pexp_open of Longident.t * expression
+ | Pexp_open of Longident.t loc * expression
(* Value descriptions *)
and value_description =
{ pval_type: core_type;
- pval_prim: string list }
+ pval_prim: string list;
+ pval_loc : Location.t
+ }
(* Type declarations *)
and type_declaration =
- { ptype_params: string option list;
+ { ptype_params: string loc option list;
ptype_cstrs: (core_type * core_type * Location.t) list;
ptype_kind: type_kind;
ptype_private: private_flag;
@@ -140,9 +143,9 @@ and type_declaration =
and type_kind =
Ptype_abstract
| Ptype_variant of
- (string * core_type list * core_type option * Location.t) list
+ (string loc * core_type list * core_type option * Location.t) list
| Ptype_record of
- (string * mutable_flag * core_type * Location.t) list
+ (string loc * mutable_flag * core_type * Location.t) list
and exception_declaration = core_type list
@@ -153,18 +156,27 @@ and class_type =
pcty_loc: Location.t }
and class_type_desc =
- Pcty_constr of Longident.t * core_type list
+ Pcty_constr of Longident.t loc * core_type list
| Pcty_signature of class_signature
| Pcty_fun of label * core_type * class_type
-and class_signature = core_type * class_type_field list
+and class_signature = {
+ pcsig_self : core_type;
+ pcsig_fields : class_type_field list;
+ pcsig_loc : Location.t;
+ }
+
+and class_type_field = {
+ pctf_desc : class_type_field_desc;
+ pctf_loc : Location.t;
+ }
-and class_type_field =
+and class_type_field_desc =
Pctf_inher of class_type
- | Pctf_val of (string * mutable_flag * virtual_flag * core_type * Location.t)
- | Pctf_virt of (string * private_flag * core_type * Location.t)
- | Pctf_meth of (string * private_flag * core_type * Location.t)
- | Pctf_cstr of (core_type * core_type * Location.t)
+ | Pctf_val of (string * mutable_flag * virtual_flag * core_type)
+ | Pctf_virt of (string * private_flag * core_type)
+ | Pctf_meth of (string * private_flag * core_type)
+ | Pctf_cstr of (core_type * core_type)
and class_description = class_type class_infos
@@ -177,25 +189,31 @@ and class_expr =
pcl_loc: Location.t }
and class_expr_desc =
- Pcl_constr of Longident.t * core_type list
+ Pcl_constr of Longident.t loc * core_type list
| Pcl_structure of class_structure
| Pcl_fun of label * expression option * pattern * class_expr
| Pcl_apply of class_expr * (label * expression) list
| Pcl_let of rec_flag * (pattern * expression) list * class_expr
| Pcl_constraint of class_expr * class_type
-and class_structure = pattern * class_field list
+and class_structure = {
+ pcstr_pat : pattern;
+ pcstr_fields : class_field list;
+ }
+
+and class_field = {
+ pcf_desc : class_field_desc;
+ pcf_loc : Location.t;
+ }
-and class_field =
+and class_field_desc =
Pcf_inher of override_flag * class_expr * string option
- | Pcf_valvirt of (string * mutable_flag * core_type * Location.t)
- | Pcf_val of
- (string * mutable_flag * override_flag * expression * Location.t)
- | Pcf_virt of (string * private_flag * core_type * Location.t)
- | Pcf_meth of
- (string * private_flag * override_flag * expression * Location.t)
- | Pcf_cstr of (core_type * core_type * Location.t)
- | Pcf_init of expression
+ | Pcf_valvirt of (string loc * mutable_flag * core_type)
+ | Pcf_val of (string loc * mutable_flag * override_flag * expression)
+ | Pcf_virt of (string loc * private_flag * core_type)
+ | Pcf_meth of (string loc * private_flag *override_flag * expression)
+ | Pcf_constr of (core_type * core_type)
+ | Pcf_init of expression
and class_declaration = class_expr class_infos
@@ -206,10 +224,10 @@ and module_type =
pmty_loc: Location.t }
and module_type_desc =
- Pmty_ident of Longident.t
+ Pmty_ident of Longident.t loc
| Pmty_signature of signature
- | Pmty_functor of string * module_type * module_type
- | Pmty_with of module_type * (Longident.t * with_constraint) list
+ | Pmty_functor of string loc * module_type * module_type
+ | Pmty_with of module_type * (Longident.t loc * with_constraint) list
| Pmty_typeof of module_expr
and signature = signature_item list
@@ -219,13 +237,13 @@ and signature_item =
psig_loc: Location.t }
and signature_item_desc =
- Psig_value of string * value_description
- | Psig_type of (string * type_declaration) list
- | Psig_exception of string * exception_declaration
- | Psig_module of string * module_type
- | Psig_recmodule of (string * module_type) list
- | Psig_modtype of string * modtype_declaration
- | Psig_open of Longident.t
+ Psig_value of string loc * value_description
+ | Psig_type of (string loc * type_declaration) list
+ | Psig_exception of string loc * exception_declaration
+ | Psig_module of string loc * module_type
+ | Psig_recmodule of (string loc * module_type) list
+ | Psig_modtype of string loc * modtype_declaration
+ | Psig_open of Longident.t loc
| Psig_include of module_type
| Psig_class of class_description list
| Psig_class_type of class_type_declaration list
@@ -236,9 +254,9 @@ and modtype_declaration =
and with_constraint =
Pwith_type of type_declaration
- | Pwith_module of Longident.t
+ | Pwith_module of Longident.t loc
| Pwith_typesubst of type_declaration
- | Pwith_modsubst of Longident.t
+ | Pwith_modsubst of Longident.t loc
(* Value expressions for the module language *)
@@ -247,9 +265,9 @@ and module_expr =
pmod_loc: Location.t }
and module_expr_desc =
- Pmod_ident of Longident.t
+ Pmod_ident of Longident.t loc
| Pmod_structure of structure
- | Pmod_functor of string * module_type * module_expr
+ | Pmod_functor of string loc * module_type * module_expr
| Pmod_apply of module_expr * module_expr
| Pmod_constraint of module_expr * module_type
| Pmod_unpack of expression
@@ -263,14 +281,14 @@ and structure_item =
and structure_item_desc =
Pstr_eval of expression
| Pstr_value of rec_flag * (pattern * expression) list
- | Pstr_primitive of string * value_description
- | Pstr_type of (string * type_declaration) list
- | Pstr_exception of string * exception_declaration
- | Pstr_exn_rebind of string * Longident.t
- | Pstr_module of string * module_expr
- | Pstr_recmodule of (string * module_type * module_expr) list
- | Pstr_modtype of string * module_type
- | Pstr_open of Longident.t
+ | Pstr_primitive of string loc * value_description
+ | Pstr_type of (string loc * type_declaration) list
+ | Pstr_exception of string loc * exception_declaration
+ | Pstr_exn_rebind of string loc * Longident.t loc
+ | Pstr_module of string loc * module_expr
+ | Pstr_recmodule of (string loc * module_type * module_expr) list
+ | Pstr_modtype of string loc * module_type
+ | Pstr_open of Longident.t loc
| Pstr_class of class_declaration list
| Pstr_class_type of class_type_declaration list
| Pstr_include of module_expr
diff --git a/parsing/printast.ml b/parsing/printast.ml
index d5b993311..e3d5b018f 100644
--- a/parsing/printast.ml
+++ b/parsing/printast.ml
@@ -38,7 +38,8 @@ let rec fmt_longident_aux f x =
fprintf f "%a(%a)" fmt_longident_aux y fmt_longident_aux z;
;;
-let fmt_longident f x = fprintf f "\"%a\"" fmt_longident_aux x;;
+let fmt_longident_noloc f x = fprintf f "\"%a\"" fmt_longident_aux x;;
+let fmt_longident f x = fprintf f "\"%a\"" fmt_longident_aux x.txt;;
let fmt_constant f x =
match x with
@@ -112,6 +113,7 @@ let option i f ppf x =
let longident i ppf li = line i ppf "%a\n" fmt_longident li;;
let string i ppf s = line i ppf "\"%s\"\n" s;;
+let string_loc i ppf s = line i ppf "\"%s\"\n" s.txt;;
let bool i ppf x = line i ppf "%s\n" (string_of_bool x);;
let label i ppf x = line i ppf "label=\"%s\"\n" x;;
@@ -172,9 +174,9 @@ and pattern i ppf x =
let i = i+1 in
match x.ppat_desc with
| Ppat_any -> line i ppf "Ppat_any\n";
- | Ppat_var (s) -> line i ppf "Ppat_var \"%s\"\n" s;
+ | Ppat_var (s) -> line i ppf "Ppat_var \"%s\"\n" s.txt;
| Ppat_alias (p, s) ->
- line i ppf "Ppat_alias \"%s\"\n" s;
+ line i ppf "Ppat_alias \"%s\"\n" s.txt;
pattern i ppf p;
| Ppat_constant (c) -> line i ppf "Ppat_constant %a\n" fmt_constant c;
| Ppat_tuple (l) ->
@@ -204,11 +206,11 @@ and pattern i ppf x =
line i ppf "Ppat_constraint";
pattern i ppf p;
core_type i ppf ct;
- | Ppat_type li ->
+ | Ppat_type (li) ->
line i ppf "Ppat_type";
longident i ppf li
| Ppat_unpack s ->
- line i ppf "Ppat_unpack \"%s\"\n" s;
+ line i ppf "Ppat_unpack \"%s\"\n" s.txt;
and expression i ppf x =
line i ppf "expression %a\n" fmt_location x.pexp_loc;
@@ -276,7 +278,7 @@ and expression i ppf x =
expression i ppf e1;
expression i ppf e2;
| Pexp_for (s, e1, e2, df, e3) ->
- line i ppf "Pexp_for \"%s\" %a\n" s fmt_direction_flag df;
+ line i ppf "Pexp_for \"%s\" %a\n" s.txt fmt_direction_flag df;
expression i ppf e1;
expression i ppf e2;
expression i ppf e3;
@@ -294,13 +296,13 @@ and expression i ppf x =
expression i ppf e;
| Pexp_new (li) -> line i ppf "Pexp_new %a\n" fmt_longident li;
| Pexp_setinstvar (s, e) ->
- line i ppf "Pexp_setinstvar \"%s\"\n" s;
+ line i ppf "Pexp_setinstvar \"%s\"\n" s.txt;
expression i ppf e;
| Pexp_override (l) ->
line i ppf "Pexp_override\n";
list i string_x_expression ppf l;
| Pexp_letmodule (s, me, e) ->
- line i ppf "Pexp_letmodule \"%s\"\n" s;
+ line i ppf "Pexp_letmodule \"%s\"\n" s.txt;
module_expr i ppf me;
expression i ppf e;
| Pexp_assert (e) ->
@@ -333,10 +335,10 @@ and value_description i ppf x =
core_type (i+1) ppf x.pval_type;
list (i+1) string ppf x.pval_prim;
-and string_option_underscore i ppf =
+and string_option_underscore i ppf =
function
| Some x ->
- string i ppf x
+ string i ppf x.txt
| None ->
string i ppf "_"
@@ -381,30 +383,31 @@ and class_type i ppf x =
core_type i ppf co;
class_type i ppf cl;
-and class_signature i ppf (ct, l) =
+and class_signature i ppf { pcsig_self = ct; pcsig_fields = l } =
line i ppf "class_signature\n";
core_type (i+1) ppf ct;
list (i+1) class_type_field ppf l;
and class_type_field i ppf x =
- match x with
+ let loc = x.pctf_loc in
+ match x.pctf_desc with
| Pctf_inher (ct) ->
line i ppf "Pctf_inher\n";
class_type i ppf ct;
- | Pctf_val (s, mf, vf, ct, loc) ->
+ | Pctf_val (s, mf, vf, ct) ->
line i ppf
"Pctf_val \"%s\" %a %a %a\n" s
fmt_mutable_flag mf fmt_virtual_flag vf fmt_location loc;
core_type (i+1) ppf ct;
- | Pctf_virt (s, pf, ct, loc) ->
+ | Pctf_virt (s, pf, ct) ->
line i ppf
"Pctf_virt \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc;
core_type (i+1) ppf ct;
- | Pctf_meth (s, pf, ct, loc) ->
+ | Pctf_meth (s, pf, ct) ->
line i ppf
"Pctf_meth \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc;
core_type (i+1) ppf ct;
- | Pctf_cstr (ct1, ct2, loc) ->
+ | Pctf_cstr (ct1, ct2) ->
line i ppf "Pctf_cstr %a\n" fmt_location loc;
core_type i ppf ct1;
core_type i ppf ct2;
@@ -415,7 +418,7 @@ and class_description i ppf x =
line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt;
line i ppf "pci_params =\n";
string_list_x_location (i+1) ppf x.pci_params;
- line i ppf "pci_name = \"%s\"\n" x.pci_name;
+ line i ppf "pci_name = \"%s\"\n" x.pci_name.txt;
line i ppf "pci_expr =\n";
class_type (i+1) ppf x.pci_expr;
@@ -425,7 +428,7 @@ and class_type_declaration i ppf x =
line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt;
line i ppf "pci_params =\n";
string_list_x_location (i+1) ppf x.pci_params;
- line i ppf "pci_name = \"%s\"\n" x.pci_name;
+ line i ppf "pci_name = \"%s\"\n" x.pci_name.txt;
line i ppf "pci_expr =\n";
class_type (i+1) ppf x.pci_expr;
@@ -458,35 +461,36 @@ and class_expr i ppf x =
class_expr i ppf ce;
class_type i ppf ct;
-and class_structure i ppf (p, l) =
+and class_structure i ppf { pcstr_pat = p; pcstr_fields = l } =
line i ppf "class_structure\n";
pattern (i+1) ppf p;
list (i+1) class_field ppf l;
and class_field i ppf x =
- match x with
+ let loc = x.pcf_loc in
+ match x.pcf_desc with
| Pcf_inher (ovf, ce, so) ->
line i ppf "Pcf_inher %a\n" fmt_override_flag ovf;
class_expr (i+1) ppf ce;
option (i+1) string ppf so;
- | Pcf_valvirt (s, mf, ct, loc) ->
+ | Pcf_valvirt (s, mf, ct) ->
line i ppf "Pcf_valvirt \"%s\" %a %a\n"
- s fmt_mutable_flag mf fmt_location loc;
+ s.txt fmt_mutable_flag mf fmt_location loc;
core_type (i+1) ppf ct;
- | Pcf_val (s, mf, ovf, e, loc) ->
+ | Pcf_val (s, mf, ovf, e) ->
line i ppf "Pcf_val \"%s\" %a %a %a\n"
- s fmt_mutable_flag mf fmt_override_flag ovf fmt_location loc;
+ s.txt fmt_mutable_flag mf fmt_override_flag ovf fmt_location loc;
expression (i+1) ppf e;
- | Pcf_virt (s, pf, ct, loc) ->
+ | Pcf_virt (s, pf, ct) ->
line i ppf "Pcf_virt \"%s\" %a %a\n"
- s fmt_private_flag pf fmt_location loc;
+ s.txt fmt_private_flag pf fmt_location loc;
core_type (i+1) ppf ct;
- | Pcf_meth (s, pf, ovf, e, loc) ->
+ | Pcf_meth (s, pf, ovf, e) ->
line i ppf "Pcf_meth \"%s\" %a %a %a\n"
- s fmt_private_flag pf fmt_override_flag ovf fmt_location loc;
+ s.txt fmt_private_flag pf fmt_override_flag ovf fmt_location loc;
expression (i+1) ppf e;
- | Pcf_cstr (ct1, ct2, loc) ->
- line i ppf "Pcf_cstr %a\n" fmt_location loc;
+ | Pcf_constr (ct1, ct2) ->
+ line i ppf "Pcf_constr %a\n" fmt_location loc;
core_type (i+1) ppf ct1;
core_type (i+1) ppf ct2;
| Pcf_init (e) ->
@@ -499,7 +503,7 @@ and class_declaration i ppf x =
line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt;
line i ppf "pci_params =\n";
string_list_x_location (i+1) ppf x.pci_params;
- line i ppf "pci_name = \"%s\"\n" x.pci_name;
+ line i ppf "pci_name = \"%s\"\n" x.pci_name.txt;
line i ppf "pci_expr =\n";
class_expr (i+1) ppf x.pci_expr;
@@ -507,12 +511,12 @@ and module_type i ppf x =
line i ppf "module_type %a\n" fmt_location x.pmty_loc;
let i = i+1 in
match x.pmty_desc with
- | Pmty_ident (li) -> line i ppf "Pmty_ident %a\n" fmt_longident li;
+ | Pmty_ident li -> line i ppf "Pmty_ident %a\n" fmt_longident li;
| Pmty_signature (s) ->
line i ppf "Pmty_signature\n";
signature i ppf s;
| Pmty_functor (s, mt1, mt2) ->
- line i ppf "Pmty_functor \"%s\"\n" s;
+ line i ppf "Pmty_functor \"%s\"\n" s.txt;
module_type i ppf mt1;
module_type i ppf mt2;
| Pmty_with (mt, l) ->
@@ -530,24 +534,24 @@ and signature_item i ppf x =
let i = i+1 in
match x.psig_desc with
| Psig_value (s, vd) ->
- line i ppf "Psig_value \"%s\"\n" s;
+ line i ppf "Psig_value \"%s\"\n" s.txt;
value_description i ppf vd;
| Psig_type (l) ->
line i ppf "Psig_type\n";
list i string_x_type_declaration ppf l;
| Psig_exception (s, ed) ->
- line i ppf "Psig_exception \"%s\"\n" s;
+ line i ppf "Psig_exception \"%s\"\n" s.txt;
exception_declaration i ppf ed;
| Psig_module (s, mt) ->
- line i ppf "Psig_module \"%s\"\n" s;
+ line i ppf "Psig_module \"%s\"\n" s.txt;
module_type i ppf mt;
| Psig_recmodule decls ->
line i ppf "Psig_recmodule\n";
list i string_x_module_type ppf decls;
| Psig_modtype (s, md) ->
- line i ppf "Psig_modtype \"%s\"\n" s;
+ line i ppf "Psig_modtype \"%s\"\n" s.txt;
modtype_declaration i ppf md;
- | Psig_open (li) -> line i ppf "Psig_open %a\n" fmt_longident li;
+ | Psig_open li -> line i ppf "Psig_open %a\n" fmt_longident li;
| Psig_include (mt) ->
line i ppf "Psig_include\n";
module_type i ppf mt;
@@ -573,8 +577,8 @@ and with_constraint i ppf x =
| Pwith_typesubst (td) ->
line i ppf "Pwith_typesubst\n";
type_declaration (i+1) ppf td;
- | Pwith_module (li) -> line i ppf "Pwith_module %a\n" fmt_longident li;
- | Pwith_modsubst (li) -> line i ppf "Pwith_modsubst %a\n" fmt_longident li;
+ | Pwith_module li -> line i ppf "Pwith_module %a\n" fmt_longident li;
+ | Pwith_modsubst li -> line i ppf "Pwith_modsubst %a\n" fmt_longident li;
and module_expr i ppf x =
line i ppf "module_expr %a\n" fmt_location x.pmod_loc;
@@ -585,7 +589,7 @@ and module_expr i ppf x =
line i ppf "Pmod_structure\n";
structure i ppf s;
| Pmod_functor (s, mt, me) ->
- line i ppf "Pmod_functor \"%s\"\n" s;
+ line i ppf "Pmod_functor \"%s\"\n" s.txt;
module_type i ppf mt;
module_expr i ppf me;
| Pmod_apply (me1, me2) ->
@@ -613,26 +617,26 @@ and structure_item i ppf x =
line i ppf "Pstr_value %a\n" fmt_rec_flag rf;
list i pattern_x_expression_def ppf l;
| Pstr_primitive (s, vd) ->
- line i ppf "Pstr_primitive \"%s\"\n" s;
+ line i ppf "Pstr_primitive \"%s\"\n" s.txt;
value_description i ppf vd;
- | Pstr_type (l) ->
+ | Pstr_type l ->
line i ppf "Pstr_type\n";
list i string_x_type_declaration ppf l;
| Pstr_exception (s, ed) ->
- line i ppf "Pstr_exception \"%s\"\n" s;
+ line i ppf "Pstr_exception \"%s\"\n" s.txt;
exception_declaration i ppf ed;
| Pstr_exn_rebind (s, li) ->
- line i ppf "Pstr_exn_rebind \"%s\" %a\n" s fmt_longident li;
+ line i ppf "Pstr_exn_rebind \"%s\" %a\n" s.txt fmt_longident li;
| Pstr_module (s, me) ->
- line i ppf "Pstr_module \"%s\"\n" s;
+ line i ppf "Pstr_module \"%s\"\n" s.txt;
module_expr i ppf me;
| Pstr_recmodule bindings ->
line i ppf "Pstr_recmodule\n";
list i string_x_modtype_x_module ppf bindings;
| Pstr_modtype (s, mt) ->
- line i ppf "Pstr_modtype \"%s\"\n" s;
+ line i ppf "Pstr_modtype \"%s\"\n" s.txt;
module_type i ppf mt;
- | Pstr_open (li) -> line i ppf "Pstr_open %a\n" fmt_longident li;
+ | Pstr_open li -> line i ppf "Pstr_open %a\n" fmt_longident li;
| Pstr_class (l) ->
line i ppf "Pstr_class\n";
list i class_declaration ppf l;
@@ -644,15 +648,15 @@ and structure_item i ppf x =
module_expr i ppf me
and string_x_type_declaration i ppf (s, td) =
- string i ppf s;
+ string i ppf s.txt;
type_declaration (i+1) ppf td;
and string_x_module_type i ppf (s, mty) =
- string i ppf s;
+ string i ppf s.txt;
module_type (i+1) ppf mty;
and string_x_modtype_x_module i ppf (s, mty, modl) =
- string i ppf s;
+ string i ppf s.txt;
module_type (i+1) ppf mty;
module_expr (i+1) ppf modl;
@@ -665,18 +669,18 @@ and core_type_x_core_type_x_location i ppf (ct1, ct2, l) =
core_type (i+1) ppf ct1;
core_type (i+1) ppf ct2;
-and string_x_core_type_list_x_location i ppf (s, l, r_opt, loc) =
- line i ppf "\"%s\" %a\n" s fmt_location loc;
+and string_x_core_type_list_x_location i ppf (s, l, r_opt, loc) =
+ line i ppf "\"%s\" %a\n" s.txt fmt_location loc;
list (i+1) core_type ppf l;
option (i+1) core_type ppf r_opt;
and string_x_mutable_flag_x_core_type_x_location i ppf (s, mf, ct, loc) =
- line i ppf "\"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc;
+ line i ppf "\"%s\" %a %a\n" s.txt fmt_mutable_flag mf fmt_location loc;
core_type (i+1) ppf ct;
and string_list_x_location i ppf (l, loc) =
line i ppf "<params> %a\n" fmt_location loc;
- list (i+1) string ppf l;
+ list (i+1) string_loc ppf l;
and longident_x_pattern i ppf (li, p) =
line i ppf "%a\n" fmt_longident li;
@@ -693,7 +697,7 @@ and pattern_x_expression_def i ppf (p, e) =
expression (i+1) ppf e;
and string_x_expression i ppf (s, e) =
- line i ppf "<override> \"%s\"\n" s;
+ line i ppf "<override> \"%s\"\n" s.txt;
expression (i+1) ppf e;
and longident_x_expression i ppf (li, e) =
@@ -728,7 +732,7 @@ and directive_argument i ppf x =
| 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 (li) -> line i ppf "Pdir_ident %a\n" fmt_longident_noloc li;
| Pdir_bool (b) -> line i ppf "Pdir_bool %s\n" (string_of_bool b);
;;
diff --git a/testsuite/tests/asmcomp/Makefile b/testsuite/tests/asmcomp/Makefile
index 2161b856e..fb1af49c9 100644
--- a/testsuite/tests/asmcomp/Makefile
+++ b/testsuite/tests/asmcomp/Makefile
@@ -33,6 +33,7 @@ OTHEROBJS=\
$(TOPDIR)/typing/subst.cmo \
$(TOPDIR)/typing/predef.cmo \
$(TOPDIR)/typing/datarepr.cmo \
+ $(TOPDIR)/typing/cmi_format.cmo \
$(TOPDIR)/typing/env.cmo \
$(TOPDIR)/typing/typedtree.cmo \
$(TOPDIR)/typing/ctype.cmo \
@@ -43,6 +44,7 @@ OTHEROBJS=\
$(TOPDIR)/typing/includemod.cmo \
$(TOPDIR)/typing/parmatch.cmo \
$(TOPDIR)/typing/typetexp.cmo \
+ $(TOPDIR)/typing/cmt_format.cmo \
$(TOPDIR)/typing/stypes.cmo \
$(TOPDIR)/typing/typecore.cmo \
$(TOPDIR)/typing/typedecl.cmo \
diff --git a/testsuite/tests/typing-gadts/Makefile b/testsuite/tests/typing-gadts/Makefile
index 9add15574..5f42b7057 100644
--- a/testsuite/tests/typing-gadts/Makefile
+++ b/testsuite/tests/typing-gadts/Makefile
@@ -1,3 +1,4 @@
-include ../../makefiles/Makefile.toplevel
-include ../../makefiles/Makefile.common
+BASEDIR=../..
+include $(BASEDIR)/makefiles/Makefile.toplevel
+include $(BASEDIR)/makefiles/Makefile.common
diff --git a/testsuite/tests/typing-objects/Tests.ml.principal.reference b/testsuite/tests/typing-objects/Tests.ml.principal.reference
index 1f8912530..34a5071d7 100644
--- a/testsuite/tests/typing-objects/Tests.ml.principal.reference
+++ b/testsuite/tests/typing-objects/Tests.ml.principal.reference
@@ -168,9 +168,9 @@ Error: This expression has type bool but an expression was expected of type
Warning 13: the following instance variables are overridden by the class c :
x
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
-Characters 53-58:
+Characters 53-54:
val y = 3
- ^^^^^
+ ^
Warning 13: the instance variable y is overridden.
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
Characters 81-84:
@@ -179,9 +179,9 @@ Characters 81-84:
Warning 13: the following instance variables are overridden by the class d :
t z
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
-Characters 91-96:
+Characters 91-92:
val u = 3
- ^^^^^
+ ^
Warning 13: the instance variable u is overridden.
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
class e :
diff --git a/testsuite/tests/typing-objects/Tests.ml.reference b/testsuite/tests/typing-objects/Tests.ml.reference
index cbeaa6142..45130d58c 100644
--- a/testsuite/tests/typing-objects/Tests.ml.reference
+++ b/testsuite/tests/typing-objects/Tests.ml.reference
@@ -168,9 +168,9 @@ Error: This expression has type bool but an expression was expected of type
Warning 13: the following instance variables are overridden by the class c :
x
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
-Characters 53-58:
+Characters 53-54:
val y = 3
- ^^^^^
+ ^
Warning 13: the instance variable y is overridden.
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
Characters 81-84:
@@ -179,9 +179,9 @@ Characters 81-84:
Warning 13: the following instance variables are overridden by the class d :
t z
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
-Characters 91-96:
+Characters 91-92:
val u = 3
- ^^^^^
+ ^
Warning 13: the instance variable u is overridden.
The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
class e :
diff --git a/tools/.depend b/tools/.depend
index 36c177ed4..ad310b457 100644
--- a/tools/.depend
+++ b/tools/.depend
@@ -1,62 +1,97 @@
-depend.cmi: ../parsing/parsetree.cmi
-profiling.cmi:
-addlabels.cmo: ../parsing/parsetree.cmi ../parsing/parse.cmi \
+depend.cmi : ../parsing/parsetree.cmi
+profiling.cmi :
+typedtreeIter.cmi : ../typing/typedtree.cmi ../parsing/asttypes.cmi
+untypeast.cmi : ../typing/typedtree.cmi ../typing/path.cmi \
+ ../parsing/parsetree.cmi ../parsing/longident.cmi
+addlabels.cmo : ../parsing/parsetree.cmi ../parsing/parse.cmi \
../parsing/longident.cmi ../parsing/location.cmi ../parsing/asttypes.cmi
-addlabels.cmx: ../parsing/parsetree.cmi ../parsing/parse.cmx \
+addlabels.cmx : ../parsing/parsetree.cmi ../parsing/parse.cmx \
../parsing/longident.cmx ../parsing/location.cmx ../parsing/asttypes.cmi
-cvt_emit.cmo:
-cvt_emit.cmx:
-depend.cmo: ../parsing/parsetree.cmi ../parsing/longident.cmi \
- ../parsing/location.cmi depend.cmi
-depend.cmx: ../parsing/parsetree.cmi ../parsing/longident.cmx \
- ../parsing/location.cmx depend.cmi
-dumpobj.cmo: ../utils/tbl.cmi opnames.cmo ../bytecomp/opcodes.cmo \
- ../parsing/location.cmi ../bytecomp/lambda.cmi ../bytecomp/instruct.cmi \
- ../typing/ident.cmi ../bytecomp/emitcode.cmi ../utils/config.cmi \
- ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmi \
- ../parsing/asttypes.cmi
-dumpobj.cmx: ../utils/tbl.cmx opnames.cmx ../bytecomp/opcodes.cmx \
- ../parsing/location.cmx ../bytecomp/lambda.cmx ../bytecomp/instruct.cmx \
- ../typing/ident.cmx ../bytecomp/emitcode.cmx ../utils/config.cmx \
- ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmx \
- ../parsing/asttypes.cmi
-myocamlbuild_config.cmo:
-myocamlbuild_config.cmx:
-objinfo.cmo: ../utils/misc.cmi ../utils/config.cmi ../asmcomp/cmx_format.cmi \
- ../bytecomp/cmo_format.cmi ../asmcomp/clambda.cmi \
- ../bytecomp/bytesections.cmi
-objinfo.cmx: ../utils/misc.cmx ../utils/config.cmx ../asmcomp/cmx_format.cmi \
- ../bytecomp/cmo_format.cmi ../asmcomp/clambda.cmx \
- ../bytecomp/bytesections.cmx
-ocaml299to3.cmo:
-ocaml299to3.cmx:
-ocamlcp.cmo: ../driver/main_args.cmi
-ocamlcp.cmx: ../driver/main_args.cmx
-ocamldep.cmo: ../parsing/syntaxerr.cmi ../parsing/parsetree.cmi \
+cmt2annot.cmo : typedtreeIter.cmi ../typing/typedtree.cmi \
+ ../typing/stypes.cmi ../typing/path.cmi ../typing/oprint.cmi \
+ ../parsing/location.cmi ../typing/ident.cmi ../typing/env.cmi \
+ ../typing/cmt_format.cmi ../parsing/asttypes.cmi ../typing/annot.cmi
+cmt2annot.cmx : typedtreeIter.cmx ../typing/typedtree.cmx \
+ ../typing/stypes.cmx ../typing/path.cmx ../typing/oprint.cmx \
+ ../parsing/location.cmx ../typing/ident.cmx ../typing/env.cmx \
+ ../typing/cmt_format.cmx ../parsing/asttypes.cmi ../typing/annot.cmi
+cmt2ml.cmo : untypeast.cmi ../typing/typedtree.cmi pprintast.cmo \
+ ../typing/cmt_format.cmi
+cmt2ml.cmx : untypeast.cmx ../typing/typedtree.cmx pprintast.cmx \
+ ../typing/cmt_format.cmx
+cvt_emit.cmo :
+cvt_emit.cmx :
+depend.cmo : ../parsing/parsetree.cmi ../utils/misc.cmi \
+ ../parsing/longident.cmi ../parsing/location.cmi ../parsing/asttypes.cmi \
+ depend.cmi
+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 ../bytecomp/emitcode.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 ../bytecomp/emitcode.cmx \
+ ../utils/config.cmx ../bytecomp/cmo_format.cmi \
+ ../bytecomp/bytesections.cmx ../parsing/asttypes.cmi
+myocamlbuild_config.cmo :
+myocamlbuild_config.cmx :
+objinfo.cmo : ../utils/misc.cmi ../utils/config.cmi \
+ ../asmcomp/cmx_format.cmi ../bytecomp/cmo_format.cmi \
+ ../asmcomp/clambda.cmi ../bytecomp/bytesections.cmi
+objinfo.cmx : ../utils/misc.cmx ../utils/config.cmx \
+ ../asmcomp/cmx_format.cmi ../bytecomp/cmo_format.cmi \
+ ../asmcomp/clambda.cmx ../bytecomp/bytesections.cmx
+ocaml299to3.cmo :
+ocaml299to3.cmx :
+ocamlcp.cmo : ../driver/main_args.cmi
+ocamlcp.cmx : ../driver/main_args.cmx
+ocamldep.cmo : ../parsing/syntaxerr.cmi ../parsing/parsetree.cmi \
../parsing/parse.cmi ../utils/misc.cmi ../parsing/longident.cmi \
../parsing/location.cmi ../parsing/lexer.cmi depend.cmi \
../utils/config.cmi ../utils/clflags.cmi
-ocamldep.cmx: ../parsing/syntaxerr.cmx ../parsing/parsetree.cmi \
+ocamldep.cmx : ../parsing/syntaxerr.cmx ../parsing/parsetree.cmi \
../parsing/parse.cmx ../utils/misc.cmx ../parsing/longident.cmx \
../parsing/location.cmx ../parsing/lexer.cmx depend.cmx \
../utils/config.cmx ../utils/clflags.cmx
-ocamlmklib.cmo: myocamlbuild_config.cmo
-ocamlmklib.cmx: myocamlbuild_config.cmx
-ocamlmktop.cmo: ../utils/ccomp.cmi
-ocamlmktop.cmx: ../utils/ccomp.cmx
-ocamlprof.cmo: ../utils/warnings.cmi ../parsing/syntaxerr.cmi \
+ocamlmklib.cmo : myocamlbuild_config.cmo
+ocamlmklib.cmx : myocamlbuild_config.cmx
+ocamlmktop.cmo : ../utils/ccomp.cmi
+ocamlmktop.cmx : ../utils/ccomp.cmx
+ocamloptp.cmo : ../driver/main_args.cmi
+ocamloptp.cmx : ../driver/main_args.cmx
+ocamlprof.cmo : ../utils/warnings.cmi ../parsing/syntaxerr.cmi \
../parsing/parsetree.cmi ../parsing/parse.cmi ../utils/misc.cmi \
../parsing/location.cmi ../parsing/lexer.cmi ../utils/config.cmi \
../utils/clflags.cmi
-ocamlprof.cmx: ../utils/warnings.cmx ../parsing/syntaxerr.cmx \
+ocamlprof.cmx : ../utils/warnings.cmx ../parsing/syntaxerr.cmx \
../parsing/parsetree.cmi ../parsing/parse.cmx ../utils/misc.cmx \
../parsing/location.cmx ../parsing/lexer.cmx ../utils/config.cmx \
../utils/clflags.cmx
-opnames.cmo:
-opnames.cmx:
-primreq.cmo: ../utils/config.cmi ../bytecomp/cmo_format.cmi
-primreq.cmx: ../utils/config.cmx ../bytecomp/cmo_format.cmi
-profiling.cmo: profiling.cmi
-profiling.cmx: profiling.cmi
-scrapelabels.cmo:
-scrapelabels.cmx:
+opnames.cmo :
+opnames.cmx :
+pprintast.cmo : ../parsing/parsetree.cmi ../parsing/longident.cmi \
+ ../parsing/location.cmi ../parsing/asttypes.cmi
+pprintast.cmx : ../parsing/parsetree.cmi ../parsing/longident.cmx \
+ ../parsing/location.cmx ../parsing/asttypes.cmi
+primreq.cmo : ../utils/config.cmi ../bytecomp/cmo_format.cmi
+primreq.cmx : ../utils/config.cmx ../bytecomp/cmo_format.cmi
+profiling.cmo : profiling.cmi
+profiling.cmx : profiling.cmi
+read_cmt.cmo : ../typing/cmt_format.cmi cmt2annot.cmo ../utils/clflags.cmi
+read_cmt.cmx : ../typing/cmt_format.cmx cmt2annot.cmx ../utils/clflags.cmx
+scrapelabels.cmo :
+scrapelabels.cmx :
+typedtreeIter.cmo : ../typing/typedtree.cmi ../utils/misc.cmi \
+ ../parsing/asttypes.cmi typedtreeIter.cmi
+typedtreeIter.cmx : ../typing/typedtree.cmx ../utils/misc.cmx \
+ ../parsing/asttypes.cmi typedtreeIter.cmi
+untypeast.cmo : ../typing/typedtree.cmi ../typing/path.cmi \
+ ../parsing/parsetree.cmi ../utils/misc.cmi ../parsing/longident.cmi \
+ ../typing/ident.cmi ../parsing/asttypes.cmi untypeast.cmi
+untypeast.cmx : ../typing/typedtree.cmx ../typing/path.cmx \
+ ../parsing/parsetree.cmi ../utils/misc.cmx ../parsing/longident.cmx \
+ ../typing/ident.cmx ../parsing/asttypes.cmi untypeast.cmi
diff --git a/tools/.ignore b/tools/.ignore
index cf3c69515..d8b1412d6 100644
--- a/tools/.ignore
+++ b/tools/.ignore
@@ -23,3 +23,4 @@ scrapelabels
addlabels
myocamlbuild_config.ml
objinfo_helper
+read_cmt
diff --git a/tools/Makefile.shared b/tools/Makefile.shared
index 02af98f0c..72f126205 100644
--- a/tools/Makefile.shared
+++ b/tools/Makefile.shared
@@ -24,6 +24,7 @@ COMPFLAGS= -warn-error A $(INCLUDES)
LINKFLAGS=$(INCLUDES)
all: ocamldep ocamlprof ocamlcp ocamlmktop ocamlmklib dumpobj objinfo
+
# scrapelabels addlabels
.PHONY: all
@@ -184,6 +185,51 @@ clean::
beforedepend:: cvt_emit.ml
+
+# Reading cmt files
+
+READ_CMT= \
+ ../utils/misc.cmo \
+ ../utils/warnings.cmo \
+ ../utils/tbl.cmo \
+ ../utils/consistbl.cmo \
+ ../utils/config.cmo \
+ ../utils/clflags.cmo \
+ ../parsing/location.cmo \
+ ../parsing/longident.cmo \
+ ../parsing/lexer.cmo \
+ ../typing/ident.cmo \
+ ../typing/path.cmo \
+ ../typing/types.cmo \
+ ../typing/typedtree.cmo \
+ ../typing/btype.cmo \
+ ../typing/subst.cmo \
+ ../typing/predef.cmo \
+ ../typing/datarepr.cmo \
+ ../typing/cmi_format.cmo \
+ ../typing/env.cmo \
+ ../typing/ctype.cmo \
+ ../typing/oprint.cmo \
+ ../typing/primitive.cmo \
+ ../typing/printtyp.cmo \
+ ../typing/cmt_format.cmo \
+ ../typing/stypes.cmo \
+ \
+ pprintast.cmo untypeast.cmo typedtreeIter.cmo \
+ cmt2annot.cmo read_cmt.cmo
+
+read_cmt: $(READ_CMT)
+ $(CAMLC) $(LINKFLAGS) -o read_cmt $(READ_CMT)
+
+# read_cmt is precious: sometimes we are stuck in the middle of a
+# bootstrap and we need to remake the dependencies
+clean::
+ if test -f read_cmt; then mv -f read_cmt read_cmt.bak; else :; fi
+
+clean::
+
+beforedepend::
+
# The bytecode disassembler
DUMPOBJ=opnames.cmo dumpobj.cmo
@@ -219,7 +265,9 @@ objinfo_helper$(EXE): objinfo_helper.c ../config/s.h
$(BYTECC) -o objinfo_helper$(EXE) $(BYTECCCOMPOPTS) \
objinfo_helper.c $(LIBBFD_LINK)
-OBJINFO=../utils/misc.cmo ../utils/config.cmo ../bytecomp/bytesections.cmo \
+OBJINFO=../utils/misc.cmo ../utils/config.cmo \
+ ../utils/warnings.cmo ../parsing/location.cmo \
+ ../typing/cmi_format.cmo ../bytecomp/bytesections.cmo \
objinfo.cmo
objinfo: objinfo_helper$(EXE) $(OBJINFO)
diff --git a/tools/addlabels.ml b/tools/addlabels.ml
index c057e72ca..c12bde847 100644
--- a/tools/addlabels.ml
+++ b/tools/addlabels.ml
@@ -49,11 +49,11 @@ let rec labels_of_cty cty =
Pcty_fun (lab, _, rem) ->
let (labs, meths) = labels_of_cty rem in
(lab :: labs, meths)
- | Pcty_signature (_, fields) ->
+ | Pcty_signature { pcsig_fields = fields } ->
([],
List.fold_left fields ~init:[] ~f:
begin fun meths -> function
- Pctf_meth (s, _, sty, _) -> (s, labels_of_sty sty)::meths
+ { pctf_desc = Pctf_meth (s, _, sty) } -> (s, labels_of_sty sty)::meths
| _ -> meths
end)
| _ ->
@@ -61,9 +61,9 @@ let rec labels_of_cty cty =
let rec pattern_vars pat =
match pat.ppat_desc with
- Ppat_var s -> [s]
+ Ppat_var s -> [s.txt]
| Ppat_alias (pat, s) ->
- s :: pattern_vars pat
+ s.txt :: pattern_vars pat
| Ppat_tuple l
| Ppat_array l ->
List.concat (List.map pattern_vars l)
@@ -124,7 +124,7 @@ let rec insert_labels ~labels ~text expr =
let start_c = pat.ppat_loc.Location.loc_start.Lexing.pos_cnum in
let pos = insertion_point start_c ~text in
match pattern_name pat with
- | Some name when l = name -> add_insertion pos "~"
+ | Some name when l = name.txt -> add_insertion pos "~"
| _ -> add_insertion pos ("~" ^ l ^ ":")
end;
insert_labels ~labels ~text rem
@@ -164,7 +164,7 @@ let rec insert_labels_class ~labels ~text expr =
let start_c = pat.ppat_loc.Location.loc_start.Lexing.pos_cnum in
let pos = insertion_point start_c ~text in
match pattern_name pat with
- | Some name when l = name -> add_insertion pos "~"
+ | Some name when l = name.txt -> add_insertion pos "~"
| _ -> add_insertion pos ("~" ^ l ^ ":")
end;
insert_labels_class ~labels ~text rem
@@ -192,7 +192,7 @@ let rec insert_labels_app ~labels ~text args =
let pos0 = arg.pexp_loc.Location.loc_start.Lexing.pos_cnum in
let pos = insertion_point pos0 ~text in
match arg.pexp_desc with
- | Pexp_ident(Longident.Lident name) when l = name && pos = pos0 ->
+ | Pexp_ident({ txt = Longident.Lident name }) when l = name && pos = pos0 ->
add_insertion pos "~"
| _ -> add_insertion pos ("~" ^ l ^ ":")
end;
@@ -218,7 +218,7 @@ let rec add_labels_expr ~text ~values ~classes expr =
let add_labels_rec ?(values=values) expr =
add_labels_expr ~text ~values ~classes expr in
match expr.pexp_desc with
- Pexp_apply ({pexp_desc=Pexp_ident(Longident.Lident s)}, args) ->
+ Pexp_apply ({pexp_desc=Pexp_ident({ txt = Longident.Lident s })}, args) ->
begin try
let labels = SMap.find s values in
insert_labels_app ~labels ~text args
@@ -226,14 +226,14 @@ let rec add_labels_expr ~text ~values ~classes expr =
end;
List.iter args ~f:(fun (_,e) -> add_labels_rec e)
| Pexp_apply ({pexp_desc=Pexp_send
- ({pexp_desc=Pexp_ident(Longident.Lident s)},meth)}, args) ->
+ ({pexp_desc=Pexp_ident({ txt = Longident.Lident s })},meth)}, args) ->
begin try
if SMap.find s values = ["<object>"] then
let labels = SMap.find (s ^ "#" ^ meth) values in
insert_labels_app ~labels ~text args
with Not_found -> ()
end
- | Pexp_apply ({pexp_desc=Pexp_new (Longident.Lident s)}, args) ->
+ | Pexp_apply ({pexp_desc=Pexp_new ({ txt = Longident.Lident s })}, args) ->
begin try
let labels = SMap.find s classes in
insert_labels_app ~labels ~text args
@@ -288,7 +288,7 @@ let rec add_labels_expr ~text ~values ~classes expr =
add_labels_rec e1; add_labels_rec e2; add_labels_rec e3
| Pexp_for (s, e1, e2, _, e3) ->
add_labels_rec e1; add_labels_rec e2;
- add_labels_rec e3 ~values:(SMap.removes [s] values)
+ add_labels_rec e3 ~values:(SMap.removes [s.txt] values)
| Pexp_override lst ->
List.iter lst ~f:(fun (_,e) -> add_labels_rec e)
| Pexp_ident _ | Pexp_constant _ | Pexp_construct _ | Pexp_variant _
@@ -298,23 +298,23 @@ let rec add_labels_expr ~text ~values ~classes expr =
let rec add_labels_class ~text ~classes ~values ~methods cl =
match cl.pcl_desc with
Pcl_constr _ -> ()
- | Pcl_structure (p, l) ->
+ | Pcl_structure { pcstr_pat = p; pcstr_fields = l } ->
let values = SMap.removes (pattern_vars p) values in
let values =
match pattern_name p with None -> values
| Some s ->
List.fold_left methods
- ~init:(SMap.add s ["<object>"] values)
- ~f:(fun m (k,l) -> SMap.add (s^"#"^k) l m)
+ ~init:(SMap.add s.txt ["<object>"] values)
+ ~f:(fun m (k,l) -> SMap.add (s.txt^"#"^k) l m)
in
ignore (List.fold_left l ~init:values ~f:
- begin fun values -> function
- | Pcf_val (s, _, _, e, _) ->
+ begin fun values -> function e -> match e.pcf_desc with
+ | Pcf_val (s, _, _, e) ->
add_labels_expr ~text ~classes ~values e;
- SMap.removes [s] values
- | Pcf_meth (s, _, _, e, _) ->
+ SMap.removes [s.txt] values
+ | Pcf_meth (s, _, _, e) ->
begin try
- let labels = List.assoc s methods in
+ let labels = List.assoc s.txt methods in
insert_labels ~labels ~text e
with Not_found -> ()
end;
@@ -323,7 +323,7 @@ let rec add_labels_class ~text ~classes ~values ~methods cl =
| Pcf_init e ->
add_labels_expr ~text ~classes ~values e;
values
- | Pcf_inher _ | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> values
+ | Pcf_inher _ | Pcf_valvirt _ | Pcf_virt _ | Pcf_constr _ -> values
end)
| Pcl_fun (_, opt, pat, cl) ->
begin match opt with None -> ()
@@ -353,12 +353,12 @@ let add_labels ~intf ~impl ~file =
begin fun (values, classes as acc) item ->
match item.psig_desc with
Psig_value (name, {pval_type = sty}) ->
- (SMap.add name (labels_of_sty sty) values, classes)
+ (SMap.add name.txt (labels_of_sty sty) values, classes)
| Psig_class l ->
(values,
List.fold_left l ~init:classes ~f:
begin fun classes {pci_name=name; pci_expr=cty} ->
- SMap.add name (labels_of_cty cty) classes
+ SMap.add name.txt (labels_of_cty cty) classes
end)
| _ ->
acc
@@ -376,7 +376,7 @@ let add_labels ~intf ~impl ~file =
begin match pattern_name pat with
| Some s ->
begin try
- let labels = SMap.find s values in
+ let labels = SMap.find s.txt values in
insert_labels ~labels ~text expr;
if !norec then () else
let values =
@@ -393,17 +393,17 @@ let add_labels ~intf ~impl ~file =
(SMap.removes names values, classes)
| Pstr_primitive (s, {pval_type=sty}) ->
begin try
- let labels = SMap.find s values in
+ let labels = SMap.find s.txt values in
insert_labels_type ~labels ~text sty;
- (SMap.removes [s] values, classes)
+ (SMap.removes [s.txt] values, classes)
with Not_found -> acc
end
| Pstr_class l ->
- let names = List.map l ~f:(fun pci -> pci.pci_name) in
+ let names = List.map l ~f:(fun pci -> pci.pci_name.txt) in
List.iter l ~f:
begin fun {pci_name=name; pci_expr=expr} ->
try
- let (labels, methods) = SMap.find name classes in
+ let (labels, methods) = SMap.find name.txt classes in
insert_labels_class ~labels ~text expr;
if !norec then () else
let classes =
diff --git a/tools/depend.ml b/tools/depend.ml
index 948646a82..2015f937e 100644
--- a/tools/depend.ml
+++ b/tools/depend.ml
@@ -12,6 +12,7 @@
(* $Id$ *)
+open Asttypes
open Format
open Location
open Longident
@@ -21,6 +22,8 @@ module StringSet = Set.Make(struct type t = string let compare = compare end)
(* Collect free module identifiers in the a.s.t. *)
+let fst3 (x, _, _) = x
+
let free_structure_names = ref StringSet.empty
let rec addmodule bv lid =
@@ -32,10 +35,12 @@ let rec addmodule bv lid =
| Lapply(l1, l2) -> addmodule bv l1; addmodule bv l2
let add bv lid =
- match lid with
+ match lid.txt with
Ldot(l, s) -> addmodule bv l
| _ -> ()
+let addmodule bv lid = addmodule bv lid.txt
+
let rec add_type bv ty =
match ty.ptyp_desc with
Ptyp_any -> ()
@@ -56,7 +61,7 @@ let rec add_type bv ty =
and add_package_type bv (lid, l) =
add bv lid;
- List.iter (add_type bv) (List.map snd l)
+ List.iter (add_type bv) (List.map (fun (_, e) -> e) l)
and add_field_type bv ft =
match ft.pfield_desc with
@@ -84,18 +89,19 @@ let rec add_class_type bv cty =
match cty.pcty_desc with
Pcty_constr(l, tyl) ->
add bv l; List.iter (add_type bv) tyl
- | Pcty_signature (ty, fieldl) ->
+ | Pcty_signature { pcsig_self = ty; pcsig_fields = fieldl } ->
add_type bv ty;
List.iter (add_class_type_field bv) fieldl
| Pcty_fun(_, ty1, cty2) ->
add_type bv ty1; add_class_type bv cty2
-and add_class_type_field bv = function
+and add_class_type_field bv pctf =
+ match pctf.pctf_desc with
Pctf_inher cty -> add_class_type bv cty
- | Pctf_val(_, _, _, ty, _) -> add_type bv ty
- | Pctf_virt(_, _, ty, _) -> add_type bv ty
- | Pctf_meth(_, _, ty, _) -> add_type bv ty
- | Pctf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2
+ | Pctf_val(_, _, _, ty) -> add_type bv ty
+ | Pctf_virt(_, _, ty) -> add_type bv ty
+ | Pctf_meth(_, _, ty) -> add_type bv ty
+ | Pctf_cstr(ty1, ty2) -> add_type bv ty1; add_type bv ty2
let add_class_description bv infos =
add_class_type bv infos.pci_expr
@@ -116,7 +122,7 @@ let rec add_pattern bv pat =
| Ppat_or(p1, p2) -> add_pattern bv p1; add_pattern bv p2
| Ppat_constraint(p, ty) -> add_pattern bv p; add_type bv ty
| Ppat_variant(_, op) -> add_opt add_pattern bv op
- | Ppat_type (li) -> add bv li
+ | Ppat_type li -> add bv li
| Ppat_lazy p -> add_pattern bv p
| Ppat_unpack _ -> ()
@@ -144,7 +150,7 @@ let rec add_expr bv exp =
add_expr bv e1; add_expr bv e2; add_opt add_expr bv opte3
| Pexp_sequence(e1, e2) -> add_expr bv e1; add_expr bv e2
| Pexp_while(e1, e2) -> add_expr bv e1; add_expr bv e2
- | Pexp_for(_, e1, e2, _, e3) ->
+ | Pexp_for( _, e1, e2, _, e3) ->
add_expr bv e1; add_expr bv e2; add_expr bv e3
| Pexp_constraint(e1, oty2, oty3) ->
add_expr bv e1;
@@ -152,16 +158,16 @@ let rec add_expr bv exp =
add_opt add_type bv oty3
| Pexp_when(e1, e2) -> add_expr bv e1; add_expr bv e2
| Pexp_send(e, m) -> add_expr bv e
- | Pexp_new l -> add bv l
+ | 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_letmodule(id, m, e) ->
- add_module bv m; add_expr (StringSet.add id bv) e
+ add_module bv m; add_expr (StringSet.add id.txt bv) e
| Pexp_assert (e) -> add_expr bv e
| Pexp_assertfalse -> ()
| Pexp_lazy (e) -> add_expr bv e
| Pexp_poly (e, t) -> add_expr bv e; add_opt add_type bv t
- | Pexp_object (pat, fieldl) ->
+ | Pexp_object { pcstr_pat = pat; pcstr_fields = fieldl } ->
add_pattern bv pat; List.iter (add_class_field bv) fieldl
| Pexp_newtype (_, e) -> add_expr bv e
| Pexp_pack m -> add_module bv m
@@ -174,14 +180,14 @@ and add_modtype bv mty =
Pmty_ident l -> add bv l
| Pmty_signature s -> add_signature bv s
| Pmty_functor(id, mty1, mty2) ->
- add_modtype bv mty1; add_modtype (StringSet.add id bv) mty2
+ add_modtype bv mty1; add_modtype (StringSet.add id.txt bv) mty2
| Pmty_with(mty, cstrl) ->
add_modtype bv mty;
List.iter
(function (_, Pwith_type td) -> add_type_declaration bv td
- | (_, Pwith_module lid) -> addmodule bv lid
+ | (_, Pwith_module (lid)) -> addmodule bv lid
| (_, Pwith_typesubst td) -> add_type_declaration bv td
- | (_, Pwith_modsubst lid) -> addmodule bv lid)
+ | (_, Pwith_modsubst (lid)) -> addmodule bv lid)
cstrl
| Pmty_typeof m -> add_module bv m
@@ -198,12 +204,12 @@ and add_sig_item bv item =
| Psig_exception(id, args) ->
List.iter (add_type bv) args; bv
| Psig_module(id, mty) ->
- add_modtype bv mty; StringSet.add id bv
+ add_modtype bv mty; StringSet.add id.txt bv
| Psig_recmodule decls ->
- let bv' = List.fold_right StringSet.add (List.map fst decls) bv in
+ let bv' = List.fold_right StringSet.add (List.map (fun (x,_) -> x.txt) decls) bv in
List.iter (fun (id, mty) -> add_modtype bv' mty) decls;
bv'
- | Psig_modtype(id, mtyd) ->
+ | Psig_modtype(id,mtyd) ->
begin match mtyd with
Pmodtype_abstract -> ()
| Pmodtype_manifest mty -> add_modtype bv mty
@@ -224,7 +230,7 @@ and add_module bv modl =
| Pmod_structure s -> ignore (add_structure bv s)
| Pmod_functor(id, mty, modl) ->
add_modtype bv mty;
- add_module (StringSet.add id bv) modl
+ add_module (StringSet.add id.txt bv) modl
| Pmod_apply(mod1, mod2) ->
add_module bv mod1; add_module bv mod2
| Pmod_constraint(modl, mty) ->
@@ -250,11 +256,11 @@ and add_struct_item bv item =
| Pstr_exn_rebind(id, l) ->
add bv l; bv
| Pstr_module(id, modl) ->
- add_module bv modl; StringSet.add id bv
+ add_module bv modl; StringSet.add id.txt bv
| Pstr_recmodule bindings ->
let bv' =
List.fold_right StringSet.add
- (List.map (fun (id,_,_) -> id) bindings) bv in
+ (List.map (fun (id,_,_) -> id.txt) bindings) bv in
List.iter
(fun (id, mty, modl) -> add_modtype bv' mty; add_module bv' modl)
bindings;
@@ -281,7 +287,7 @@ and add_class_expr bv ce =
match ce.pcl_desc with
Pcl_constr(l, tyl) ->
add bv l; List.iter (add_type bv) tyl
- | Pcl_structure(pat, fieldl) ->
+ | Pcl_structure { pcstr_pat = pat; pcstr_fields = fieldl } ->
add_pattern bv pat; List.iter (add_class_field bv) fieldl
| Pcl_fun(_, opte, pat, ce) ->
add_opt add_expr bv opte; add_pattern bv pat; add_class_expr bv ce
@@ -292,13 +298,14 @@ and add_class_expr bv ce =
| Pcl_constraint(ce, ct) ->
add_class_expr bv ce; add_class_type bv ct
-and add_class_field bv = function
+and add_class_field bv pcf =
+ match pcf.pcf_desc with
Pcf_inher(_, ce, _) -> add_class_expr bv ce
- | Pcf_val(_, _, _, e, _) -> add_expr bv e
- | Pcf_valvirt(_, _, ty, _)
- | Pcf_virt(_, _, ty, _) -> add_type bv ty
- | Pcf_meth(_, _, _, e, _) -> add_expr bv e
- | Pcf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2
+ | Pcf_val(_, _, _, e) -> add_expr bv e
+ | Pcf_valvirt(_, _, ty)
+ | Pcf_virt(_, _, ty) -> add_type bv ty
+ | Pcf_meth(_, _, _, e) -> add_expr bv e
+ | Pcf_constr(ty1, ty2) -> add_type bv ty1; add_type bv ty2
| Pcf_init e -> add_expr bv e
and add_class_declaration bv decl =
diff --git a/tools/dumpobj.ml b/tools/dumpobj.ml
index ff7ff688a..5a40cfc39 100644
--- a/tools/dumpobj.ml
+++ b/tools/dumpobj.ml
@@ -26,6 +26,8 @@ open Opnames
open Cmo_format
open Printf
+let print_locations = ref true
+
(* Read signed and unsigned integers *)
let inputu ic =
@@ -399,11 +401,12 @@ let op_shapes = [
];;
let print_event ev =
- let ls = ev.ev_loc.loc_start in
- let le = ev.ev_loc.loc_end in
- printf "File \"%s\", line %d, characters %d-%d:\n" ls.Lexing.pos_fname
- ls.Lexing.pos_lnum (ls.Lexing.pos_cnum - ls.Lexing.pos_bol)
- (le.Lexing.pos_cnum - ls.Lexing.pos_bol)
+ if !print_locations then
+ let ls = ev.ev_loc.loc_start in
+ let le = ev.ev_loc.loc_end in
+ printf "File \"%s\", line %d, characters %d-%d:\n" ls.Lexing.pos_fname
+ ls.Lexing.pos_lnum (ls.Lexing.pos_cnum - ls.Lexing.pos_bol)
+ (le.Lexing.pos_cnum - ls.Lexing.pos_bol)
let print_instr ic =
let pos = currpos ic in
@@ -539,20 +542,28 @@ let dump_exe ic =
let code_size = Bytesections.seek_section ic "CODE" in
print_code ic code_size
-let main() =
- for i = 1 to Array.length Sys.argv - 1 do
- let filnam = Sys.argv.(i) in
- let ic = open_in_bin filnam in
- if i>1 then print_newline ();
- printf "## start of ocaml dump of %S\n%!" filnam;
- begin try
- objfile := false; dump_exe ic
+let arg_list = [
+ "-noloc", Arg.Clear print_locations, " : don't print source information";
+]
+let arg_usage = Printf.sprintf "%s [OPTIONS] FILES : dump content of bytecode files" Sys.argv.(0)
+
+let first_file = ref true
+
+let arg_fun filename =
+ let ic = open_in_bin filename in
+ if not !first_file then print_newline ();
+ first_file := false;
+ printf "## start of ocaml dump of %S\n%!" filename;
+ begin try
+ objfile := false; dump_exe ic
with Bytesections.Bad_magic_number ->
- objfile := true; seek_in ic 0; dump_obj (Sys.argv.(i)) ic
- end;
- close_in ic;
- printf "## end of ocaml dump of %S\n%!" filnam;
- done;
- exit 0
+ objfile := true; seek_in ic 0; dump_obj filename ic
+ end;
+ close_in ic;
+ printf "## end of ocaml dump of %S\n%!" filename
+
+let main() =
+ Arg.parse arg_list arg_fun arg_usage;
+ exit 0
let _ = main ()
diff --git a/tools/objinfo.ml b/tools/objinfo.ml
index 42fa8ee9c..1e0a38e10 100644
--- a/tools/objinfo.ml
+++ b/tools/objinfo.ml
@@ -97,7 +97,7 @@ let print_cma_infos (lib : Cmo_format.library) =
printf "\n";
List.iter print_cmo_infos lib.lib_units
-let print_cmi_infos name sign comps crcs =
+let print_cmi_infos name sign crcs =
printf "Unit name: %s\n" name;
printf "Interfaces imported:\n";
List.iter print_name_crc crcs
@@ -231,10 +231,10 @@ let dump_obj filename =
close_in ic;
print_cma_infos toc
end else if magic_number = cmi_magic_number then begin
- let (name, sign, comps) = input_value ic in
- let crcs = input_value ic in
+ let cmi = Cmi_format.input_cmi ic in
close_in ic;
- print_cmi_infos name sign comps crcs
+ print_cmi_infos cmi.Cmi_format.cmi_name cmi.Cmi_format.cmi_sign
+ cmi.Cmi_format.cmi_crcs
end else if magic_number = cmx_magic_number then begin
let ui = (input_value ic : unit_infos) in
let crc = Digest.input ic in
@@ -269,10 +269,11 @@ let dump_obj filename =
end
end
+let arg_list = []
+let arg_usage = Printf.sprintf "%s [OPTIONS] FILES : give information on files" Sys.argv.(0)
+
let main() =
- for i = 1 to Array.length Sys.argv - 1 do
- dump_obj Sys.argv.(i)
- done;
+ Arg.parse arg_list dump_obj arg_usage;
exit 0
let _ = main ()
diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml
index e9c6c0599..8f09cc134 100644
--- a/tools/ocamlcp.ml
+++ b/tools/ocamlcp.ml
@@ -45,6 +45,7 @@ module Options = Main_args.Make_bytecomp_options (struct
let _a () = make_archive := true; option "-a" ()
let _absname = option "-absname"
let _annot = option "-annot"
+ let _binannot = option "-bin-annot"
let _c = option "-c"
let _cc s = option_with_arg "-cc" s
let _cclib s = option_with_arg "-cclib" s
diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml
index b8a6b3fa4..1fd123cea 100644
--- a/tools/ocamlprof.ml
+++ b/tools/ocamlprof.ml
@@ -282,8 +282,8 @@ and rw_exp iflag sexp =
| Pexp_poly (sexp, _) -> rewrite_exp iflag sexp
- | Pexp_object (_, fieldl) ->
- List.iter (rewrite_class_field iflag) fieldl
+ | Pexp_object cl ->
+ List.iter (rewrite_class_field iflag) cl.pcstr_fields
| Pexp_newtype (_, sexp) -> rewrite_exp iflag sexp
| Pexp_open (_, e) -> rewrite_exp iflag e
@@ -319,24 +319,25 @@ and rewrite_trymatching l =
(* Rewrite a class definition *)
-and rewrite_class_field iflag =
- function
+and rewrite_class_field iflag cf =
+ match cf.pcf_desc with
Pcf_inher (_, cexpr, _) -> rewrite_class_expr iflag cexpr
- | Pcf_val (_, _, _, sexp, _) -> rewrite_exp iflag sexp
- | Pcf_meth (_, _, _, ({pexp_desc = Pexp_function _} as sexp), _) ->
+ | Pcf_val (_, _, _, sexp) -> rewrite_exp iflag sexp
+ | Pcf_meth (_, _, _, ({pexp_desc = Pexp_function _} as sexp)) ->
rewrite_exp iflag sexp
- | Pcf_meth (_, _, _, sexp, loc) ->
+ | Pcf_meth (_, _, _, sexp) ->
+ let loc = cf.pcf_loc in
if !instr_fun && not loc.loc_ghost then insert_profile rw_exp sexp
else rewrite_exp iflag sexp
| Pcf_init sexp ->
rewrite_exp iflag sexp
- | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> ()
+ | Pcf_valvirt _ | Pcf_virt _ | Pcf_constr _ -> ()
and rewrite_class_expr iflag cexpr =
match cexpr.pcl_desc with
Pcl_constr _ -> ()
- | Pcl_structure (_, fields) ->
- List.iter (rewrite_class_field iflag) fields
+ | Pcl_structure st ->
+ List.iter (rewrite_class_field iflag) st.pcstr_fields
| Pcl_fun (_, _, _, cexpr) ->
rewrite_class_expr iflag cexpr
| Pcl_apply (cexpr, exprs) ->
diff --git a/toplevel/genprintval.ml b/toplevel/genprintval.ml
index 2bf72f19c..9282aa2bc 100644
--- a/toplevel/genprintval.ml
+++ b/toplevel/genprintval.ml
@@ -156,10 +156,10 @@ module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct
let tree_of_constr =
tree_of_qualified
- (fun lid env -> (Env.lookup_constructor lid env).cstr_res)
+ (fun lid env -> (snd (Env.lookup_constructor lid env)).cstr_res)
and tree_of_label =
- tree_of_qualified (fun lid env -> (Env.lookup_label lid env).lbl_res)
+ tree_of_qualified (fun lid env -> (snd (Env.lookup_label lid env)).lbl_res)
(* An abstract type *)
@@ -249,10 +249,10 @@ module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct
else Cstr_constant(O.obj obj) in
let (constr_name, constr_args,ret_type) =
Datarepr.find_constr_by_tag tag constr_list in
- let type_params =
+ let type_params =
match ret_type with
- Some t ->
- begin match (Ctype.repr t).desc with
+ Some t ->
+ begin match (Ctype.repr t).desc with
Tconstr (_,params,_) ->
params
| _ -> assert false end
@@ -265,7 +265,7 @@ module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct
Ctype.Cannot_apply -> abstract_type)
constr_args in
tree_of_constr_with_args (tree_of_constr env path)
- constr_name 0 depth obj ty_args
+ (Ident.name constr_name) 0 depth obj ty_args
| {type_kind = Type_record(lbl_list, rep)} ->
begin match check_depth depth obj ty with
Some x -> x
@@ -279,7 +279,7 @@ module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct
ty_list
with
Ctype.Cannot_apply -> abstract_type in
- let lid = tree_of_label env path lbl_name in
+ let lid = tree_of_label env path (Ident.name lbl_name) in
let v =
tree_of_val (depth - 1) (O.field obj pos)
ty_arg
@@ -351,7 +351,7 @@ module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct
try
(* Attempt to recover the constructor description for the exn
from its name *)
- let cstr = Env.lookup_constructor lid env in
+ let cstr = snd (Env.lookup_constructor lid env) in
let path =
match cstr.cstr_tag with
Cstr_exception (p, _) -> p | _ -> raise Not_found in
diff --git a/toplevel/toplevellib.mllib b/toplevel/toplevellib.mllib
index eb459a906..886d1d2c8 100644
--- a/toplevel/toplevellib.mllib
+++ b/toplevel/toplevellib.mllib
@@ -4,9 +4,11 @@ Misc Tbl Config Clflags Terminfo Ccomp Warnings Consistbl
Location Longident Syntaxerr Parser
Lexer Parse Printast
-Unused_var Ident Path Primitive Types
-Btype Oprint Subst Predef Datarepr Env
-Typedtree Ctype Printtyp Includeclass Mtype Includecore
+Ident Path Primitive Types
+Btype Oprint Subst Predef Datarepr
+Cmi_format Env
+Typedtree
+Cmt_format Ctype Printtyp Includeclass Mtype Includecore
Includemod Parmatch Typetexp Stypes Typecore
Typedecl Typeclass Typemod
diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml
index f4ac1c82a..d65f94127 100644
--- a/toplevel/toploop.ml
+++ b/toplevel/toploop.ml
@@ -149,7 +149,7 @@ let load_lambda ppf lam =
(* Print the outcome of an evaluation *)
let rec pr_item env = function
- | Tsig_value(id, decl) :: rem ->
+ | Sig_value(id, decl) :: rem ->
let tree = Printtyp.tree_of_value_description id decl in
let valopt =
match decl.val_kind with
@@ -162,24 +162,24 @@ let rec pr_item env = function
Some v
in
Some (tree, valopt, rem)
- | Tsig_type(id, _, _) :: rem when Btype.is_row_name (Ident.name id) ->
+ | Sig_type(id, _, _) :: rem when Btype.is_row_name (Ident.name id) ->
pr_item env rem
- | Tsig_type(id, decl, rs) :: rem ->
+ | Sig_type(id, decl, rs) :: rem ->
let tree = Printtyp.tree_of_type_declaration id decl rs in
Some (tree, None, rem)
- | Tsig_exception(id, decl) :: rem ->
+ | Sig_exception(id, decl) :: rem ->
let tree = Printtyp.tree_of_exception_declaration id decl in
Some (tree, None, rem)
- | Tsig_module(id, mty, rs) :: rem ->
+ | Sig_module(id, mty, rs) :: rem ->
let tree = Printtyp.tree_of_module id mty rs in
Some (tree, None, rem)
- | Tsig_modtype(id, decl) :: rem ->
+ | Sig_modtype(id, decl) :: rem ->
let tree = Printtyp.tree_of_modtype_declaration id decl in
Some (tree, None, rem)
- | Tsig_class(id, decl, rs) :: cltydecl :: tydecl1 :: tydecl2 :: rem ->
+ | Sig_class(id, decl, rs) :: cltydecl :: tydecl1 :: tydecl2 :: rem ->
let tree = Printtyp.tree_of_class_declaration id decl rs in
Some (tree, None, rem)
- | Tsig_cltype(id, decl, rs) :: tydecl1 :: tydecl2 :: rem ->
+ | Sig_class_type(id, decl, rs) :: tydecl1 :: tydecl2 :: rem ->
let tree = Printtyp.tree_of_cltype_declaration id decl rs in
Some (tree, None, rem)
| _ -> None
@@ -231,8 +231,8 @@ let execute_phrase print_outcome ppf phr =
match res with
| Result v ->
if print_outcome then
- match str with
- | [Tstr_eval exp] ->
+ match str.str_items with
+ | [ { str_desc = Tstr_eval exp }] ->
let outv = outval_of_value newenv v exp.exp_type in
let ty = Printtyp.tree_of_type_scheme exp.exp_type in
Ophr_eval (outv, ty)
diff --git a/typing/btype.ml b/typing/btype.ml
index 769535bcb..ebe13d471 100644
--- a/typing/btype.ml
+++ b/typing/btype.ml
@@ -351,11 +351,11 @@ let unmark_class_signature sign =
let rec unmark_class_type =
function
- Tcty_constr (p, tyl, cty) ->
+ Cty_constr (p, tyl, cty) ->
List.iter unmark_type tyl; unmark_class_type cty
- | Tcty_signature sign ->
+ | Cty_signature sign ->
unmark_class_signature sign
- | Tcty_fun (_, ty, cty) ->
+ | Cty_fun (_, ty, cty) ->
unmark_type ty; unmark_class_type cty
diff --git a/typing/ctype.ml b/typing/ctype.ml
index 400a923d0..66d96a317 100644
--- a/typing/ctype.ml
+++ b/typing/ctype.ml
@@ -189,14 +189,14 @@ module TypePairs =
(**** unification mode ****)
-type unification_mode =
+type unification_mode =
| Expression (* unification in expression *)
| Pattern (* unification in pattern which may add local constraints *)
let umode = ref Expression
let generate_equations = ref false
-let set_mode mode ?(generate = (mode = Pattern)) f =
+let set_mode mode ?(generate = (mode = Pattern)) f =
let old_unification_mode = !umode
and old_gen = !generate_equations in
try
@@ -218,10 +218,10 @@ let in_current_module = function
| Path.Pident _ -> true
| Path.Pdot _ | Path.Papply _ -> false
-let in_pervasives p =
+let in_pervasives p =
try ignore (Env.find_type p Env.initial); true
with Not_found -> false
-
+
let is_datatype decl=
match decl.type_kind with
Type_record _ | Type_variant _ -> true
@@ -366,18 +366,18 @@ let hide_private_methods ty =
let rec signature_of_class_type =
function
- Tcty_constr (_, _, cty) -> signature_of_class_type cty
- | Tcty_signature sign -> sign
- | Tcty_fun (_, ty, cty) -> signature_of_class_type cty
+ Cty_constr (_, _, cty) -> signature_of_class_type cty
+ | Cty_signature sign -> sign
+ | Cty_fun (_, ty, cty) -> signature_of_class_type cty
let self_type cty =
repr (signature_of_class_type cty).cty_self
let rec class_type_arity =
function
- Tcty_constr (_, _, cty) -> class_type_arity cty
- | Tcty_signature _ -> 0
- | Tcty_fun (_, _, cty) -> 1 + class_type_arity cty
+ Cty_constr (_, _, cty) -> class_type_arity cty
+ | Cty_signature _ -> 0
+ | Cty_fun (_, _, cty) -> 1 + class_type_arity cty
(*******************************************)
@@ -519,13 +519,13 @@ let closed_type_decl decl =
Type_abstract ->
()
| Type_variant v ->
- List.iter
+ List.iter
(fun (_, tyl,ret_type_opt) ->
match ret_type_opt with
| Some _ -> ()
| None ->
List.iter closed_type tyl)
- v
+ v
| Type_record(r, rep) ->
List.iter (fun (_, _, ty) -> closed_type ty) r
end;
@@ -685,14 +685,15 @@ let forward_try_expand_once = (* Forward declaration *)
module M = struct type t let _ = (x : t list ref) end
(without this constraint, the type system would actually be unsound.)
*)
-let get_level env p =
+let get_level env p =
try
match (Env.find_type p env).type_newtype_level with
- | None -> Path.binding_time p
- | Some (x, _) -> x
- with Not_found ->
- (* no newtypes in predef *)
- Path.binding_time p
+ | None -> Path.binding_time p
+ | Some (x, _) -> x
+ with
+ | Not_found ->
+ (* no newtypes in predef *)
+ Path.binding_time p
let rec update_level env level ty =
let ty = repr ty in
@@ -1022,7 +1023,7 @@ let instance ?partial env sch =
let instance_def sch =
let ty = copy sch in
cleanup_types ();
- ty
+ ty
let instance_list env schl =
let env = gadt_env env in
@@ -1031,9 +1032,9 @@ let instance_list env schl =
tyl
let reified_var_counter = ref Vars.empty
-
-(* names given to new type constructors.
- Used for existential types and
+
+(* names given to new type constructors.
+ Used for existential types and
local constraints *)
let get_new_abstract_name s =
let index =
@@ -1042,7 +1043,7 @@ let get_new_abstract_name s =
reified_var_counter := Vars.add s index !reified_var_counter;
Printf.sprintf "%s#%d" s index
-let new_declaration newtype manifest =
+let new_declaration newtype manifest =
{
type_params = [];
type_arity = 0;
@@ -1060,7 +1061,7 @@ let instance_constructor ?in_pattern cstr =
begin match in_pattern with
| None -> ()
| Some (env, newtype_lev) ->
- let process existential =
+ let process existential =
let decl = new_declaration (Some (newtype_lev, newtype_lev)) None in
let name =
match repr existential with
@@ -1070,8 +1071,8 @@ let instance_constructor ?in_pattern cstr =
let (id, new_env) =
Env.enter_type (get_new_abstract_name name) decl !env in
env := new_env;
- let to_unify = newty (Tconstr (Path.Pident id,[],ref Mnil)) in
- link_type (copy existential) to_unify
+ let to_unify = newty (Tconstr (Path.Pident id,[],ref Mnil)) in
+ link_type (copy existential) to_unify
in
List.iter process cstr.cstr_existentials
end;
@@ -1110,18 +1111,18 @@ let instance_declaration decl =
let instance_class params cty =
let rec copy_class_type =
function
- Tcty_constr (path, tyl, cty) ->
- Tcty_constr (path, List.map copy tyl, copy_class_type cty)
- | Tcty_signature sign ->
- Tcty_signature
+ Cty_constr (path, tyl, cty) ->
+ Cty_constr (path, List.map copy tyl, copy_class_type cty)
+ | Cty_signature sign ->
+ Cty_signature
{cty_self = copy sign.cty_self;
cty_vars =
Vars.map (function (m, v, ty) -> (m, v, copy ty)) sign.cty_vars;
cty_concr = sign.cty_concr;
cty_inher =
List.map (fun (p,tl) -> (p, List.map copy tl)) sign.cty_inher}
- | Tcty_fun (l, ty, cty) ->
- Tcty_fun (l, copy ty, copy_class_type cty)
+ | Cty_fun (l, ty, cty) ->
+ Cty_fun (l, copy ty, copy_class_type cty)
in
let params' = List.map copy params in
let cty' = copy_class_type cty in
@@ -1348,7 +1349,7 @@ let expand_abbrev_gen kind find_type_expansion env ty =
| _ ->
assert false
-(* inside objects and variants we do not want to
+(* inside objects and variants we do not want to
use local constraints *)
let expand_abbrev ty =
expand_abbrev_gen Public (fun level -> Env.find_type_expansion ~level) ty
@@ -1794,26 +1795,26 @@ let deep_occur t0 ty =
let newtype_level = ref None
-let get_newtype_level () =
+let get_newtype_level () =
match !newtype_level with
| None -> assert false
| Some x -> x
-(* a local constraint can be added only if the rhs
+(* a local constraint can be added only if the rhs
of the constraint does not contain any Tvars.
They need to be removed using this function *)
let reify env t =
let newtype_level = get_newtype_level () in
- let create_fresh_constr lev name =
+ let create_fresh_constr lev name =
let decl = new_declaration (Some (newtype_level, newtype_level)) None in
let name = get_new_abstract_name name in
- let (id, new_env) = Env.enter_type name decl !env in
- let t = newty2 lev (Tconstr (Path.Pident id,[],ref Mnil)) in
+ let (id, new_env) = Env.enter_type name decl !env in
+ let t = newty2 lev (Tconstr (Path.Pident id,[],ref Mnil)) in
env := new_env;
t
in
let visited = ref TypeSet.empty in
- let rec iterator ty =
+ let rec iterator ty =
let ty = repr ty in
if TypeSet.mem ty !visited then () else begin
visited := TypeSet.add ty !visited;
@@ -1835,16 +1836,16 @@ let reify env t =
let is_abstract_newtype env p =
try
- let decl = Env.find_type p env in
+ let decl = Env.find_type p env in
not (decl.type_newtype_level = None) &&
decl.type_manifest = None &&
decl.type_kind = Type_abstract
with Not_found -> false
-(* mcomp type_pairs subst env t1 t2 does not raise an
+(* mcomp type_pairs subst env t1 t2 does not raise an
exception if it is possible that t1 and t2 are actually
- equal, assuming the types in type_pairs are equal and
- that the mapping subst holds.
+ equal, assuming the types in type_pairs are equal and
+ that the mapping subst holds.
Assumes that both t1 and t2 do not contain any tvars
and that both their objects and variants are closed
*)
@@ -1855,7 +1856,7 @@ let rec mcomp type_pairs subst env t1 t2 =
let t2 = repr t2 in
if t1 == t2 then () else
match (t1.desc, t2.desc) with
- | (Tvar _, _)
+ | (Tvar _, _)
| (_, Tvar _) ->
fatal_error "types should not include variables"
| (Tconstr (p1, [], _), Tconstr (p2, [], _)) when Path.same p1 p2 ->
@@ -1955,7 +1956,7 @@ and mcomp_row type_pairs subst env row1 row2 =
| _ -> ())
pairs
-and mcomp_type_decl type_pairs subst env p1 p2 tl1 tl2 =
+and mcomp_type_decl type_pairs subst env p1 p2 tl1 tl2 =
let non_aliased p decl =
in_pervasives p ||
in_current_module p && decl.type_newtype_level = None
@@ -1979,18 +1980,18 @@ and mcomp_type_decl type_pairs subst env p1 p2 tl1 tl2 =
|| is_datatype decl && non_aliased p2 decl' then raise (Unify [])
with Not_found -> ()
-and mcomp_type_option type_pairs subst env t t' =
+and mcomp_type_option type_pairs subst env t t' =
match t, t' with
None, None -> ()
- | Some t, Some t' -> mcomp type_pairs subst env t t'
- | _ -> raise (Unify [])
+ | Some t, Some t' -> mcomp type_pairs subst env t t'
+ | _ -> raise (Unify [])
-and mcomp_variant_description type_pairs subst env =
+and mcomp_variant_description type_pairs subst env =
let rec iter = fun x y ->
match x, y with
(name,mflag,t) :: xs, (name', mflag', t') :: ys ->
mcomp_type_option type_pairs subst env t t';
- if name = name' && mflag = mflag'
+ if name = name' && mflag = mflag'
then iter xs ys
else raise (Unify [])
| [],[] -> ()
@@ -1998,12 +1999,12 @@ and mcomp_variant_description type_pairs subst env =
in
iter
-and mcomp_record_description type_pairs subst env =
+and mcomp_record_description type_pairs subst env =
let rec iter = fun x y ->
- match x, y with
+ match x, y with
(name, mutable_flag, t) :: xs, (name', mutable_flag', t') :: ys ->
mcomp type_pairs subst env t t';
- if name = name' && mutable_flag = mutable_flag'
+ if name = name' && mutable_flag = mutable_flag'
then iter xs ys
else raise (Unify [])
| [], [] -> ()
@@ -2029,26 +2030,26 @@ let find_lowest_level ty =
let find_newtype_level env path =
try match (Env.find_type path env).type_newtype_level with
- | Some x -> x
+ Some x -> x
| None -> assert false
with Not_found -> assert false
-
+
let add_gadt_equation env source destination =
- let destination = duplicate_type destination in
+ let destination = duplicate_type destination in
let source_lev = find_newtype_level !env (Path.Pident source) in
let decl = new_declaration (Some source_lev) (Some destination) in
let newtype_level = get_newtype_level () in
env := Env.add_local_constraint source decl newtype_level !env;
- cleanup_abbrev ()
+ cleanup_abbrev ()
let unify_eq_set = TypePairs.create 11
let order_type_pair t1 t2 =
if t1.id <= t2.id then (t1, t2) else (t2, t1)
-let add_type_equality t1 t2 =
+let add_type_equality t1 t2 =
TypePairs.add unify_eq_set (order_type_pair t1 t2) ()
-
+
let unify_eq env t1 t2 =
t1 == t2 ||
match !umode with
@@ -2064,7 +2065,7 @@ let rec unify (env:Env.t ref) t1 t2 =
let t2 = repr t2 in
if unify_eq !env t1 t2 then () else
let reset_tracing = check_trace_gadt_instances !env in
-
+
try
type_changed := true;
begin match (t1.desc, t2.desc) with
@@ -2073,12 +2074,12 @@ let rec unify (env:Env.t ref) t1 t2 =
| (Tconstr _, Tvar _) when deep_occur t2 t1 ->
unify2 env t1 t2
| (Tvar _, _) ->
- occur !env t1 t2;
+ occur !env t1 t2;
occur_univar !env t2;
link_type t1 t2;
update_level !env t1.level t2
| (_, Tvar _) ->
- occur !env t2 t1;
+ occur !env t2 t1;
occur_univar !env t1;
link_type t2 t1;
update_level !env t2.level t1
@@ -2299,9 +2300,9 @@ and unify_fields env ty1 ty2 = (* Optimization *)
List.iter
(fun (n, k1, t1, k2, t2) ->
unify_kind k1 k2;
- try
+ try
if !trace_gadt_instances then update_level !env va.level t1;
- unify env t1 t2
+ unify env t1 t2
with Unify trace ->
raise (Unify ((newty (Tfield(n, k1, t1, newty Tnil)),
newty (Tfield(n, k2, t2, newty Tnil)))::trace)))
@@ -2494,7 +2495,7 @@ let unify_var env t1 t2 =
if reset_tracing then trace_gadt_instances := false;
with Unify trace ->
if reset_tracing then trace_gadt_instances := false;
- let expanded_trace = expand_trace env ((t1,t2)::trace) in
+ let expanded_trace = expand_trace env ((t1,t2)::trace) in
raise (Unify expanded_trace)
end
| _ ->
@@ -3078,16 +3079,16 @@ exception Failure of class_match_failure list
let rec moregen_clty trace type_pairs env cty1 cty2 =
try
match cty1, cty2 with
- Tcty_constr (_, _, cty1), _ ->
+ Cty_constr (_, _, cty1), _ ->
moregen_clty true type_pairs env cty1 cty2
- | _, Tcty_constr (_, _, cty2) ->
+ | _, Cty_constr (_, _, cty2) ->
moregen_clty true type_pairs env cty1 cty2
- | Tcty_fun (l1, ty1, cty1'), Tcty_fun (l2, ty2, cty2') when l1 = l2 ->
+ | Cty_fun (l1, ty1, cty1'), Cty_fun (l2, ty2, cty2') when l1 = l2 ->
begin try moregen true type_pairs env ty1 ty2 with Unify trace ->
raise (Failure [CM_Parameter_mismatch (expand_trace env trace)])
end;
moregen_clty false type_pairs env cty1' cty2'
- | Tcty_signature sign1, Tcty_signature sign2 ->
+ | Cty_signature sign1, Cty_signature sign2 ->
let ty1 = object_fields (repr sign1.cty_self) in
let ty2 = object_fields (repr sign2.cty_self) in
let (fields1, rest1) = flatten_fields ty1
@@ -3211,18 +3212,18 @@ let match_class_types ?(trace=true) env pat_sch subj_sch =
let rec equal_clty trace type_pairs subst env cty1 cty2 =
try
match cty1, cty2 with
- Tcty_constr (_, _, cty1), Tcty_constr (_, _, cty2) ->
+ Cty_constr (_, _, cty1), Cty_constr (_, _, cty2) ->
equal_clty true type_pairs subst env cty1 cty2
- | Tcty_constr (_, _, cty1), _ ->
+ | Cty_constr (_, _, cty1), _ ->
equal_clty true type_pairs subst env cty1 cty2
- | _, Tcty_constr (_, _, cty2) ->
+ | _, Cty_constr (_, _, cty2) ->
equal_clty true type_pairs subst env cty1 cty2
- | Tcty_fun (l1, ty1, cty1'), Tcty_fun (l2, ty2, cty2') when l1 = l2 ->
+ | Cty_fun (l1, ty1, cty1'), Cty_fun (l2, ty2, cty2') when l1 = l2 ->
begin try eqtype true type_pairs subst env ty1 ty2 with Unify trace ->
raise (Failure [CM_Parameter_mismatch (expand_trace env trace)])
end;
equal_clty false type_pairs subst env cty1' cty2'
- | Tcty_signature sign1, Tcty_signature sign2 ->
+ | Cty_signature sign1, Cty_signature sign2 ->
let ty1 = object_fields (repr sign1.cty_self) in
let ty2 = object_fields (repr sign2.cty_self) in
let (fields1, rest1) = flatten_fields ty1
@@ -3339,10 +3340,10 @@ let match_class_declarations env patt_params patt_type subj_params subj_type =
patt_params subj_params;
(* old code: equal_clty false type_pairs subst env patt_type subj_type; *)
equal_clty false type_pairs subst env
- (Tcty_signature sign1) (Tcty_signature sign2);
+ (Cty_signature sign1) (Cty_signature sign2);
(* Use moregeneral for class parameters, need to recheck everything to
keeps relationships (PR#4824) *)
- let clty_params = List.fold_right (fun ty cty -> Tcty_fun ("*",ty,cty)) in
+ let clty_params = List.fold_right (fun ty cty -> Cty_fun ("*",ty,cty)) in
match_class_types ~trace:false env
(clty_params patt_params patt_type) (clty_params subj_params subj_type)
with
@@ -4006,11 +4007,11 @@ let nondep_type_decl env mid id is_covariant decl =
| Type_variant cstrs ->
Type_variant
(List.map
- (fun (c, tl,ret_type_opt) ->
- let ret_type_opt =
+ (fun (c, tl,ret_type_opt) ->
+ let ret_type_opt =
may_map (nondep_type_rec env mid) ret_type_opt
in
- (c, List.map (nondep_type_rec env mid) tl,ret_type_opt))
+ (c, List.map (nondep_type_rec env mid) tl,ret_type_opt))
cstrs)
| Type_record(lbls, rep) ->
Type_record
@@ -4059,15 +4060,15 @@ let nondep_class_signature env id sign =
let rec nondep_class_type env id =
function
- Tcty_constr (p, _, cty) when Path.isfree id p ->
+ Cty_constr (p, _, cty) when Path.isfree id p ->
nondep_class_type env id cty
- | Tcty_constr (p, tyl, cty) ->
- Tcty_constr (p, List.map (nondep_type_rec env id) tyl,
+ | Cty_constr (p, tyl, cty) ->
+ Cty_constr (p, List.map (nondep_type_rec env id) tyl,
nondep_class_type env id cty)
- | Tcty_signature sign ->
- Tcty_signature (nondep_class_signature env id sign)
- | Tcty_fun (l, ty, cty) ->
- Tcty_fun (l, nondep_type_rec env id ty, nondep_class_type env id cty)
+ | Cty_signature sign ->
+ Cty_signature (nondep_class_signature env id sign)
+ | Cty_fun (l, ty, cty) ->
+ Cty_fun (l, nondep_type_rec env id ty, nondep_class_type env id cty)
let nondep_class_declaration env id decl =
assert (not (Path.isfree id decl.cty_path));
diff --git a/typing/ctype.mli b/typing/ctype.mli
index c0f165040..ccb04da44 100644
--- a/typing/ctype.mli
+++ b/typing/ctype.mli
@@ -227,7 +227,7 @@ val nondep_class_declaration:
Env.t -> Ident.t -> class_declaration -> class_declaration
(* Same for class declarations. *)
val nondep_cltype_declaration:
- Env.t -> Ident.t -> cltype_declaration -> cltype_declaration
+ Env.t -> Ident.t -> class_type_declaration -> class_type_declaration
(* Same for class type declarations. *)
val correct_abbrev: Env.t -> Path.t -> type_expr list -> type_expr -> unit
val cyclic_abbrev: Env.t -> Ident.t -> type_expr -> bool
diff --git a/typing/datarepr.ml b/typing/datarepr.ml
index d069ad307..5d4450427 100644
--- a/typing/datarepr.ml
+++ b/typing/datarepr.ml
@@ -110,7 +110,7 @@ let label_descrs ty_res lbls repres priv =
[] -> []
| (name, mut_flag, ty_arg) :: rest ->
let lbl =
- { lbl_name = name;
+ { lbl_name = Ident.name name;
lbl_res = ty_res;
lbl_arg = ty_arg;
lbl_mut = mut_flag;
diff --git a/typing/datarepr.mli b/typing/datarepr.mli
index bc1190d45..527fecb57 100644
--- a/typing/datarepr.mli
+++ b/typing/datarepr.mli
@@ -19,17 +19,17 @@ open Asttypes
open Types
val constructor_descrs:
- type_expr -> (string * type_expr list * type_expr option) list ->
- private_flag -> (string * constructor_description) list
+ type_expr -> (Ident.t * type_expr list * type_expr option) list ->
+ private_flag -> (Ident.t * constructor_description) list
val exception_descr:
Path.t -> exception_declaration -> constructor_description
val label_descrs:
- type_expr -> (string * mutable_flag * type_expr) list ->
+ type_expr -> (Ident.t * mutable_flag * type_expr) list ->
record_representation -> private_flag ->
- (string * label_description) list
+ (Ident.t * label_description) list
exception Constr_not_found
val find_constr_by_tag:
- constructor_tag -> (string * type_expr list * type_expr option) list ->
- string * type_expr list * type_expr option
+ constructor_tag -> (Ident.t * type_expr list * type_expr option) list ->
+ Ident.t * type_expr list * type_expr option
diff --git a/typing/env.ml b/typing/env.ml
index 7ec2028b6..5a216ee95 100644
--- a/typing/env.ml
+++ b/typing/env.ml
@@ -14,6 +14,7 @@
(* Environment handling *)
+open Cmi_format
open Config
open Misc
open Asttypes
@@ -49,15 +50,47 @@ let constructor_usages () =
let used_constructors : (string * Location.t * string, (constructor_usage -> unit)) Hashtbl.t = Hashtbl.create 16
type error =
- Not_an_interface of string
- | Wrong_version_interface of string * string
- | Corrupted_interface of string
| Illegal_renaming of string * string
| Inconsistent_import of string * string * string
| Need_recursive_types of string * string
exception Error of error
+module EnvLazy : sig
+ type ('a,'b) t
+
+ val force : ('a -> 'b) -> ('a,'b) t -> 'b
+ val create : 'a -> ('a,'b) t
+
+end = struct
+
+ type ('a,'b) t = ('a,'b) eval ref
+
+ and ('a,'b) eval =
+ Done of 'b
+ | Raise of exn
+ | Thunk of 'a
+
+ let force f x =
+ match !x with
+ Done x -> x
+ | Raise e -> raise e
+ | Thunk e ->
+ try
+ let y = f e in
+ x := Done y;
+ y
+ with e ->
+ x := Raise e;
+ raise e
+
+ let create x =
+ let x = ref (Thunk x) in
+ x
+
+end
+
+
type summary =
Env_empty
| Env_value of summary * Ident.t * value_description
@@ -66,7 +99,7 @@ type summary =
| Env_module of summary * Ident.t * module_type
| Env_modtype of summary * Ident.t * modtype_declaration
| Env_class of summary * Ident.t * class_declaration
- | Env_cltype of summary * Ident.t * cltype_declaration
+ | Env_cltype of summary * Ident.t * class_type_declaration
| Env_open of summary * Path.t
module EnvTbl =
@@ -107,22 +140,22 @@ module EnvTbl =
type t = {
values: (Path.t * value_description) EnvTbl.t;
annotations: (Path.t * Annot.ident) EnvTbl.t;
- constrs: constructor_description EnvTbl.t;
- labels: label_description EnvTbl.t;
+ constrs: (Path.t * constructor_description) EnvTbl.t;
+ labels: (Path.t * label_description) EnvTbl.t;
constrs_by_path: (Path.t * (constructor_description list)) EnvTbl.t;
types: (Path.t * type_declaration) EnvTbl.t;
modules: (Path.t * module_type) EnvTbl.t;
modtypes: (Path.t * modtype_declaration) EnvTbl.t;
components: (Path.t * module_components) EnvTbl.t;
classes: (Path.t * class_declaration) EnvTbl.t;
- cltypes: (Path.t * cltype_declaration) EnvTbl.t;
+ cltypes: (Path.t * class_type_declaration) EnvTbl.t;
summary: summary;
local_constraints: bool;
gadt_instances: (int * TypeSet.t ref) list;
in_signature: bool;
}
-and module_components = module_components_repr Lazy.t
+and module_components = (t * Subst.t * Path.t * Types.module_type, module_components_repr) EnvLazy.t
and module_components_repr =
Structure_comps of structure_components
@@ -133,14 +166,14 @@ and structure_components = {
mutable comp_annotations: (string, (Annot.ident * int)) Tbl.t;
mutable comp_constrs: (string, (constructor_description * int)) Tbl.t;
mutable comp_labels: (string, (label_description * int)) Tbl.t;
- mutable comp_constrs_by_path:
+ mutable comp_constrs_by_path:
(string, (constructor_description list * int)) Tbl.t;
mutable comp_types: (string, (type_declaration * int)) Tbl.t;
- mutable comp_modules: (string, (module_type Lazy.t * int)) Tbl.t;
+ mutable comp_modules: (string, ((Subst.t * Types.module_type,module_type) EnvLazy.t * int)) Tbl.t;
mutable comp_modtypes: (string, (modtype_declaration * int)) Tbl.t;
mutable comp_components: (string, (module_components * int)) Tbl.t;
mutable comp_classes: (string, (class_declaration * int)) Tbl.t;
- mutable comp_cltypes: (string, (cltype_declaration * int)) Tbl.t
+ mutable comp_cltypes: (string, (class_type_declaration * int)) Tbl.t
}
and functor_components = {
@@ -152,13 +185,15 @@ and functor_components = {
fcomp_cache: (Path.t, module_components) Hashtbl.t (* For memoization *)
}
+let subst_modtype_maker (subst, mty) = Subst.modtype subst mty
+
let empty = {
values = EnvTbl.empty; annotations = EnvTbl.empty; constrs = EnvTbl.empty;
- labels = EnvTbl.empty; types = EnvTbl.empty;
+ labels = EnvTbl.empty; types = EnvTbl.empty;
constrs_by_path = EnvTbl.empty;
modules = EnvTbl.empty; modtypes = EnvTbl.empty;
components = EnvTbl.empty; classes = EnvTbl.empty;
- cltypes = EnvTbl.empty;
+ cltypes = EnvTbl.empty;
summary = Env_empty; local_constraints = false; gadt_instances = [];
in_signature = false;
}
@@ -179,13 +214,9 @@ let is_ident = function
let is_local (p, _) = is_ident p
-let is_local_exn = function
- {cstr_tag = Cstr_exception (p, _)} -> is_ident p
- | _ -> false
-
let diff env1 env2 =
diff_keys is_local env1.values env2.values @
- diff_keys is_local_exn env1.constrs env2.constrs @
+ diff_keys is_local env1.constrs env2.constrs @
diff_keys is_local env1.modules env2.modules @
diff_keys is_local env1.classes env2.classes
@@ -194,6 +225,9 @@ let diff env1 env2 =
let components_of_module' =
ref ((fun env sub path mty -> assert false) :
t -> Subst.t -> Path.t -> module_type -> module_components)
+let components_of_module_maker' =
+ ref ((fun (env, sub, path, mty) -> assert false) :
+ t * Subst.t * Path.t * module_type -> module_components_repr)
let components_of_functor_appl' =
ref ((fun f p1 p2 -> assert false) :
functor_components -> Path.t -> Path.t -> module_components)
@@ -209,8 +243,6 @@ let current_unit = ref ""
(* Persistent structure descriptions *)
-type pers_flags = Rectypes
-
type pers_struct =
{ ps_name: string;
ps_sig: signature;
@@ -237,28 +269,15 @@ let check_consistency filename crcs =
(* Reading persistent structures from .cmi files *)
let read_pers_struct modname filename =
- let ic = open_in_bin filename in
- try
- let buffer = Misc.input_bytes ic (String.length cmi_magic_number) in
- if buffer <> cmi_magic_number then begin
- close_in ic;
- let pre_len = String.length cmi_magic_number - 3 in
- if String.sub buffer 0 pre_len = String.sub cmi_magic_number 0 pre_len then
- begin
- let msg = if buffer < cmi_magic_number then "an older" else "a newer" in
- raise (Error (Wrong_version_interface (filename, msg)))
- end else begin
- raise(Error(Not_an_interface filename))
- end
- end;
- let (name, sign) = input_value ic in
- let crcs = input_value ic in
- let flags = input_value ic in
- close_in ic;
- let comps =
+ let cmi = read_cmi filename in
+ let name = cmi.cmi_name in
+ let sign = cmi.cmi_sign in
+ let crcs = cmi.cmi_crcs in
+ let flags = cmi.cmi_flags in
+ let comps =
!components_of_module' empty Subst.identity
(Pident(Ident.create_persistent name))
- (Tmty_signature sign) in
+ (Mty_signature sign) in
let ps = { ps_name = name;
ps_sig = sign;
ps_comps = comps;
@@ -275,9 +294,6 @@ let read_pers_struct modname filename =
ps.ps_flags;
Hashtbl.add persistent_structures modname (Some ps);
ps
- with End_of_file | Failure _ ->
- close_in ic;
- raise(Error(Corrupted_interface(filename)))
let find_pers_struct name =
if name = "*predef*" then raise Not_found;
@@ -325,7 +341,7 @@ let rec find_module_descr path env =
else raise Not_found
end
| Pdot(p, s, pos) ->
- begin match Lazy.force(find_module_descr p env) with
+ begin match EnvLazy.force !components_of_module_maker' (find_module_descr p env) with
Structure_comps c ->
let (descr, pos) = Tbl.find s c.comp_components in
descr
@@ -333,7 +349,7 @@ let rec find_module_descr path env =
raise Not_found
end
| Papply(p1, p2) ->
- begin match Lazy.force(find_module_descr p1 env) with
+ begin match EnvLazy.force !components_of_module_maker' (find_module_descr p1 env) with
Functor_comps f ->
!components_of_functor_appl' f p1 p2
| Structure_comps c ->
@@ -346,7 +362,7 @@ let find proj1 proj2 path env =
let (p, data) = EnvTbl.find_same id (proj1 env)
in data
| Pdot(p, s, pos) ->
- begin match Lazy.force(find_module_descr p env) with
+ begin match EnvLazy.force !components_of_module_maker' (find_module_descr p env) with
Structure_comps c ->
let (data, pos) = Tbl.find s (proj2 c) in data
| Functor_comps f ->
@@ -357,6 +373,8 @@ let find proj1 proj2 path env =
let find_value =
find (fun env -> env.values) (fun sc -> sc.comp_values)
+and find_annot =
+ find (fun env -> env.annotations) (fun sc -> sc.comp_annotations)
and find_type =
find (fun env -> env.types) (fun sc -> sc.comp_types)
and find_constructors =
@@ -398,8 +416,8 @@ let find_type_expansion_opt path env =
let find_modtype_expansion path env =
match find_modtype path env with
- Tmodtype_abstract -> raise Not_found
- | Tmodtype_manifest mty -> mty
+ Modtype_abstract -> raise Not_found
+ | Modtype_manifest mty -> mty
let find_module path env =
match path with
@@ -410,13 +428,13 @@ let find_module path env =
with Not_found ->
if Ident.persistent id then
let ps = find_pers_struct (Ident.name id) in
- Tmty_signature(ps.ps_sig)
+ Mty_signature(ps.ps_sig)
else raise Not_found
end
| Pdot(p, s, pos) ->
- begin match Lazy.force (find_module_descr p env) with
+ begin match EnvLazy.force !components_of_module_maker' (find_module_descr p env) with
Structure_comps c ->
- let (data, pos) = Tbl.find s c.comp_modules in Lazy.force data
+ let (data, pos) = Tbl.find s c.comp_modules in EnvLazy.force subst_modtype_maker data
| Functor_comps f ->
raise Not_found
end
@@ -437,7 +455,7 @@ let rec lookup_module_descr lid env =
end
| Ldot(l, s) ->
let (p, descr) = lookup_module_descr l env in
- begin match Lazy.force descr with
+ begin match EnvLazy.force !components_of_module_maker' descr with
Structure_comps c ->
let (descr, pos) = Tbl.find s c.comp_components in
(Pdot(p, s, pos), descr)
@@ -447,7 +465,7 @@ let rec lookup_module_descr lid env =
| Lapply(l1, l2) ->
let (p1, desc1) = lookup_module_descr l1 env in
let (p2, mty2) = lookup_module l2 env in
- begin match Lazy.force desc1 with
+ begin match EnvLazy.force !components_of_module_maker' desc1 with
Functor_comps f ->
!check_modtype_inclusion env mty2 p2 f.fcomp_arg;
(Papply(p1, p2), !components_of_functor_appl' f p1 p2)
@@ -463,14 +481,14 @@ and lookup_module lid env =
with Not_found ->
if s = !current_unit then raise Not_found;
let ps = find_pers_struct s in
- (Pident(Ident.create_persistent s), Tmty_signature ps.ps_sig)
+ (Pident(Ident.create_persistent s), Mty_signature ps.ps_sig)
end
| Ldot(l, s) ->
let (p, descr) = lookup_module_descr l env in
- begin match Lazy.force descr with
+ begin match EnvLazy.force !components_of_module_maker' descr with
Structure_comps c ->
let (data, pos) = Tbl.find s c.comp_modules in
- (Pdot(p, s, pos), Lazy.force data)
+ (Pdot(p, s, pos), EnvLazy.force subst_modtype_maker data)
| Functor_comps f ->
raise Not_found
end
@@ -478,7 +496,7 @@ and lookup_module lid env =
let (p1, desc1) = lookup_module_descr l1 env in
let (p2, mty2) = lookup_module l2 env in
let p = Papply(p1, p2) in
- begin match Lazy.force desc1 with
+ begin match EnvLazy.force !components_of_module_maker' desc1 with
Functor_comps f ->
!check_modtype_inclusion env mty2 p2 f.fcomp_arg;
(p, Subst.modtype (Subst.add_module f.fcomp_param p2 f.fcomp_subst)
@@ -493,7 +511,7 @@ let lookup proj1 proj2 lid env =
EnvTbl.find_name s (proj1 env)
| Ldot(l, s) ->
let (p, desc) = lookup_module_descr l env in
- begin match Lazy.force desc with
+ begin match EnvLazy.force !components_of_module_maker' desc with
Structure_comps c ->
let (data, pos) = Tbl.find s (proj2 c) in
(Pdot(p, s, pos), data)
@@ -509,7 +527,7 @@ let lookup_simple proj1 proj2 lid env =
EnvTbl.find_name s (proj1 env)
| Ldot(l, s) ->
let (p, desc) = lookup_module_descr l env in
- begin match Lazy.force desc with
+ begin match EnvLazy.force !components_of_module_maker' desc with
Structure_comps c ->
let (data, pos) = Tbl.find s (proj2 c) in
data
@@ -526,9 +544,9 @@ let lookup_value =
let lookup_annot id e =
lookup (fun env -> env.annotations) (fun sc -> sc.comp_annotations) id e
and lookup_constructor =
- lookup_simple (fun env -> env.constrs) (fun sc -> sc.comp_constrs)
+ lookup (fun env -> env.constrs) (fun sc -> sc.comp_constrs)
and lookup_label =
- lookup_simple (fun env -> env.labels) (fun sc -> sc.comp_labels)
+ lookup (fun env -> env.labels) (fun sc -> sc.comp_labels)
and lookup_type =
lookup (fun env -> env.types) (fun sc -> sc.comp_types)
and lookup_modtype =
@@ -580,6 +598,13 @@ let lookup_type lid env =
mark_type_used (Longident.last lid) desc;
r
+(* [path] must be the path to a type, not to a module ! *)
+let path_subst_last path id =
+ match path with
+ Pident _ -> Pident id
+ | Pdot (p, name, pos) -> Pdot(p, Ident.name id, pos)
+ | Papply (p1, p2) -> assert false
+
let mark_type_path env path =
let decl = try find_type path env with Not_found -> assert false in
mark_type_used (Path.last path) decl
@@ -589,9 +614,9 @@ let ty_path = function
| _ -> assert false
let lookup_constructor lid env =
- let desc = lookup_constructor lid env in
+ let (_,desc) as c = lookup_constructor lid env in
mark_type_path env (ty_path desc.cstr_res);
- desc
+ c
let mark_constructor usage env name desc =
match desc.cstr_tag with
@@ -607,9 +632,9 @@ let mark_constructor usage env name desc =
mark_constructor_used usage ty_name ty_decl name
let lookup_label lid env =
- let desc = lookup_label lid env in
+ let (_,desc) as c = lookup_label lid env in
mark_type_path env (ty_path desc.lbl_res);
- desc
+ c
let lookup_class lid env =
let (_, desc) as r = lookup_class lid env in
@@ -674,7 +699,7 @@ let add_gadt_instance_chain env lv t =
let rec scrape_modtype mty env =
match mty with
- Tmty_ident path ->
+ Mty_ident path ->
begin try
scrape_modtype (find_modtype_expansion path env) env
with Not_found ->
@@ -685,7 +710,7 @@ let rec scrape_modtype mty env =
(* Compute constructor descriptions *)
let constructors_of_type ty_path decl =
- let handle_variants cstrs =
+ let handle_variants cstrs =
Datarepr.constructor_descrs
(newgenty (Tconstr(ty_path, decl.type_params, ref Mnil)))
cstrs decl.type_private
@@ -709,36 +734,36 @@ let labels_of_type ty_path decl =
let rec prefix_idents root pos sub = function
[] -> ([], sub)
- | Tsig_value(id, decl) :: rem ->
+ | Sig_value(id, decl) :: rem ->
let p = Pdot(root, Ident.name id, pos) in
let nextpos = match decl.val_kind with Val_prim _ -> pos | _ -> pos+1 in
let (pl, final_sub) = prefix_idents root nextpos sub rem in
(p::pl, final_sub)
- | Tsig_type(id, decl, _) :: rem ->
+ | Sig_type(id, decl, _) :: rem ->
let p = Pdot(root, Ident.name id, nopos) in
let (pl, final_sub) =
prefix_idents root pos (Subst.add_type id p sub) rem in
(p::pl, final_sub)
- | Tsig_exception(id, decl) :: rem ->
+ | Sig_exception(id, decl) :: rem ->
let p = Pdot(root, Ident.name id, pos) in
let (pl, final_sub) = prefix_idents root (pos+1) sub rem in
(p::pl, final_sub)
- | Tsig_module(id, mty, _) :: rem ->
+ | Sig_module(id, mty, _) :: rem ->
let p = Pdot(root, Ident.name id, pos) in
let (pl, final_sub) =
prefix_idents root (pos+1) (Subst.add_module id p sub) rem in
(p::pl, final_sub)
- | Tsig_modtype(id, decl) :: rem ->
+ | Sig_modtype(id, decl) :: rem ->
let p = Pdot(root, Ident.name id, nopos) in
let (pl, final_sub) =
prefix_idents root pos
- (Subst.add_modtype id (Tmty_ident p) sub) rem in
+ (Subst.add_modtype id (Mty_ident p) sub) rem in
(p::pl, final_sub)
- | Tsig_class(id, decl, _) :: rem ->
+ | Sig_class(id, decl, _) :: rem ->
let p = Pdot(root, Ident.name id, pos) in
let (pl, final_sub) = prefix_idents root (pos + 1) sub rem in
(p::pl, final_sub)
- | Tsig_cltype(id, decl, _) :: rem ->
+ | Sig_class_type(id, decl, _) :: rem ->
let p = Pdot(root, Ident.name id, nopos) in
let (pl, final_sub) = prefix_idents root pos sub rem in
(p::pl, final_sub)
@@ -746,11 +771,14 @@ let rec prefix_idents root pos sub = function
(* Compute structure descriptions *)
let rec components_of_module env sub path mty =
- lazy(match scrape_modtype mty env with
- Tmty_signature sg ->
+ EnvLazy.create (env, sub, path, mty)
+
+and components_of_module_maker (env, sub, path, mty) =
+ (match scrape_modtype mty env with
+ Mty_signature sg ->
let c =
{ comp_values = Tbl.empty; comp_annotations = Tbl.empty;
- comp_constrs = Tbl.empty;
+ comp_constrs = Tbl.empty;
comp_labels = Tbl.empty; comp_types = Tbl.empty;
comp_constrs_by_path = Tbl.empty;
comp_modules = Tbl.empty; comp_modtypes = Tbl.empty;
@@ -761,7 +789,7 @@ let rec components_of_module env sub path mty =
let pos = ref 0 in
List.iter2 (fun item path ->
match item with
- Tsig_value(id, decl) ->
+ Sig_value(id, decl) ->
let decl' = Subst.value_description sub decl in
c.comp_values <-
Tbl.add (Ident.name id) (decl', !pos) c.comp_values;
@@ -773,32 +801,32 @@ let rec components_of_module env sub path mty =
begin match decl.val_kind with
Val_prim _ -> () | _ -> incr pos
end
- | Tsig_type(id, decl, _) ->
+ | Sig_type(id, decl, _) ->
let decl' = Subst.type_declaration sub decl in
c.comp_types <-
Tbl.add (Ident.name id) (decl', nopos) c.comp_types;
let constructors = constructors_of_type path decl' in
c.comp_constrs_by_path <-
- Tbl.add (Ident.name id)
+ Tbl.add (Ident.name id)
(List.map snd constructors, nopos) c.comp_constrs_by_path;
List.iter
(fun (name, descr) ->
- c.comp_constrs <- Tbl.add name (descr, nopos) c.comp_constrs)
+ c.comp_constrs <- Tbl.add (Ident.name name) (descr, nopos) c.comp_constrs)
constructors;
let labels = labels_of_type path decl' in
List.iter
(fun (name, descr) ->
- c.comp_labels <- Tbl.add name (descr, nopos) c.comp_labels)
+ c.comp_labels <- Tbl.add (Ident.name name) (descr, nopos) c.comp_labels)
(labels);
env := store_type_infos id path decl !env
- | Tsig_exception(id, decl) ->
+ | Sig_exception(id, decl) ->
let decl' = Subst.exception_declaration sub decl in
let cstr = Datarepr.exception_descr path decl' in
c.comp_constrs <-
Tbl.add (Ident.name id) (cstr, !pos) c.comp_constrs;
incr pos
- | Tsig_module(id, mty, _) ->
- let mty' = lazy (Subst.modtype sub mty) in
+ | Sig_module(id, mty, _) ->
+ let mty' = EnvLazy.create (sub, mty) in
c.comp_modules <-
Tbl.add (Ident.name id) (mty', !pos) c.comp_modules;
let comps = components_of_module !env sub path mty in
@@ -806,23 +834,23 @@ let rec components_of_module env sub path mty =
Tbl.add (Ident.name id) (comps, !pos) c.comp_components;
env := store_module id path mty !env;
incr pos
- | Tsig_modtype(id, decl) ->
+ | Sig_modtype(id, decl) ->
let decl' = Subst.modtype_declaration sub decl in
c.comp_modtypes <-
Tbl.add (Ident.name id) (decl', nopos) c.comp_modtypes;
env := store_modtype id path decl !env
- | Tsig_class(id, decl, _) ->
+ | Sig_class(id, decl, _) ->
let decl' = Subst.class_declaration sub decl in
c.comp_classes <-
Tbl.add (Ident.name id) (decl', !pos) c.comp_classes;
incr pos
- | Tsig_cltype(id, decl, _) ->
+ | Sig_class_type(id, decl, _) ->
let decl' = Subst.cltype_declaration sub decl in
c.comp_cltypes <-
Tbl.add (Ident.name id) (decl', !pos) c.comp_cltypes)
sg pl;
Structure_comps c
- | Tmty_functor(param, ty_arg, ty_res) ->
+ | Mty_functor(param, ty_arg, ty_res) ->
Functor_comps {
fcomp_param = param;
(* fcomp_arg must be prefixed eagerly, because it is interpreted
@@ -833,11 +861,11 @@ let rec components_of_module env sub path mty =
fcomp_env = env;
fcomp_subst = sub;
fcomp_cache = Hashtbl.create 17 }
- | Tmty_ident p ->
+ | Mty_ident p ->
Structure_comps {
comp_values = Tbl.empty; comp_annotations = Tbl.empty;
- comp_constrs = Tbl.empty;
- comp_labels = Tbl.empty;
+ comp_constrs = Tbl.empty;
+ comp_labels = Tbl.empty;
comp_types = Tbl.empty; comp_constrs_by_path = Tbl.empty;
comp_modules = Tbl.empty; comp_modtypes = Tbl.empty;
comp_components = Tbl.empty; comp_classes = Tbl.empty;
@@ -882,6 +910,7 @@ and store_type id path info env =
let ty = Ident.name id in
List.iter
(fun (c, _) ->
+ let c = Ident.name c in
let k = (ty, loc, c) in
if not (Hashtbl.mem used_constructors k) then
let used = constructor_usages () in
@@ -902,17 +931,17 @@ and store_type id path info env =
constrs =
List.fold_right
(fun (name, descr) constrs ->
- EnvTbl.add (Ident.create name) descr constrs)
- constructors
+ EnvTbl.add name (path_subst_last path name, descr) constrs)
+ constructors
env.constrs;
- constrs_by_path =
- EnvTbl.add id
+ constrs_by_path =
+ EnvTbl.add id
(path,List.map snd constructors) env.constrs_by_path;
labels =
List.fold_right
(fun (name, descr) labels ->
- EnvTbl.add (Ident.create name) descr labels)
+ EnvTbl.add name (path_subst_last path name, descr) labels)
labels
env.labels;
types = EnvTbl.add id (path, info) env.types;
@@ -950,7 +979,8 @@ and store_exception id path decl env =
end;
end;
{ env with
- constrs = EnvTbl.add id (Datarepr.exception_descr path decl) env.constrs;
+ constrs = EnvTbl.add id (path_subst_last path id,
+ Datarepr.exception_descr path decl) env.constrs;
summary = Env_exception(env.summary, id, decl) }
and store_module id path mty env =
@@ -994,7 +1024,8 @@ let components_of_functor_appl f p1 p2 =
let _ =
components_of_module' := components_of_module;
- components_of_functor_appl' := components_of_functor_appl
+ components_of_functor_appl' := components_of_functor_appl;
+ components_of_module_maker' := components_of_module_maker
(* Insertion of bindings by identifier *)
@@ -1048,13 +1079,13 @@ and enter_cltype = enter store_cltype
let add_item comp env =
match comp with
- Tsig_value(id, decl) -> add_value id decl env
- | Tsig_type(id, decl, _) -> add_type id decl env
- | Tsig_exception(id, decl) -> add_exception id decl env
- | Tsig_module(id, mty, _) -> add_module id mty env
- | Tsig_modtype(id, decl) -> add_modtype id decl env
- | Tsig_class(id, decl, _) -> add_class id decl env
- | Tsig_cltype(id, decl, _) -> add_cltype id decl env
+ Sig_value(id, decl) -> add_value id decl env
+ | Sig_type(id, decl, _) -> add_type id decl env
+ | Sig_exception(id, decl) -> add_exception id decl env
+ | Sig_module(id, mty, _) -> add_module id mty env
+ | Sig_modtype(id, decl) -> add_modtype id decl env
+ | Sig_class(id, decl, _) -> add_class id decl env
+ | Sig_class_type(id, decl, _) -> add_cltype id decl env
let rec add_signature sg env =
match sg with
@@ -1071,25 +1102,25 @@ let open_signature root sg env =
List.fold_left2
(fun env item p ->
match item with
- Tsig_value(id, decl) ->
+ Sig_value(id, decl) ->
let e1 = store_value (Ident.hide id) p
(Subst.value_description sub decl) env
in store_annot (Ident.hide id) p (Annot.Iref_external) e1
- | Tsig_type(id, decl, _) ->
+ | Sig_type(id, decl, _) ->
store_type (Ident.hide id) p
(Subst.type_declaration sub decl) env
- | Tsig_exception(id, decl) ->
+ | Sig_exception(id, decl) ->
store_exception (Ident.hide id) p
(Subst.exception_declaration sub decl) env
- | Tsig_module(id, mty, _) ->
+ | Sig_module(id, mty, _) ->
store_module (Ident.hide id) p (Subst.modtype sub mty) env
- | Tsig_modtype(id, decl) ->
+ | Sig_modtype(id, decl) ->
store_modtype (Ident.hide id) p
(Subst.modtype_declaration sub decl) env
- | Tsig_class(id, decl, _) ->
+ | Sig_class(id, decl, _) ->
store_class (Ident.hide id) p
(Subst.class_declaration sub decl) env
- | Tsig_cltype(id, decl, _) ->
+ | Sig_class_type(id, decl, _) ->
store_cltype (Ident.hide id) p
(Subst.cltype_declaration sub decl) env)
env sg pl in
@@ -1140,29 +1171,29 @@ let save_signature_with_imports sg modname filename imports =
let sg = Subst.signature (Subst.for_saving Subst.identity) sg in
let oc = open_out_bin filename in
try
- output_string oc cmi_magic_number;
- output_value oc (modname, sg);
- flush oc;
- let crc = Digest.file filename in
- let crcs = (modname, crc) :: imports in
- output_value oc crcs;
- let flags = if !Clflags.recursive_types then [Rectypes] else [] in
- output_value oc flags;
+ let cmi = {
+ cmi_name = modname;
+ cmi_sign = sg;
+ cmi_crcs = imports;
+ cmi_flags = if !Clflags.recursive_types then [Rectypes] else [];
+ } in
+ let crc = output_cmi filename oc cmi in
close_out oc;
(* Enter signature in persistent table so that imported_unit()
will also return its crc *)
let comps =
components_of_module empty Subst.identity
- (Pident(Ident.create_persistent modname)) (Tmty_signature sg) in
+ (Pident(Ident.create_persistent modname)) (Mty_signature sg) in
let ps =
{ ps_name = modname;
ps_sig = sg;
ps_comps = comps;
- ps_crcs = crcs;
+ ps_crcs = (cmi.cmi_name, crc) :: imports;
ps_filename = filename;
- ps_flags = flags } in
+ ps_flags = cmi.cmi_flags } in
Hashtbl.add persistent_structures modname (Some ps);
- Consistbl.set crc_units modname crc filename
+ Consistbl.set crc_units modname crc filename;
+ sg
with exn ->
close_out oc;
remove_file filename;
@@ -1171,6 +1202,75 @@ let save_signature_with_imports sg modname filename imports =
let save_signature sg modname filename =
save_signature_with_imports sg modname filename (imported_units())
+(* Folding on environments *)
+let ident_tbl_fold f t acc =
+ List.fold_right
+ (fun key acc -> f key (EnvTbl.find_same_not_using key t) acc)
+ (EnvTbl.keys t)
+ acc
+
+let find_all proj1 proj2 f lid env acc =
+ match lid with
+ | None ->
+ ident_tbl_fold
+ (fun id (p, data) acc -> f (Ident.name id) p data acc)
+ (proj1 env) acc
+ | Some l ->
+ let p, desc = lookup_module_descr l env in
+ begin match EnvLazy.force components_of_module_maker desc with
+ Structure_comps c ->
+ Tbl.fold
+ (fun s (data, pos) acc -> f s (Pdot (p, s, pos)) data acc)
+ (proj2 c) acc
+ | Functor_comps _ ->
+ raise Not_found
+ end
+
+let fold_modules f lid env acc =
+ match lid with
+ | None ->
+ let acc =
+ ident_tbl_fold
+ (fun id (p, data) acc -> f (Ident.name id) p data acc)
+ env.modules
+ acc
+ in
+ Hashtbl.fold
+ (fun name ps acc ->
+ match ps with
+ None -> acc
+ | Some ps ->
+ f name (Pident(Ident.create_persistent name)) (Mty_signature ps.ps_sig) acc)
+ persistent_structures
+ acc
+ | Some l ->
+ let p, desc = lookup_module_descr l env in
+ begin match EnvLazy.force components_of_module_maker desc with
+ Structure_comps c ->
+ Tbl.fold
+ (fun s (data, pos) acc -> f s (Pdot (p, s, pos)) (EnvLazy.force subst_modtype_maker data) acc)
+ c.comp_modules
+ acc
+ | Functor_comps _ ->
+ raise Not_found
+ end
+
+let fold_values f =
+ find_all (fun env -> env.values) (fun sc -> sc.comp_values) f
+and fold_constructors f =
+ find_all (fun env -> env.constrs) (fun sc -> sc.comp_constrs) f
+and fold_labels f =
+ find_all (fun env -> env.labels) (fun sc -> sc.comp_labels) f
+and fold_types f =
+ find_all (fun env -> env.types) (fun sc -> sc.comp_types) f
+and fold_modtypes f =
+ find_all (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) f
+and fold_classs f =
+ find_all (fun env -> env.classes) (fun sc -> sc.comp_classes) f
+and fold_cltypes f =
+ find_all (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) f
+
+
(* Make the initial environment *)
let initial = Predef.build_initial_env add_type add_exception empty
@@ -1184,13 +1284,6 @@ let summary env = env.summary
open Format
let report_error ppf = function
- | Not_an_interface filename -> fprintf ppf
- "%a@ is not a compiled interface" Location.print_filename filename
- | Wrong_version_interface (filename, older_newer) -> fprintf ppf
- "%a@ is not a compiled interface for this version of OCaml.@.\
- It seems to be for %s version of OCaml." Location.print_filename filename older_newer
- | Corrupted_interface filename -> fprintf ppf
- "Corrupted compiled interface@ %a" Location.print_filename filename
| Illegal_renaming(modname, filename) -> fprintf ppf
"Wrong file naming: %a@ contains the compiled interface for@ %s"
Location.print_filename filename modname
diff --git a/typing/env.mli b/typing/env.mli
index 599daf88e..44d0491ed 100644
--- a/typing/env.mli
+++ b/typing/env.mli
@@ -16,6 +16,17 @@
open Types
+type summary =
+ Env_empty
+ | Env_value of summary * Ident.t * value_description
+ | Env_type of summary * Ident.t * type_declaration
+ | Env_exception of summary * Ident.t * exception_declaration
+ | Env_module of summary * Ident.t * module_type
+ | Env_modtype of summary * Ident.t * modtype_declaration
+ | Env_class of summary * Ident.t * class_declaration
+ | Env_cltype of summary * Ident.t * class_type_declaration
+ | Env_open of summary * Path.t
+
type t
val empty: t
@@ -25,12 +36,13 @@ val diff: t -> t -> Ident.t list
(* Lookup by paths *)
val find_value: Path.t -> t -> value_description
+val find_annot: Path.t -> t -> Annot.ident
val find_type: Path.t -> t -> type_declaration
val find_constructors: Path.t -> t -> constructor_description list
val find_module: Path.t -> t -> module_type
val find_modtype: Path.t -> t -> modtype_declaration
val find_class: Path.t -> t -> class_declaration
-val find_cltype: Path.t -> t -> cltype_declaration
+val find_cltype: Path.t -> t -> class_type_declaration
val find_type_expansion:
?level:int -> Path.t -> t -> type_expr list * type_expr * int option
@@ -50,13 +62,13 @@ val add_gadt_instance_chain: t -> int -> type_expr -> unit
val lookup_value: Longident.t -> t -> Path.t * value_description
val lookup_annot: Longident.t -> t -> Path.t * Annot.ident
-val lookup_constructor: Longident.t -> t -> constructor_description
-val lookup_label: Longident.t -> t -> label_description
+val lookup_constructor: Longident.t -> t -> Path.t * constructor_description
+val lookup_label: Longident.t -> t -> Path.t * label_description
val lookup_type: Longident.t -> t -> Path.t * type_declaration
val lookup_module: Longident.t -> t -> Path.t * module_type
val lookup_modtype: Longident.t -> t -> Path.t * modtype_declaration
val lookup_class: Longident.t -> t -> Path.t * class_declaration
-val lookup_cltype: Longident.t -> t -> Path.t * cltype_declaration
+val lookup_cltype: Longident.t -> t -> Path.t * class_type_declaration
(* Insertion by identifier *)
@@ -67,7 +79,7 @@ val add_exception: Ident.t -> exception_declaration -> t -> t
val add_module: Ident.t -> module_type -> t -> t
val add_modtype: Ident.t -> modtype_declaration -> t -> t
val add_class: Ident.t -> class_declaration -> t -> t
-val add_cltype: Ident.t -> cltype_declaration -> t -> t
+val add_cltype: Ident.t -> class_type_declaration -> t -> t
val add_local_constraint: Ident.t -> type_declaration -> int -> t -> t
(* Insertion of all fields of a signature. *)
@@ -89,7 +101,7 @@ val enter_exception: string -> exception_declaration -> t -> Ident.t * t
val enter_module: string -> module_type -> t -> Ident.t * t
val enter_modtype: string -> modtype_declaration -> t -> Ident.t * t
val enter_class: string -> class_declaration -> t -> Ident.t * t
-val enter_cltype: string -> cltype_declaration -> t -> Ident.t * t
+val enter_cltype: string -> class_type_declaration -> t -> Ident.t * t
(* Initialize the cache of in-core module interfaces. *)
val reset_cache: unit -> unit
@@ -102,10 +114,10 @@ val set_unit_name: string -> unit
val read_signature: string -> string -> signature
(* Arguments: module name, file name. Results: signature. *)
-val save_signature: signature -> string -> string -> unit
+val save_signature: signature -> string -> string -> signature
(* Arguments: signature, module name, file name. *)
val save_signature_with_imports:
- signature -> string -> string -> (string * Digest.t) list -> unit
+ signature -> string -> string -> (string * Digest.t) list -> signature
(* Arguments: signature, module name, file name,
imported units with their CRCs. *)
@@ -124,25 +136,11 @@ val crc_units: Consistbl.t
(* Summaries -- compact representation of an environment, to be
exported in debugging information. *)
-type summary =
- Env_empty
- | Env_value of summary * Ident.t * value_description
- | Env_type of summary * Ident.t * type_declaration
- | Env_exception of summary * Ident.t * exception_declaration
- | Env_module of summary * Ident.t * module_type
- | Env_modtype of summary * Ident.t * modtype_declaration
- | Env_class of summary * Ident.t * class_declaration
- | Env_cltype of summary * Ident.t * cltype_declaration
- | Env_open of summary * Path.t
-
val summary: t -> summary
(* Error report *)
type error =
- Not_an_interface of string
- | Wrong_version_interface of string * string
- | Corrupted_interface of string
| Illegal_renaming of string * string
| Inconsistent_import of string * string * string
| Need_recursive_types of string * string
@@ -172,3 +170,36 @@ val check_modtype_inclusion:
(t -> module_type -> Path.t -> module_type -> unit) ref
(* Forward declaration to break mutual recursion with Typecore. *)
val add_delayed_check_forward: ((unit -> unit) -> unit) ref
+
+(** Folding over all identifiers (for analysis purpose) *)
+
+val fold_values:
+ (string -> Path.t -> Types.value_description -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+val fold_types:
+ (string -> Path.t -> Types.type_declaration -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+val fold_constructors:
+ (string -> Path.t -> Types.constructor_description -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+val fold_labels:
+ (string -> Path.t -> Types.label_description -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+
+(** Persistent structures are only traversed if they are already loaded. *)
+val fold_modules:
+ (string -> Path.t -> Types.module_type -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+
+val fold_modtypes:
+ (string -> Path.t -> Types.modtype_declaration -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+val fold_classs:
+ (string -> Path.t -> Types.class_declaration -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+val fold_cltypes:
+ (string -> Path.t -> Types.class_type_declaration -> 'a -> 'a) ->
+ Longident.t option -> t -> 'a -> 'a
+
+
+
diff --git a/typing/ident.mli b/typing/ident.mli
index e26490a9c..f9e575421 100644
--- a/typing/ident.mli
+++ b/typing/ident.mli
@@ -14,7 +14,7 @@
(* Identifiers (unique names) *)
-type t
+type t = { stamp: int; name: string; mutable flags: int }
val create: string -> t
val create_persistent: string -> t
diff --git a/typing/includeclass.mli b/typing/includeclass.mli
index b98960f82..27784e960 100644
--- a/typing/includeclass.mli
+++ b/typing/includeclass.mli
@@ -21,7 +21,7 @@ open Format
val class_types:
Env.t -> class_type -> class_type -> class_match_failure list
val class_type_declarations:
- Env.t -> cltype_declaration -> cltype_declaration ->
+ Env.t -> class_type_declaration -> class_type_declaration ->
class_match_failure list
val class_declarations:
Env.t -> class_declaration -> class_declaration ->
diff --git a/typing/includecore.ml b/typing/includecore.ml
index 558cfe7de..68f848576 100644
--- a/typing/includecore.ml
+++ b/typing/includecore.ml
@@ -117,11 +117,11 @@ type type_mismatch =
| Constraint
| Manifest
| Variance
- | Field_type of string
- | Field_mutable of string
- | Field_arity of string
- | Field_names of int * string * string
- | Field_missing of bool * string
+ | Field_type of Ident.t
+ | Field_mutable of Ident.t
+ | Field_arity of Ident.t
+ | Field_names of int * Ident.t * Ident.t
+ | Field_missing of bool * Ident.t
| Record_representation of bool
let nth n =
@@ -140,17 +140,17 @@ let report_type_mismatch0 first second decl ppf err =
| Manifest -> ()
| Variance -> pr "Their variances do not agree"
| Field_type s ->
- pr "The types for field %s are not equal" s
+ pr "The types for field %s are not equal" (Ident.name s)
| Field_mutable s ->
- pr "The mutability of field %s is different" s
+ pr "The mutability of field %s is different" (Ident.name s)
| Field_arity s ->
- pr "The arities for field %s differ" s
+ pr "The arities for field %s differ" (Ident.name s)
| Field_names (n, name1, name2) ->
pr "Their %s fields have different names, %s and %s"
- (nth n) name1 name2
+ (nth n) (Ident.name name1) (Ident.name name2)
| Field_missing (b, s) ->
pr "The field %s is only present in %s %s"
- s (if b then second else first) decl
+ (Ident.name s) (if b then second else first) decl
| Record_representation b ->
pr "Their internal representations differ:@ %s %s %s"
(if b then second else first) decl
@@ -168,31 +168,31 @@ let rec compare_variants env decl1 decl2 n cstrs1 cstrs2 =
| [], (cstr2,_,_)::_ -> [Field_missing (true, cstr2)]
| (cstr1,_,_)::_, [] -> [Field_missing (false, cstr1)]
| (cstr1, arg1, ret1)::rem1, (cstr2, arg2,ret2)::rem2 ->
- if cstr1 <> cstr2 then [Field_names (n, cstr1, cstr2)] else
+ if Ident.name cstr1 <> Ident.name cstr2 then [Field_names (n, cstr1, cstr2)] else
if List.length arg1 <> List.length arg2 then [Field_arity cstr1] else
match ret1, ret2 with
- | Some r1, Some r2 when not (Ctype.equal env true [r1] [r2]) ->
+ | Some r1, Some r2 when not (Ctype.equal env true [r1] [r2]) ->
[Field_type cstr1]
| Some _, None | None, Some _ ->
[Field_type cstr1]
- | _ ->
+ | _ ->
if Misc.for_all2
(fun ty1 ty2 ->
Ctype.equal env true (ty1::decl1.type_params)
(ty2::decl2.type_params))
- (arg1) (arg2)
- then
+ (arg1) (arg2)
+ then
compare_variants env decl1 decl2 (n+1) rem1 rem2
else [Field_type cstr1]
-
-
+
+
let rec compare_records env decl1 decl2 n labels1 labels2 =
match labels1, labels2 with
[], [] -> []
| [], (lab2,_,_)::_ -> [Field_missing (true, lab2)]
| (lab1,_,_)::_, [] -> [Field_missing (false, lab1)]
| (lab1, mut1, arg1)::rem1, (lab2, mut2, arg2)::rem2 ->
- if lab1 <> lab2 then [Field_names (n, lab1, lab2)] else
+ if Ident.name lab1 <> Ident.name lab2 then [Field_names (n, lab1, lab2)] else
if mut1 <> mut2 then [Field_mutable lab1] else
if Ctype.equal env true (arg1::decl1.type_params)
(arg2::decl2.type_params)
@@ -207,7 +207,7 @@ let type_declarations ?(equality = false) env name decl1 id decl2 =
| (Type_variant cstrs1, Type_variant cstrs2) ->
let mark cstrs usage name decl =
List.iter
- (fun (c, _, _) -> Env.mark_constructor_used usage name decl c)
+ (fun (c, _, _) -> Env.mark_constructor_used usage name decl (Ident.name c))
cstrs
in
let usage =
diff --git a/typing/includecore.mli b/typing/includecore.mli
index 726325440..8ddfcb163 100644
--- a/typing/includecore.mli
+++ b/typing/includecore.mli
@@ -14,8 +14,8 @@
(* Inclusion checks for the core language *)
-open Types
open Typedtree
+open Types
exception Dont_match
@@ -26,11 +26,11 @@ type type_mismatch =
| Constraint
| Manifest
| Variance
- | Field_type of string
- | Field_mutable of string
- | Field_arity of string
- | Field_names of int * string * string
- | Field_missing of bool * string
+ | Field_type of Ident.t
+ | Field_mutable of Ident.t
+ | Field_arity of Ident.t
+ | Field_names of int * Ident.t * Ident.t
+ | Field_missing of bool * Ident.t
| Record_representation of bool
val value_descriptions:
diff --git a/typing/includemod.ml b/typing/includemod.ml
index bc981ddef..b46e919af 100644
--- a/typing/includemod.ml
+++ b/typing/includemod.ml
@@ -16,8 +16,8 @@
open Misc
open Path
-open Types
open Typedtree
+open Types
type symptom =
Missing_field of Ident.t
@@ -31,7 +31,7 @@ type symptom =
| Modtype_permutation
| Interface_mismatch of string * string
| Class_type_declarations of
- Ident.t * cltype_declaration * cltype_declaration *
+ Ident.t * class_type_declaration * class_type_declaration *
Ctype.class_match_failure list
| Class_declarations of
Ident.t * class_declaration * class_declaration *
@@ -112,13 +112,13 @@ type field_desc =
| Field_classtype of string
let item_ident_name = function
- Tsig_value(id, _) -> (id, Field_value(Ident.name id))
- | Tsig_type(id, _, _) -> (id, Field_type(Ident.name id))
- | Tsig_exception(id, _) -> (id, Field_exception(Ident.name id))
- | Tsig_module(id, _, _) -> (id, Field_module(Ident.name id))
- | Tsig_modtype(id, _) -> (id, Field_modtype(Ident.name id))
- | Tsig_class(id, _, _) -> (id, Field_class(Ident.name id))
- | Tsig_cltype(id, _, _) -> (id, Field_classtype(Ident.name id))
+ Sig_value(id, _) -> (id, Field_value(Ident.name id))
+ | Sig_type(id, _, _) -> (id, Field_type(Ident.name id))
+ | Sig_exception(id, _) -> (id, Field_exception(Ident.name id))
+ | Sig_module(id, _, _) -> (id, Field_module(Ident.name id))
+ | Sig_modtype(id, _) -> (id, Field_modtype(Ident.name id))
+ | Sig_class(id, _, _) -> (id, Field_class(Ident.name id))
+ | Sig_class_type(id, _, _) -> (id, Field_classtype(Ident.name id))
(* Simplify a structure coercion *)
@@ -148,13 +148,13 @@ let rec modtypes env cxt subst mty1 mty2 =
and try_modtypes env cxt subst mty1 mty2 =
match (mty1, mty2) with
- (_, Tmty_ident p2) ->
+ (_, Mty_ident p2) ->
try_modtypes2 env cxt mty1 (Subst.modtype subst mty2)
- | (Tmty_ident p1, _) ->
+ | (Mty_ident p1, _) ->
try_modtypes env cxt subst (expand_module_path env cxt p1) mty2
- | (Tmty_signature sig1, Tmty_signature sig2) ->
+ | (Mty_signature sig1, Mty_signature sig2) ->
signatures env cxt subst sig1 sig2
- | (Tmty_functor(param1, arg1, res1), Tmty_functor(param2, arg2, res2)) ->
+ | (Mty_functor(param1, arg1, res1), Mty_functor(param2, arg2, res2)) ->
let arg2' = Subst.modtype subst arg2 in
let cc_arg = modtypes env (Arg param1::cxt) Subst.identity arg2' arg1 in
let cc_res =
@@ -170,9 +170,9 @@ and try_modtypes env cxt subst mty1 mty2 =
and try_modtypes2 env cxt mty1 mty2 =
(* mty2 is an identifier *)
match (mty1, mty2) with
- (Tmty_ident p1, Tmty_ident p2) when Path.same p1 p2 ->
+ (Mty_ident p1, Mty_ident p2) when Path.same p1 p2 ->
Tcoerce_none
- | (_, Tmty_ident p2) ->
+ | (_, Mty_ident p2) ->
try_modtypes env cxt Subst.identity mty1 (expand_module_path env cxt p2)
| (_, _) ->
assert false
@@ -191,14 +191,14 @@ and signatures env cxt subst sig1 sig2 =
let (id, name) = item_ident_name item in
let nextpos =
match item with
- Tsig_value(_,{val_kind = Val_prim _})
- | Tsig_type(_,_,_)
- | Tsig_modtype(_,_)
- | Tsig_cltype(_,_,_) -> pos
- | Tsig_value(_,_)
- | Tsig_exception(_,_)
- | Tsig_module(_,_,_)
- | Tsig_class(_, _,_) -> pos+1 in
+ Sig_value(_,{val_kind = Val_prim _})
+ | Sig_type(_,_,_)
+ | Sig_modtype(_,_)
+ | Sig_class_type(_,_,_) -> pos
+ | Sig_value(_,_)
+ | Sig_exception(_,_)
+ | Sig_module(_,_,_)
+ | Sig_class(_, _,_) -> pos+1 in
build_component_table nextpos
(Tbl.add name (id, item, pos) tbl) rem in
let comps1 =
@@ -218,7 +218,7 @@ and signatures env cxt subst sig1 sig2 =
let (id2, name2) = item_ident_name item2 in
let name2, report =
match item2, name2 with
- Tsig_type (_, {type_manifest=None}, _), Field_type s
+ Sig_type (_, {type_manifest=None}, _), Field_type s
when let l = String.length s in
l >= 4 && String.sub s (l-4) 4 = "#row" ->
(* Do not report in case of failure,
@@ -230,13 +230,13 @@ and signatures env cxt subst sig1 sig2 =
let (id1, item1, pos1) = Tbl.find name2 comps1 in
let new_subst =
match item2 with
- Tsig_type _ ->
+ Sig_type _ ->
Subst.add_type id2 (Pident id1) subst
- | Tsig_module _ ->
+ | Sig_module _ ->
Subst.add_module id2 (Pident id1) subst
- | Tsig_modtype _ ->
- Subst.add_modtype id2 (Tmty_ident (Pident id1)) subst
- | Tsig_value _ | Tsig_exception _ | Tsig_class _ | Tsig_cltype _ ->
+ | Sig_modtype _ ->
+ Subst.add_modtype id2 (Mty_ident (Pident id1)) subst
+ | Sig_value _ | Sig_exception _ | Sig_class _ | Sig_class_type _ ->
subst
in
pair_components new_subst
@@ -253,31 +253,31 @@ and signatures env cxt subst sig1 sig2 =
and signature_components env cxt subst = function
[] -> []
- | (Tsig_value(id1, valdecl1), Tsig_value(id2, valdecl2), pos) :: rem ->
+ | (Sig_value(id1, valdecl1), Sig_value(id2, valdecl2), pos) :: rem ->
let cc = value_descriptions env cxt subst id1 valdecl1 valdecl2 in
begin match valdecl2.val_kind with
Val_prim p -> signature_components env cxt subst rem
| _ -> (pos, cc) :: signature_components env cxt subst rem
end
- | (Tsig_type(id1, tydecl1, _), Tsig_type(id2, tydecl2, _), pos) :: rem ->
+ | (Sig_type(id1, tydecl1, _), Sig_type(id2, tydecl2, _), pos) :: rem ->
type_declarations env cxt subst id1 tydecl1 tydecl2;
signature_components env cxt subst rem
- | (Tsig_exception(id1, excdecl1), Tsig_exception(id2, excdecl2), pos)
+ | (Sig_exception(id1, excdecl1), Sig_exception(id2, excdecl2), pos)
:: rem ->
exception_declarations env cxt subst id1 excdecl1 excdecl2;
(pos, Tcoerce_none) :: signature_components env cxt subst rem
- | (Tsig_module(id1, mty1, _), Tsig_module(id2, mty2, _), pos) :: rem ->
+ | (Sig_module(id1, mty1, _), Sig_module(id2, mty2, _), pos) :: rem ->
let cc =
modtypes env (Module id1::cxt) subst
(Mtype.strengthen env mty1 (Pident id1)) mty2 in
(pos, cc) :: signature_components env cxt subst rem
- | (Tsig_modtype(id1, info1), Tsig_modtype(id2, info2), pos) :: rem ->
+ | (Sig_modtype(id1, info1), Sig_modtype(id2, info2), pos) :: rem ->
modtype_infos env cxt subst id1 info1 info2;
signature_components env cxt subst rem
- | (Tsig_class(id1, decl1, _), Tsig_class(id2, decl2, _), pos) :: rem ->
+ | (Sig_class(id1, decl1, _), Sig_class(id2, decl2, _), pos) :: rem ->
class_declarations env cxt subst id1 decl1 decl2;
(pos, Tcoerce_none) :: signature_components env cxt subst rem
- | (Tsig_cltype(id1, info1, _), Tsig_cltype(id2, info2, _), pos) :: rem ->
+ | (Sig_class_type(id1, info1, _), Sig_class_type(id2, info2, _), pos) :: rem ->
class_type_declarations env cxt subst id1 info1 info2;
signature_components env cxt subst rem
| _ ->
@@ -290,12 +290,12 @@ and modtype_infos env cxt subst id info1 info2 =
let cxt' = Modtype id :: cxt in
try
match (info1, info2) with
- (Tmodtype_abstract, Tmodtype_abstract) -> ()
- | (Tmodtype_manifest mty1, Tmodtype_abstract) -> ()
- | (Tmodtype_manifest mty1, Tmodtype_manifest mty2) ->
+ (Modtype_abstract, Modtype_abstract) -> ()
+ | (Modtype_manifest mty1, Modtype_abstract) -> ()
+ | (Modtype_manifest mty1, Modtype_manifest mty2) ->
check_modtype_equiv env cxt' mty1 mty2
- | (Tmodtype_abstract, Tmodtype_manifest mty2) ->
- check_modtype_equiv env cxt' (Tmty_ident(Pident id)) mty2
+ | (Modtype_abstract, Modtype_manifest mty2) ->
+ check_modtype_equiv env cxt' (Mty_ident(Pident id)) mty2
with Error reasons ->
raise(Error((cxt, Modtype_infos(id, info1, info2)) :: reasons))
diff --git a/typing/includemod.mli b/typing/includemod.mli
index c1c9c1f0c..c060a580a 100644
--- a/typing/includemod.mli
+++ b/typing/includemod.mli
@@ -14,8 +14,8 @@
(* Inclusion checks for the module language *)
-open Types
open Typedtree
+open Types
open Format
val modtypes: Env.t -> module_type -> module_type -> module_coercion
@@ -36,7 +36,7 @@ type symptom =
| Modtype_permutation
| Interface_mismatch of string * string
| Class_type_declarations of
- Ident.t * cltype_declaration * cltype_declaration *
+ Ident.t * class_type_declaration * class_type_declaration *
Ctype.class_match_failure list
| Class_declarations of
Ident.t * class_declaration * class_declaration *
diff --git a/typing/mtype.ml b/typing/mtype.ml
index 5700b59e0..cda8186db 100644
--- a/typing/mtype.ml
+++ b/typing/mtype.ml
@@ -21,7 +21,7 @@ open Types
let rec scrape env mty =
match mty with
- Tmty_ident p ->
+ Mty_ident p ->
begin try
scrape env (Env.find_modtype_expansion p env)
with Not_found ->
@@ -34,19 +34,19 @@ let freshen mty =
let rec strengthen env mty p =
match scrape env mty with
- Tmty_signature sg ->
- Tmty_signature(strengthen_sig env sg p)
- | Tmty_functor(param, arg, res) when !Clflags.applicative_functors ->
- Tmty_functor(param, arg, strengthen env res (Papply(p, Pident param)))
+ Mty_signature sg ->
+ Mty_signature(strengthen_sig env sg p)
+ | Mty_functor(param, arg, res) when !Clflags.applicative_functors ->
+ Mty_functor(param, arg, strengthen env res (Papply(p, Pident param)))
| mty ->
mty
and strengthen_sig env sg p =
match sg with
[] -> []
- | (Tsig_value(id, desc) as sigelt) :: rem ->
+ | (Sig_value(id, desc) as sigelt) :: rem ->
sigelt :: strengthen_sig env rem p
- | Tsig_type(id, decl, rs) :: rem ->
+ | Sig_type(id, decl, rs) :: rem ->
let newdecl =
match decl.type_manifest, decl.type_private, decl.type_kind with
Some _, Public, _ -> decl
@@ -60,26 +60,26 @@ and strengthen_sig env sg p =
else
{ decl with type_manifest = manif }
in
- Tsig_type(id, newdecl, rs) :: strengthen_sig env rem p
- | (Tsig_exception(id, d) as sigelt) :: rem ->
+ Sig_type(id, newdecl, rs) :: strengthen_sig env rem p
+ | (Sig_exception(id, d) as sigelt) :: rem ->
sigelt :: strengthen_sig env rem p
- | Tsig_module(id, mty, rs) :: rem ->
- Tsig_module(id, strengthen env mty (Pdot(p, Ident.name id, nopos)), rs)
+ | Sig_module(id, mty, rs) :: rem ->
+ Sig_module(id, strengthen env mty (Pdot(p, Ident.name id, nopos)), rs)
:: strengthen_sig (Env.add_module id mty env) rem p
(* Need to add the module in case it defines manifest module types *)
- | Tsig_modtype(id, decl) :: rem ->
+ | Sig_modtype(id, decl) :: rem ->
let newdecl =
match decl with
- Tmodtype_abstract ->
- Tmodtype_manifest(Tmty_ident(Pdot(p, Ident.name id, nopos)))
- | Tmodtype_manifest _ ->
+ Modtype_abstract ->
+ Modtype_manifest(Mty_ident(Pdot(p, Ident.name id, nopos)))
+ | Modtype_manifest _ ->
decl in
- Tsig_modtype(id, newdecl) ::
+ Sig_modtype(id, newdecl) ::
strengthen_sig (Env.add_modtype id decl env) rem p
(* Need to add the module type in case it is manifest *)
- | (Tsig_class(id, decl, rs) as sigelt) :: rem ->
+ | (Sig_class(id, decl, rs) as sigelt) :: rem ->
sigelt :: strengthen_sig env rem p
- | (Tsig_cltype(id, decl, rs) as sigelt) :: rem ->
+ | (Sig_class_type(id, decl, rs) as sigelt) :: rem ->
sigelt :: strengthen_sig env rem p
(* In nondep_supertype, env is only used for the type it assigns to id.
@@ -92,16 +92,16 @@ let nondep_supertype env mid mty =
let rec nondep_mty env va mty =
match mty with
- Tmty_ident p ->
+ Mty_ident p ->
if Path.isfree mid p then
nondep_mty env va (Env.find_modtype_expansion p env)
else mty
- | Tmty_signature sg ->
- Tmty_signature(nondep_sig env va sg)
- | Tmty_functor(param, arg, res) ->
+ | Mty_signature sg ->
+ Mty_signature(nondep_sig env va sg)
+ | Mty_functor(param, arg, res) ->
let var_inv =
match va with Co -> Contra | Contra -> Co | Strict -> Strict in
- Tmty_functor(param, nondep_mty env var_inv arg,
+ Mty_functor(param, nondep_mty env var_inv arg,
nondep_mty (Env.add_module param arg env) va res)
and nondep_sig env va = function
@@ -109,38 +109,38 @@ let nondep_supertype env mid mty =
| item :: rem ->
let rem' = nondep_sig env va rem in
match item with
- Tsig_value(id, d) ->
- Tsig_value(id, {val_type = Ctype.nondep_type env mid d.val_type;
+ Sig_value(id, d) ->
+ Sig_value(id, {val_type = Ctype.nondep_type env mid d.val_type;
val_kind = d.val_kind;
val_loc = d.val_loc;
- }) :: rem'
- | Tsig_type(id, d, rs) ->
- Tsig_type(id, Ctype.nondep_type_decl env mid id (va = Co) d, rs)
+ }) :: rem'
+ | Sig_type(id, d, rs) ->
+ Sig_type(id, Ctype.nondep_type_decl env mid id (va = Co) d, rs)
:: rem'
- | Tsig_exception(id, d) ->
+ | Sig_exception(id, d) ->
let d = {exn_args = List.map (Ctype.nondep_type env mid) d.exn_args;
exn_loc = d.exn_loc} in
- Tsig_exception(id, d) :: rem'
- | Tsig_module(id, mty, rs) ->
- Tsig_module(id, nondep_mty env va mty, rs) :: rem'
- | Tsig_modtype(id, d) ->
+ Sig_exception(id, d) :: rem'
+ | Sig_module(id, mty, rs) ->
+ Sig_module(id, nondep_mty env va mty, rs) :: rem'
+ | Sig_modtype(id, d) ->
begin try
- Tsig_modtype(id, nondep_modtype_decl env d) :: rem'
+ Sig_modtype(id, nondep_modtype_decl env d) :: rem'
with Not_found ->
match va with
- Co -> Tsig_modtype(id, Tmodtype_abstract) :: rem'
+ Co -> Sig_modtype(id, Modtype_abstract) :: rem'
| _ -> raise Not_found
end
- | Tsig_class(id, d, rs) ->
- Tsig_class(id, Ctype.nondep_class_declaration env mid d, rs)
+ | Sig_class(id, d, rs) ->
+ Sig_class(id, Ctype.nondep_class_declaration env mid d, rs)
:: rem'
- | Tsig_cltype(id, d, rs) ->
- Tsig_cltype(id, Ctype.nondep_cltype_declaration env mid d, rs)
+ | Sig_class_type(id, d, rs) ->
+ Sig_class_type(id, Ctype.nondep_cltype_declaration env mid d, rs)
:: rem'
and nondep_modtype_decl env = function
- Tmodtype_abstract -> Tmodtype_abstract
- | Tmodtype_manifest mty -> Tmodtype_manifest(nondep_mty env Strict mty)
+ Modtype_abstract -> Modtype_abstract
+ | Modtype_manifest mty -> Modtype_manifest(nondep_mty env Strict mty)
in
nondep_mty env Co mty
@@ -160,62 +160,62 @@ let enrich_typedecl env p decl =
let rec enrich_modtype env p mty =
match mty with
- Tmty_signature sg ->
- Tmty_signature(List.map (enrich_item env p) sg)
+ Mty_signature sg ->
+ Mty_signature(List.map (enrich_item env p) sg)
| _ ->
mty
and enrich_item env p = function
- Tsig_type(id, decl, rs) ->
- Tsig_type(id,
+ Sig_type(id, decl, rs) ->
+ Sig_type(id,
enrich_typedecl env (Pdot(p, Ident.name id, nopos)) decl, rs)
- | Tsig_module(id, mty, rs) ->
- Tsig_module(id,
+ | Sig_module(id, mty, rs) ->
+ Sig_module(id,
enrich_modtype env (Pdot(p, Ident.name id, nopos)) mty, rs)
| item -> item
let rec type_paths env p mty =
match scrape env mty with
- Tmty_ident p -> []
- | Tmty_signature sg -> type_paths_sig env p 0 sg
- | Tmty_functor(param, arg, res) -> []
+ Mty_ident p -> []
+ | Mty_signature sg -> type_paths_sig env p 0 sg
+ | Mty_functor(param, arg, res) -> []
and type_paths_sig env p pos sg =
match sg with
[] -> []
- | Tsig_value(id, decl) :: rem ->
+ | Sig_value(id, decl) :: rem ->
let pos' = match decl.val_kind with Val_prim _ -> pos | _ -> pos + 1 in
type_paths_sig env p pos' rem
- | Tsig_type(id, decl, _) :: rem ->
+ | Sig_type(id, decl, _) :: rem ->
Pdot(p, Ident.name id, nopos) :: type_paths_sig env p pos rem
- | Tsig_module(id, mty, _) :: rem ->
+ | Sig_module(id, mty, _) :: rem ->
type_paths env (Pdot(p, Ident.name id, pos)) mty @
type_paths_sig (Env.add_module id mty env) p (pos+1) rem
- | Tsig_modtype(id, decl) :: rem ->
+ | Sig_modtype(id, decl) :: rem ->
type_paths_sig (Env.add_modtype id decl env) p pos rem
- | (Tsig_exception _ | Tsig_class _) :: rem ->
+ | (Sig_exception _ | Sig_class _) :: rem ->
type_paths_sig env p (pos+1) rem
- | (Tsig_cltype _) :: rem ->
+ | (Sig_class_type _) :: rem ->
type_paths_sig env p pos rem
let rec no_code_needed env mty =
match scrape env mty with
- Tmty_ident p -> false
- | Tmty_signature sg -> no_code_needed_sig env sg
- | Tmty_functor(_, _, _) -> false
+ Mty_ident p -> false
+ | Mty_signature sg -> no_code_needed_sig env sg
+ | Mty_functor(_, _, _) -> false
and no_code_needed_sig env sg =
match sg with
[] -> true
- | Tsig_value(id, decl) :: rem ->
+ | Sig_value(id, decl) :: rem ->
begin match decl.val_kind with
| Val_prim _ -> no_code_needed_sig env rem
| _ -> false
end
- | Tsig_module(id, mty, _) :: rem ->
+ | Sig_module(id, mty, _) :: rem ->
no_code_needed env mty &&
no_code_needed_sig (Env.add_module id mty env) rem
- | (Tsig_type _ | Tsig_modtype _ | Tsig_cltype _) :: rem ->
+ | (Sig_type _ | Sig_modtype _ | Sig_class_type _) :: rem ->
no_code_needed_sig env rem
- | (Tsig_exception _ | Tsig_class _) :: rem ->
+ | (Sig_exception _ | Sig_class _) :: rem ->
false
diff --git a/typing/parmatch.ml b/typing/parmatch.ml
index c2cf0d606..ab93a3f63 100644
--- a/typing/parmatch.ml
+++ b/typing/parmatch.ml
@@ -24,13 +24,15 @@ open Typedtree
(*************************************)
let make_pat desc ty tenv =
- {pat_desc = desc; pat_loc = Location.none;
+ {pat_desc = desc; pat_loc = Location.none; pat_extra = [];
pat_type = ty ; pat_env = tenv }
let omega = make_pat Tpat_any Ctype.none Env.empty
let extra_pat =
- make_pat (Tpat_var (Ident.create "+")) Ctype.none Env.empty
+ make_pat
+ (Tpat_var (Ident.create "+", mknoloc "+"))
+ Ctype.none Env.empty
let rec omegas i =
if i <= 0 then [] else omega :: omegas (i-1)
@@ -55,9 +57,9 @@ let records_args l1 l2 =
(* Invariant: fields are already sorted by Typecore.type_label_a_list *)
let rec combine r1 r2 l1 l2 = match l1,l2 with
| [],[] -> List.rev r1, List.rev r2
- | [],(_,p2)::rem2 -> combine (omega::r1) (p2::r2) [] rem2
- | (_,p1)::rem1,[] -> combine (p1::r1) (omega::r2) rem1 []
- | (lbl1,p1)::rem1, (lbl2,p2)::rem2 ->
+ | [],(_,_,_,p2)::rem2 -> combine (omega::r1) (p2::r2) [] rem2
+ | (_,_,_,p1)::rem1,[] -> combine (p1::r1) (omega::r2) rem1 []
+ | (_,_,lbl1,p1)::rem1, (_, _,lbl2,p2)::rem2 ->
if lbl1.lbl_pos < lbl2.lbl_pos then
combine (p1::r1) (omega::r2) rem1 l2
else if lbl1.lbl_pos > lbl2.lbl_pos then
@@ -69,8 +71,8 @@ let records_args l1 l2 =
let rec compat p q =
match p.pat_desc,q.pat_desc with
- | Tpat_alias (p,_),_ -> compat p q
- | _,Tpat_alias (q,_) -> compat p q
+ | Tpat_alias (p,_,_),_ -> compat p q
+ | _,Tpat_alias (q,_,_) -> compat p q
| (Tpat_any|Tpat_var _),_ -> true
| _,(Tpat_any|Tpat_var _) -> true
| Tpat_or (p1,p2,_),_ -> compat p1 q || compat p2 q
@@ -78,7 +80,7 @@ let rec compat p q =
| Tpat_constant c1, Tpat_constant c2 -> c1=c2
| Tpat_tuple ps, Tpat_tuple qs -> compats ps qs
| Tpat_lazy p, Tpat_lazy q -> compat p q
- | Tpat_construct (c1,ps1), Tpat_construct (c2,ps2) ->
+ | Tpat_construct (_, _, c1,ps1, _), Tpat_construct (_, _, c2,ps2, _) ->
c1.cstr_tag = c2.cstr_tag && compats ps1 ps2
| Tpat_variant(l1,Some p1, r1), Tpat_variant(l2,Some p2,_) ->
l1=l2 && compat p1 p2
@@ -86,7 +88,7 @@ let rec compat p q =
l1 = l2
| Tpat_variant (_, None, _), Tpat_variant (_,Some _, _) -> false
| Tpat_variant (_, Some _, _), Tpat_variant (_, None, _) -> false
- | Tpat_record l1,Tpat_record l2 ->
+ | Tpat_record (l1,_),Tpat_record (l2,_) ->
let ps,qs = records_args l1 l2 in
compats ps qs
| Tpat_array ps, Tpat_array qs ->
@@ -135,7 +137,7 @@ let find_label lbl lbls =
try
let name,_,_ = List.nth lbls lbl.lbl_pos in
name
- with Failure "nth" -> "*Unkown label*"
+ with Failure "nth" -> Ident.create "*Unknown label*"
let rec get_record_labels ty tenv =
match get_type_descr ty tenv with
@@ -156,7 +158,7 @@ let get_constr_name tag ty tenv = match tag with
| Cstr_exception (path, _) -> Path.name path
| _ ->
try
- let name,_,_ = get_constr tag ty tenv in name
+ let name,_,_ = get_constr tag ty tenv in Ident.name name
with
| Datarepr.Constr_not_found -> "*Unknown constructor*"
@@ -165,9 +167,21 @@ let is_cons tag v = match get_constr_name tag v.pat_type v.pat_env with
| _ -> false
-let rec pretty_val ppf v = match v.pat_desc with
+let rec pretty_val ppf v =
+ match v.pat_extra with
+ (cstr,_) :: rem ->
+ begin match cstr with
+ | Tpat_unpack ->
+ fprintf ppf "@[(module %a)@]" pretty_val { v with pat_extra = rem }
+ | Tpat_constraint ctyp ->
+ fprintf ppf "@[(%a : _)@]" pretty_val { v with pat_extra = rem }
+ | Tpat_type _ ->
+ fprintf ppf "@[(# %a)@]" pretty_val { v with pat_extra = rem }
+ end
+ | [] ->
+ match v.pat_desc with
| Tpat_any -> fprintf ppf "_"
- | Tpat_var x -> Ident.print ppf x
+ | Tpat_var (x,_) -> Ident.print ppf x
| Tpat_constant (Const_int i) -> fprintf ppf "%d" i
| Tpat_constant (Const_char c) -> fprintf ppf "%C" c
| Tpat_constant (Const_string s) -> fprintf ppf "%S" s
@@ -177,13 +191,13 @@ let rec pretty_val ppf v = match v.pat_desc with
| Tpat_constant (Const_nativeint i) -> fprintf ppf "%ndn" i
| Tpat_tuple vs ->
fprintf ppf "@[(%a)@]" (pretty_vals ",") vs
- | Tpat_construct ({cstr_tag=tag},[]) ->
+ | Tpat_construct (_, _, {cstr_tag=tag},[], _) ->
let name = get_constr_name tag v.pat_type v.pat_env in
fprintf ppf "%s" name
- | Tpat_construct ({cstr_tag=tag},[w]) ->
+ | Tpat_construct (_, _, {cstr_tag=tag},[w], _) ->
let name = get_constr_name tag v.pat_type v.pat_env in
fprintf ppf "@[<2>%s@ %a@]" name pretty_arg w
- | Tpat_construct ({cstr_tag=tag},vs) ->
+ | Tpat_construct (_, _, {cstr_tag=tag},vs, _) ->
let name = get_constr_name tag v.pat_type v.pat_env in
begin match (name, vs) with
("::", [v1;v2]) ->
@@ -195,36 +209,36 @@ let rec pretty_val ppf v = match v.pat_desc with
fprintf ppf "`%s" l
| Tpat_variant (l, Some w, _) ->
fprintf ppf "@[<2>`%s@ %a@]" l pretty_arg w
- | Tpat_record lvs ->
+ | Tpat_record (lvs,_) ->
fprintf ppf "@[{%a}@]"
(pretty_lvals (get_record_labels v.pat_type v.pat_env))
(List.filter
(function
- | (_,{pat_desc=Tpat_any}) -> false (* do not show lbl=_ *)
+ | (_,_,_,{pat_desc=Tpat_any}) -> false (* do not show lbl=_ *)
| _ -> true) lvs)
| Tpat_array vs ->
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
| Tpat_lazy v ->
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
- | Tpat_alias (v,x) ->
+ | Tpat_alias (v, x,_) ->
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
| Tpat_or (v,w,_) ->
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
and pretty_car ppf v = match v.pat_desc with
-| Tpat_construct ({cstr_tag=tag}, [_ ; _])
+| Tpat_construct (_,_,{cstr_tag=tag}, [_ ; _], _)
when is_cons tag v ->
fprintf ppf "(%a)" pretty_val v
| _ -> pretty_val ppf v
and pretty_cdr ppf v = match v.pat_desc with
-| Tpat_construct ({cstr_tag=tag}, [v1 ; v2])
+| Tpat_construct (_,_,{cstr_tag=tag}, [v1 ; v2], _)
when is_cons tag v ->
fprintf ppf "%a::@,%a" pretty_car v1 pretty_cdr v2
| _ -> pretty_val ppf v
and pretty_arg ppf v = match v.pat_desc with
-| Tpat_construct (_,_::_) -> fprintf ppf "(%a)" pretty_val v
+| Tpat_construct (_,_,_,_::_, _) -> fprintf ppf "(%a)" pretty_val v
| _ -> pretty_val ppf v
and pretty_or ppf v = match v.pat_desc with
@@ -240,12 +254,12 @@ and pretty_vals sep ppf = function
and pretty_lvals lbls ppf = function
| [] -> ()
- | [lbl,v] ->
+ | [_, _,lbl,v] ->
let name = find_label lbl lbls in
- fprintf ppf "%s=%a" name pretty_val v
- | (lbl,v)::rest ->
+ fprintf ppf "%s=%a" (Ident.name name) pretty_val v
+ | (_, _, lbl,v)::rest ->
let name = find_label lbl lbls in
- fprintf ppf "%s=%a;@ %a" name pretty_val v (pretty_lvals lbls) rest
+ fprintf ppf "%s=%a;@ %a" (Ident.name name) pretty_val v (pretty_lvals lbls) rest
let top_pretty ppf v =
fprintf ppf "@[%a@]@?" pretty_val v
@@ -263,7 +277,7 @@ let prerr_pat v =
(* Check top matching *)
let simple_match p1 p2 =
match p1.pat_desc, p2.pat_desc with
- | Tpat_construct(c1, _), Tpat_construct(c2, _) ->
+ | Tpat_construct(_, _, c1, _, _), Tpat_construct(_,_, c2, _, _) ->
c1.cstr_tag = c2.cstr_tag
| Tpat_variant(l1, _, _), Tpat_variant(l2, _, _) ->
l1 = l2
@@ -283,30 +297,30 @@ let simple_match p1 p2 =
(* extract record fields as a whole *)
let record_arg p = match p.pat_desc with
| Tpat_any -> []
-| Tpat_record args -> args
+| Tpat_record (args,_) -> args
| _ -> fatal_error "Parmatch.as_record"
(* Raise Not_found when pos is not present in arg *)
let get_field pos arg =
- let _,p = List.find (fun (lbl,_) -> pos = lbl.lbl_pos) arg in
+ let _,_,_, p = List.find (fun (_,_,lbl,_) -> pos = lbl.lbl_pos) arg in
p
let extract_fields omegas arg =
List.map
- (fun (lbl,_) ->
+ (fun (_,_,lbl,_) ->
try
get_field lbl.lbl_pos arg
with Not_found -> omega)
omegas
let all_record_args lbls = match lbls with
-| ({lbl_all=lbl_all},_)::_ ->
+| (_,_,{lbl_all=lbl_all},_)::_ ->
let t =
Array.map
- (fun lbl -> lbl,omega) lbl_all in
+ (fun lbl -> Path.Pident (Ident.create "?temp?"), mknoloc (Longident.Lident "?temp?"), lbl,omega) lbl_all in
List.iter
- (fun ((lbl,_) as x) -> t.(lbl.lbl_pos) <- x)
+ (fun ((_,_, lbl,_) as x) -> t.(lbl.lbl_pos) <- x)
lbls ;
Array.to_list t
| _ -> fatal_error "Parmatch.all_record_args"
@@ -314,19 +328,19 @@ let all_record_args lbls = match lbls with
(* Build argument list when p2 >= p1, where p1 is a simple pattern *)
let rec simple_match_args p1 p2 = match p2.pat_desc with
-| Tpat_alias (p2,_) -> simple_match_args p1 p2
-| Tpat_construct(cstr, args) -> args
+| Tpat_alias (p2,_,_) -> simple_match_args p1 p2
+| Tpat_construct(_,_, cstr, args, _) -> args
| Tpat_variant(lab, Some arg, _) -> [arg]
| Tpat_tuple(args) -> args
-| Tpat_record(args) -> extract_fields (record_arg p1) args
+| Tpat_record(args,_) -> extract_fields (record_arg p1) args
| Tpat_array(args) -> args
| Tpat_lazy arg -> [arg]
| (Tpat_any | Tpat_var(_)) ->
begin match p1.pat_desc with
- Tpat_construct(_, args) -> omega_list args
+ Tpat_construct(_,_, _,args, _) -> omega_list args
| Tpat_variant(_, Some _, _) -> [omega]
| Tpat_tuple(args) -> omega_list args
- | Tpat_record(args) -> omega_list args
+ | Tpat_record(args,_) -> omega_list args
| Tpat_array(args) -> omega_list args
| Tpat_lazy _ -> [omega]
| _ -> []
@@ -341,24 +355,23 @@ let rec simple_match_args p1 p2 = match p2.pat_desc with
let rec normalize_pat q = match q.pat_desc with
| Tpat_any | Tpat_constant _ -> q
| Tpat_var _ -> make_pat Tpat_any q.pat_type q.pat_env
- | Tpat_alias (p,_) -> normalize_pat p
+ | Tpat_alias (p,_,_) -> normalize_pat p
| Tpat_tuple (args) ->
make_pat (Tpat_tuple (omega_list args)) q.pat_type q.pat_env
- | Tpat_construct (c,args) ->
- make_pat (Tpat_construct (c,omega_list args)) q.pat_type q.pat_env
+ | Tpat_construct (lid, lid_loc, c,args,explicit_arity) ->
+ make_pat (Tpat_construct (lid, lid_loc, c,omega_list args, explicit_arity)) q.pat_type q.pat_env
| Tpat_variant (l, arg, row) ->
make_pat (Tpat_variant (l, may_map (fun _ -> omega) arg, row))
q.pat_type q.pat_env
| Tpat_array (args) ->
make_pat (Tpat_array (omega_list args)) q.pat_type q.pat_env
- | Tpat_record (largs) ->
- make_pat (Tpat_record (List.map (fun (lbl,_) -> lbl,omega) largs))
+ | Tpat_record (largs, closed) ->
+ make_pat (Tpat_record (List.map (fun (lid,lid_loc,lbl,_) -> lid, lid_loc, lbl,omega) largs, closed))
q.pat_type q.pat_env
| Tpat_lazy _ ->
make_pat (Tpat_lazy omega) q.pat_type q.pat_env
| Tpat_or _ -> fatal_error "Parmatch.normalize_pat"
-
(*
Build normalized (cf. supra) discriminating pattern,
in the non-data type case
@@ -367,7 +380,7 @@ let rec normalize_pat q = match q.pat_desc with
let discr_pat q pss =
let rec acc_pat acc pss = match pss with
- ({pat_desc = Tpat_alias (p,_)}::ps)::pss ->
+ ({pat_desc = Tpat_alias (p,_,_)}::ps)::pss ->
acc_pat acc ((p::ps)::pss)
| ({pat_desc = Tpat_or (p1,p2,_)}::ps)::pss ->
acc_pat acc ((p1::ps)::(p2::ps)::pss)
@@ -375,19 +388,19 @@ let discr_pat q pss =
acc_pat acc pss
| (({pat_desc = Tpat_tuple _} as p)::_)::_ -> normalize_pat p
| (({pat_desc = Tpat_lazy _} as p)::_)::_ -> normalize_pat p
- | (({pat_desc = Tpat_record largs} as p)::_)::pss ->
+ | (({pat_desc = Tpat_record (largs,closed)} as p)::_)::pss ->
let new_omegas =
List.fold_right
- (fun (lbl,_) r ->
+ (fun (lid, lid_loc, lbl,_) r ->
try
let _ = get_field lbl.lbl_pos r in
r
with Not_found ->
- (lbl,omega)::r)
+ (lid, lid_loc, lbl,omega)::r)
largs (record_arg acc)
in
acc_pat
- (make_pat (Tpat_record new_omegas) p.pat_type p.pat_env)
+ (make_pat (Tpat_record (new_omegas, closed)) p.pat_type p.pat_env)
pss
| _ -> acc in
@@ -412,26 +425,26 @@ let do_set_args erase_mutable q r = match q with
| {pat_desc = Tpat_tuple omegas} ->
let args,rest = read_args omegas r in
make_pat (Tpat_tuple args) q.pat_type q.pat_env::rest
-| {pat_desc = Tpat_record omegas} ->
+| {pat_desc = Tpat_record (omegas,closed)} ->
let args,rest = read_args omegas r in
make_pat
(Tpat_record
- (List.map2 (fun (lbl,_) arg ->
+ (List.map2 (fun (lid, lid_loc, lbl,_) arg ->
if
erase_mutable &&
(match lbl.lbl_mut with
| Mutable -> true | Immutable -> false)
then
- lbl, omega
+ lid, lid_loc, lbl, omega
else
- lbl,arg)
- omegas args))
+ lid, lid_loc, lbl, arg)
+ omegas args, closed))
q.pat_type q.pat_env::
rest
-| {pat_desc = Tpat_construct (c,omegas)} ->
+| {pat_desc = Tpat_construct (lid, lid_loc, c,omegas, explicit_arity)} ->
let args,rest = read_args omegas r in
make_pat
- (Tpat_construct (c,args)) q.pat_type q.pat_env::
+ (Tpat_construct (lid, lid_loc, c,args, explicit_arity)) q.pat_type q.pat_env::
rest
| {pat_desc = Tpat_variant (l, omega, row)} ->
let arg, rest =
@@ -464,7 +477,7 @@ and set_args_erase_mutable q r = do_set_args true q r
(* filter pss acording to pattern q *)
let filter_one q pss =
let rec filter_rec = function
- ({pat_desc = Tpat_alias(p,_)}::ps)::pss ->
+ ({pat_desc = Tpat_alias(p,_,_)}::ps)::pss ->
filter_rec ((p::ps)::pss)
| ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss ->
filter_rec ((p1::ps)::(p2::ps)::pss)
@@ -482,7 +495,7 @@ let filter_one q pss =
*)
let filter_extra pss =
let rec filter_rec = function
- ({pat_desc = Tpat_alias(p,_)}::ps)::pss ->
+ ({pat_desc = Tpat_alias(p,_,_)}::ps)::pss ->
filter_rec ((p::ps)::pss)
| ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss ->
filter_rec ((p1::ps)::(p2::ps)::pss)
@@ -517,7 +530,7 @@ let filter_all pat0 pss =
else c :: insert q qs env in
let rec filter_rec env = function
- ({pat_desc = Tpat_alias(p,_)}::ps)::pss ->
+ ({pat_desc = Tpat_alias(p,_,_)}::ps)::pss ->
filter_rec env ((p::ps)::pss)
| ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss ->
filter_rec env ((p1::ps)::(p2::ps)::pss)
@@ -528,7 +541,7 @@ let filter_all pat0 pss =
| _ -> env
and filter_omega env = function
- ({pat_desc = Tpat_alias(p,_)}::ps)::pss ->
+ ({pat_desc = Tpat_alias(p,_,_)}::ps)::pss ->
filter_omega env ((p::ps)::pss)
| ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss ->
filter_omega env ((p1::ps)::(p2::ps)::pss)
@@ -556,7 +569,7 @@ let rec set_last a = function
(* mark constructor lines for failure when they are incomplete *)
let rec mark_partial = function
- ({pat_desc = Tpat_alias(p,_)}::ps)::pss ->
+ ({pat_desc = Tpat_alias(p,_,_)}::ps)::pss ->
mark_partial ((p::ps)::pss)
| ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss ->
mark_partial ((p1::ps)::(p2::ps)::pss)
@@ -596,14 +609,14 @@ let row_of_pat pat =
not.
*)
-let generalized_constructor x =
- match x with
- ({pat_desc = Tpat_construct(c,_);pat_env=env},_) ->
+let generalized_constructor x =
+ match x with
+ ({pat_desc = Tpat_construct(_,_,c,_, _);pat_env=env},_) ->
c.cstr_generalized
| _ -> assert false
-let clean_env env =
- let rec loop =
+let clean_env env =
+ let rec loop =
function
| [] -> []
| x :: xs ->
@@ -612,12 +625,12 @@ let clean_env env =
loop env
let full_match ignore_generalized closing env = match env with
-| ({pat_desc = Tpat_construct ({cstr_tag=Cstr_exception _},_)},_)::_ ->
+| ({pat_desc = Tpat_construct (_,_,{cstr_tag=Cstr_exception _},_,_)},_)::_ ->
false
-| ({pat_desc = Tpat_construct(c,_);pat_type=typ},_) :: _ ->
+| ({pat_desc = Tpat_construct(_,_,c,_,_);pat_type=typ},_) :: _ ->
if ignore_generalized then
(* remove generalized constructors; those cases will be handled separately *)
- let env = clean_env env in
+ let env = clean_env env in
List.length env = c.cstr_normal
else
List.length env = c.cstr_consts + c.cstr_nonconsts
@@ -656,12 +669,12 @@ let full_match ignore_generalized closing env = match env with
| _ -> fatal_error "Parmatch.full_match"
let full_match_gadt env = match env with
- | ({pat_desc = Tpat_construct(c,_);pat_type=typ},_) :: _ ->
+ | ({pat_desc = Tpat_construct(_,_,c,_,_);pat_type=typ},_) :: _ ->
List.length env = c.cstr_consts + c.cstr_nonconsts
| _ -> true
let extendable_match env = match env with
-| ({pat_desc = Tpat_construct({cstr_tag=(Cstr_constant _|Cstr_block _)},_)} as p,_) :: _ ->
+| ({pat_desc = Tpat_construct(_,_,{cstr_tag=(Cstr_constant _|Cstr_block _)},_,_)} as p,_) :: _ ->
let path = get_type_path p.pat_type p.pat_env in
not
(Path.same path Predef.path_bool ||
@@ -674,7 +687,7 @@ let should_extend ext env = match ext with
| None -> false
| Some ext -> match env with
| ({pat_desc =
- Tpat_construct({cstr_tag=(Cstr_constant _|Cstr_block _)},_)} as p,_)
+ Tpat_construct(_, _,{cstr_tag=(Cstr_constant _|Cstr_block _)},_,_)} as p,_)
:: _ ->
let path = get_type_path p.pat_type p.pat_env in
Path.same path ext
@@ -703,7 +716,9 @@ let complete_tags nconsts nconstrs tags =
(* build a pattern from a constructor list *)
let pat_of_constr ex_pat cstr =
- {ex_pat with pat_desc = Tpat_construct (cstr,omegas cstr.cstr_arity)}
+ {ex_pat with pat_desc = Tpat_construct (
+ Path.Pident (Ident.create "?pat_of_constr?"), mknoloc (Longident.Lident "?pat_of_constr?"),
+ cstr,omegas cstr.cstr_arity,false)}
let rec pat_of_constrs ex_pat = function
| [] -> raise Empty
@@ -729,7 +744,7 @@ let rec adt_path env ty =
| _ -> raise Not_an_adt
;;
-let rec map_filter f =
+let rec map_filter f =
function
[] -> []
| x :: xs ->
@@ -738,9 +753,9 @@ let rec map_filter f =
| Some y -> y :: map_filter f xs
(* Sends back a pattern that complements constructor tags all_tag *)
-let complete_constrs p all_tags =
+let complete_constrs p all_tags =
match p.pat_desc with
- | Tpat_construct (c,_) ->
+ | Tpat_construct (_,_,c,_,_) ->
begin try
let not_tags = complete_tags c.cstr_consts c.cstr_nonconsts all_tags in
let constrs = Env.find_constructors (adt_path p.pat_env p.pat_type) p.pat_env in
@@ -771,22 +786,22 @@ let build_other_constant proj make first next p env =
*)
let build_other ext env = match env with
-| ({pat_desc = Tpat_construct ({cstr_tag=Cstr_exception _} as c,_)},_)
+| ({pat_desc = Tpat_construct (lid, lid_loc, ({cstr_tag=Cstr_exception _} as c),_,_)},_)
::_ ->
make_pat
(Tpat_construct
- ({c with
+ (lid, lid_loc, {c with
cstr_tag=(Cstr_exception
(Path.Pident (Ident.create "*exception*"), Location.none))},
- []))
+ [], false))
Ctype.none Env.empty
-| ({pat_desc = Tpat_construct (_,_)} as p,_) :: _ ->
+| ({pat_desc = Tpat_construct (_,_, _,_,_)} as p,_) :: _ ->
begin match ext with
| Some ext when Path.same ext (get_type_path p.pat_type p.pat_env) ->
extra_pat
| _ ->
let get_tag = function
- | {pat_desc = Tpat_construct (c,_)} -> c.cstr_tag
+ | {pat_desc = Tpat_construct (_,_,c,_,_)} -> c.cstr_tag
| _ -> fatal_error "Parmatch.get_tag" in
let all_tags = List.map (fun (p,_) -> get_tag p) env in
pat_of_constrs p (complete_constrs p all_tags)
@@ -899,11 +914,11 @@ let build_other ext env = match env with
| [] -> omega
| _ -> omega
-let build_other_gadt ext env =
+let build_other_gadt ext env =
match env with
- | ({pat_desc = Tpat_construct (_,_)} as p,_) :: _ ->
+ | ({pat_desc = Tpat_construct _} as p,_) :: _ ->
let get_tag = function
- | {pat_desc = Tpat_construct (c,_)} -> c.cstr_tag
+ | {pat_desc = Tpat_construct (_,_,c,_,_)} -> c.cstr_tag
| _ -> fatal_error "Parmatch.get_tag" in
let all_tags = List.map (fun (p,_) -> get_tag p) env in
let cnstrs = complete_constrs p all_tags in
@@ -912,7 +927,7 @@ let build_other_gadt ext env =
Format.eprintf "@.@."; *)
pats
| _ -> assert false
-
+
(*
Core function :
Is the last row of pattern matrix pss + qs satisfiable ?
@@ -925,11 +940,13 @@ let build_other_gadt ext env =
let rec has_instance p = match p.pat_desc with
| Tpat_variant (l,_,r) when is_absent l r -> false
| Tpat_any | Tpat_var _ | Tpat_constant _ | Tpat_variant (_,None,_) -> true
- | Tpat_alias (p,_) | Tpat_variant (_,Some p,_) -> has_instance p
+ | Tpat_alias (p,_,_) | Tpat_variant (_,Some p,_) -> has_instance p
| Tpat_or (p1,p2,_) -> has_instance p1 || has_instance p2
- | Tpat_construct (_,ps) | Tpat_tuple ps | Tpat_array ps -> has_instances ps
- | Tpat_record lps -> has_instances (List.map snd lps)
- | Tpat_lazy p -> has_instance p
+ | Tpat_construct (_, _,_,ps,_) | Tpat_tuple ps | Tpat_array ps -> has_instances ps
+ | Tpat_record (lps,_) -> has_instances (List.map (fun (_,_,_,x) -> x) lps)
+ | Tpat_lazy p
+ -> has_instance p
+
and has_instances = function
| [] -> true
@@ -942,7 +959,7 @@ let rec satisfiable pss qs = match pss with
| [] -> false
| {pat_desc = Tpat_or(q1,q2,_)}::qs ->
satisfiable pss (q1::qs) || satisfiable pss (q2::qs)
- | {pat_desc = Tpat_alias(q,_)}::qs ->
+ | {pat_desc = Tpat_alias(q,_,_)}::qs ->
satisfiable pss (q::qs)
| {pat_desc = (Tpat_any | Tpat_var(_))}::qs ->
let q0 = discr_pat omega pss in
@@ -983,7 +1000,7 @@ let rec orify_many =
| [] -> assert false
| [x] -> x
| x :: xs -> orify x (orify_many xs)
-
+
let rec try_many f = function
| [] -> Rnone
| (p,pss)::rest ->
@@ -997,13 +1014,13 @@ let try_many_gadt f = function
| (p,pss)::rest ->
match f (p,pss) with
| Rnone -> try_many f rest
- | Rsome sofar ->
- let others = try_many f rest in
+ | Rsome sofar ->
+ let others = try_many f rest in
match others with
Rnone -> Rsome sofar
| Rsome sofar' ->
Rsome (sofar @ sofar')
-
+
let rec exhaust ext pss n = match pss with
@@ -1053,8 +1070,8 @@ let rec exhaust ext pss n = match pss with
| Empty -> fatal_error "Parmatch.exhaust"
end
-let combinations f lst lst' =
- let rec iter2 x =
+let combinations f lst lst' =
+ let rec iter2 x =
function
[] -> []
| y :: ys ->
@@ -1066,10 +1083,33 @@ let combinations f lst lst' =
| x :: xs -> iter2 x lst' @ iter xs
in
iter lst
-
+
+(*
+let print_pat pat =
+ let rec string_of_pat pat =
+ match pat.pat_desc with
+ Tpat_var _ -> "v"
+ | Tpat_any -> "_"
+ | Tpat_alias (p, x) -> Printf.sprintf "(%s) as ?" (string_of_pat p)
+ | Tpat_constant n -> "0"
+ | Tpat_construct (_, lid, _, _) ->
+ Printf.sprintf "%s" (String.concat "." (Longident.flatten lid.txt))
+ | Tpat_lazy p ->
+ Printf.sprintf "(lazy %s)" (string_of_pat p)
+ | Tpat_or (p1,p2,_) ->
+ Printf.sprintf "(%s | %s)" (string_of_pat p1) (string_of_pat p2)
+ | Tpat_tuple list ->
+ Printf.sprintf "(%s)" (String.concat "," (List.map string_of_pat list))
+ | Tpat_variant (_, _, _) -> "variant"
+ | Tpat_record (_, _) -> "record"
+ | Tpat_array _ -> "array"
+ in
+ Printf.fprintf stderr "PAT[%s]\n%!" (string_of_pat pat)
+*)
+
(* strictly more powerful than exhaust; however, exhaust
was kept for backwards compatibility *)
-let rec exhaust_gadt ext pss n = match pss with
+let rec exhaust_gadt (ext:Path.t option) (pss:Typedtree.pattern list list) (n:int) = match pss with
| [] -> Rsome [omegas n]
| []::_ -> Rnone
| pss ->
@@ -1112,34 +1152,33 @@ let rec exhaust_gadt ext pss n = match pss with
| Rsome r ->
try
let missing_trailing = build_other_gadt ext constrs in
- let before =
- match before with
- Rnone -> []
- | Rsome lst -> lst
+ let before =
+ match before with
+ Rnone -> []
+ | Rsome lst -> lst
in
- let dug =
+ let dug =
combinations
- (fun head tail ->
- head :: tail)
+ (fun head tail -> head :: tail)
missing_trailing
r
in
- Rsome (dug @ before)
+ Rsome (dug @ before)
with
(* cannot occur, since constructors don't make a full signature *)
| Empty -> fatal_error "Parmatch.exhaust"
end
-let exhaust_gadt ext pss n =
- let ret = exhaust_gadt ext pss n in
+let exhaust_gadt ext pss n =
+ let ret = exhaust_gadt ext pss n in
match ret with
Rnone -> Rnone
| Rsome lst ->
(* The following line is needed to compile stdlib/printf.ml *)
if lst = [] then Rsome (omegas n) else
- let singletons =
- List.map
- (function
+ let singletons =
+ List.map
+ (function
[x] -> x
| _ -> assert false)
lst
@@ -1261,7 +1300,7 @@ let make_rows pss = List.map make_row pss
(* Useful to detect and expand or pats inside as pats *)
let rec unalias p = match p.pat_desc with
-| Tpat_alias (p,_) -> unalias p
+| Tpat_alias (p,_,_) -> unalias p
| _ -> p
@@ -1279,7 +1318,7 @@ let is_var_column rs =
(* Standard or-args for left-to-right matching *)
let rec or_args p = match p.pat_desc with
| Tpat_or (p1,p2,_) -> p1,p2
-| Tpat_alias (p,_) -> or_args p
+| Tpat_alias (p,_,_) -> or_args p
| _ -> assert false
(* Just remove current column *)
@@ -1314,7 +1353,7 @@ let filter_one q rs =
| r::rem ->
match r.active with
| [] -> assert false
- | {pat_desc = Tpat_alias(p,_)}::ps ->
+ | {pat_desc = Tpat_alias(p,_,_)}::ps ->
filter_rec ({r with active = p::ps}::rem)
| {pat_desc = Tpat_or(p1,p2,_)}::ps ->
filter_rec
@@ -1467,10 +1506,10 @@ and every_both pss qs q1 q2 =
let rec le_pat p q =
match (p.pat_desc, q.pat_desc) with
| (Tpat_var _|Tpat_any),_ -> true
- | Tpat_alias(p,_), _ -> le_pat p q
- | _, Tpat_alias(q,_) -> le_pat p q
+ | Tpat_alias(p,_,_), _ -> le_pat p q
+ | _, Tpat_alias(q,_,_) -> le_pat p q
| Tpat_constant(c1), Tpat_constant(c2) -> c1 = c2
- | Tpat_construct(c1,ps), Tpat_construct(c2,qs) ->
+ | Tpat_construct(_,_,c1,ps,_), Tpat_construct(_,_,c2,qs,_) ->
c1.cstr_tag = c2.cstr_tag && le_pats ps qs
| Tpat_variant(l1,Some p1,_), Tpat_variant(l2,Some p2,_) ->
(l1 = l2 && le_pat p1 p2)
@@ -1479,7 +1518,7 @@ let rec le_pat p q =
| Tpat_variant(_,_,_), Tpat_variant(_,_,_) -> false
| Tpat_tuple(ps), Tpat_tuple(qs) -> le_pats ps qs
| Tpat_lazy p, Tpat_lazy q -> le_pat p q
- | Tpat_record l1, Tpat_record l2 ->
+ | Tpat_record (l1,_), Tpat_record (l2,_) ->
let ps,qs = records_args l1 l2 in
le_pats ps qs
| Tpat_array(ps), Tpat_array(qs) ->
@@ -1507,8 +1546,8 @@ let get_mins le ps =
*)
let rec lub p q = match p.pat_desc,q.pat_desc with
-| Tpat_alias (p,_),_ -> lub p q
-| _,Tpat_alias (q,_) -> lub p q
+| Tpat_alias (p,_,_),_ -> lub p q
+| _,Tpat_alias (q,_,_) -> lub p q
| (Tpat_any|Tpat_var _),_ -> q
| _,(Tpat_any|Tpat_var _) -> p
| Tpat_or (p1,p2,_),_ -> orlub p1 p2 q
@@ -1520,19 +1559,19 @@ let rec lub p q = match p.pat_desc,q.pat_desc with
| Tpat_lazy p, Tpat_lazy q ->
let r = lub p q in
make_pat (Tpat_lazy r) p.pat_type p.pat_env
-| Tpat_construct (c1,ps1), Tpat_construct (c2,ps2)
+| Tpat_construct (lid, lid_loc, c1,ps1,_), Tpat_construct (_, _,c2,ps2,_)
when c1.cstr_tag = c2.cstr_tag ->
let rs = lubs ps1 ps2 in
- make_pat (Tpat_construct (c1,rs)) p.pat_type p.pat_env
+ make_pat (Tpat_construct (lid, lid_loc, c1,rs, false)) p.pat_type p.pat_env
| Tpat_variant(l1,Some p1,row), Tpat_variant(l2,Some p2,_)
when l1=l2 ->
let r=lub p1 p2 in
make_pat (Tpat_variant (l1,Some r,row)) p.pat_type p.pat_env
| Tpat_variant (l1,None,row), Tpat_variant(l2,None,_)
when l1 = l2 -> p
-| Tpat_record l1,Tpat_record l2 ->
+| Tpat_record (l1,closed),Tpat_record (l2,_) ->
let rs = record_lubs l1 l2 in
- make_pat (Tpat_record rs) p.pat_type p.pat_env
+ make_pat (Tpat_record (rs, closed)) p.pat_type p.pat_env
| Tpat_array ps, Tpat_array qs
when List.length ps = List.length qs ->
let rs = lubs ps qs in
@@ -1554,13 +1593,13 @@ and record_lubs l1 l2 =
let rec lub_rec l1 l2 = match l1,l2 with
| [],_ -> l2
| _,[] -> l1
- | (lbl1,p1)::rem1, (lbl2,p2)::rem2 ->
+ | (lid1, lid1_loc, lbl1,p1)::rem1, (lid2, lid2_loc, lbl2,p2)::rem2 ->
if lbl1.lbl_pos < lbl2.lbl_pos then
- (lbl1,p1)::lub_rec rem1 l2
+ (lid1, lid1_loc, lbl1,p1)::lub_rec rem1 l2
else if lbl2.lbl_pos < lbl1.lbl_pos then
- (lbl2,p2)::lub_rec l1 rem2
+ (lid2, lid2_loc, lbl2,p2)::lub_rec l1 rem2
else
- (lbl1,lub p1 p2)::lub_rec rem1 rem2 in
+ (lid1, lid1_loc, lbl1,lub p1 p2)::lub_rec rem1 rem2 in
lub_rec l1 l2
and lubs ps qs = match ps,qs with
@@ -1631,7 +1670,7 @@ let rec do_filter_var = function
let do_filter_one q pss =
let rec filter_rec = function
- | ({pat_desc = Tpat_alias(p,_)}::ps,loc)::pss ->
+ | ({pat_desc = Tpat_alias(p,_,_)}::ps,loc)::pss ->
filter_rec ((p::ps,loc)::pss)
| ({pat_desc = Tpat_or(p1,p2,_)}::ps,loc)::pss ->
filter_rec ((p1::ps,loc)::(p2::ps,loc)::pss)
@@ -1673,11 +1712,11 @@ let check_partial_all v casel =
(************************)
- let rec get_first f =
+ let rec get_first f =
function
| [] -> None
- | x :: xs ->
- match f x with
+ | x :: xs ->
+ match f x with
| None -> get_first f xs
| x -> x
@@ -1685,11 +1724,11 @@ let check_partial_all v casel =
(* conversion from Typedtree.pattern to Parsetree.pattern list *)
module Conv = struct
open Parsetree
- let mkpat desc =
+ let mkpat desc =
{ppat_desc = desc;
ppat_loc = Location.none}
- let rec select : 'a list list -> 'a list list =
+ let rec select : 'a list list -> 'a list list =
function
| xs :: [] -> List.map (fun y -> [y]) xs
| (x::xs)::ys ->
@@ -1700,48 +1739,49 @@ module Conv = struct
select (xs::ys)
| _ -> []
- let name_counter = ref 0
- let fresh () =
- let current = !name_counter in
+ let name_counter = ref 0
+ let fresh () =
+ let current = !name_counter in
name_counter := !name_counter + 1;
"#$%^@*@" ^ string_of_int current
- let conv (typed: Typedtree.pattern) :
- Parsetree.pattern list *
- (string,Types.constructor_description) Hashtbl.t *
- (string,Types.label_description) Hashtbl.t
- =
- let constrs = Hashtbl.create 0 in
- let labels = Hashtbl.create 0 in
- let rec loop pat =
+ let conv (typed: Typedtree.pattern) :
+ Parsetree.pattern list *
+ (string,Path.t * Types.constructor_description) Hashtbl.t *
+ (string,Path.t * Types.label_description) Hashtbl.t
+ =
+ let constrs = Hashtbl.create 0 in
+ let labels = Hashtbl.create 0 in
+ let rec loop pat =
match pat.pat_desc with
Tpat_or (a,b,_) ->
loop a @ loop b
| Tpat_any | Tpat_constant _ | Tpat_var _ ->
[mkpat Ppat_any]
- | Tpat_alias (p,_) -> loop p
+ | Tpat_alias (p,_,_) -> loop p
| Tpat_tuple lst ->
- let results = select (List.map loop lst) in
+ let results = select (List.map loop lst) in
List.map
(fun lst -> mkpat (Ppat_tuple lst))
results
- | Tpat_construct (cstr,lst) ->
- let id = fresh () in
- Hashtbl.add constrs id cstr;
+ | Tpat_construct (cstr_path, cstr_lid, cstr,lst,_) ->
+ let id = fresh () in
+ let lid = { cstr_lid with txt = Longident.Lident id } in
+ Hashtbl.add constrs id (cstr_path,cstr);
let results = select (List.map loop lst) in
begin match lst with
[] ->
- [mkpat (Ppat_construct(Longident.Lident id, None, false))]
+ [mkpat (Ppat_construct(lid, None, false))]
| _ ->
- List.map
+ List.map
(fun lst ->
- let arg =
+ let arg =
match lst with
[] -> assert false
| [x] -> Some x
| _ -> Some (mkpat (Ppat_tuple lst))
in
- mkpat (Ppat_construct(Longident.Lident id, arg, false)))
+ mkpat (Ppat_construct(lid, arg, false)))
results
end
| Tpat_variant(label,p_opt,row_desc) ->
@@ -1749,38 +1789,40 @@ module Conv = struct
| None ->
[mkpat (Ppat_variant(label, None))]
| Some p ->
- let results = loop p in
+ let results = loop p in
List.map
(fun p ->
mkpat (Ppat_variant(label, Some p)))
results
end
- | Tpat_record subpatterns ->
- let pats =
+ | Tpat_record (subpatterns, _closed_flag) ->
+ let pats =
select
- (List.map (fun (_,x) -> (loop x)) subpatterns)
+ (List.map (fun (_,_,_,x) -> (loop x)) subpatterns)
in
- let label_idents =
- List.map
- (fun (lbl,_) ->
- let id = fresh () in
- Hashtbl.add labels id lbl;
- Longident.Lident id)
+ let label_idents =
+ List.map
+ (fun (lbl_path,_,lbl,_) ->
+ let id = fresh () in
+ Hashtbl.add labels id (lbl_path, lbl);
+ Longident.Lident id)
subpatterns
- in
+ in
List.map
(fun lst ->
- let lst = List.combine label_idents lst in
- mkpat (Ppat_record (lst, Open)))
+ let lst = List.map2 (fun lid pat ->
+ (mknoloc lid, pat)
+ ) label_idents lst in
+ mkpat (Ppat_record (lst, Open)))
pats
| Tpat_array lst ->
- let results = select (List.map loop lst) in
+ let results = select (List.map loop lst) in
List.map (fun lst -> mkpat (Ppat_array lst)) results
| Tpat_lazy p ->
- let results = loop p in
+ let results = loop p in
List.map (fun p -> mkpat (Ppat_lazy p)) results
in
- let ps = loop typed in
+ let ps = loop typed in
(ps, constrs, labels)
end
@@ -1804,10 +1846,13 @@ let do_check_partial ?pred exhaust loc casel pss = match pss with
begin match exhaust None pss (List.length ps) with
| Rnone -> Total
| Rsome [u] ->
- let v =
- match pred with
+ let v =
+ match pred with
| Some pred ->
- let (patterns,constrs,labels) = Conv.conv u in
+ let (patterns,constrs,labels) = Conv.conv u in
+(* Hashtbl.iter (fun s (path, _) ->
+ Printf.fprintf stderr "CONV: %s -> %s \n%!" s (Path.name path)) constrs
+ ; *)
get_first (pred constrs labels) patterns
| None -> Some u
in
@@ -1838,10 +1883,10 @@ let do_check_partial ?pred exhaust loc casel pss = match pss with
fatal_error "Parmatch.check_partial"
end
-let do_check_partial_normal loc casel pss =
+let do_check_partial_normal loc casel pss =
do_check_partial exhaust loc casel pss
-let do_check_partial_gadt pred loc casel pss =
+let do_check_partial_gadt pred loc casel pss =
do_check_partial ~pred exhaust_gadt loc casel pss
@@ -1866,7 +1911,7 @@ let extendable_path path =
Path.same path Predef.path_option)
let rec collect_paths_from_pat r p = match p.pat_desc with
-| Tpat_construct({cstr_tag=(Cstr_constant _|Cstr_block _)},ps) ->
+| Tpat_construct(_, _, {cstr_tag=(Cstr_constant _|Cstr_block _)},ps,_) ->
let path = get_type_path p.pat_type p.pat_env in
List.fold_left
collect_paths_from_pat
@@ -1874,16 +1919,17 @@ let rec collect_paths_from_pat r p = match p.pat_desc with
ps
| Tpat_any|Tpat_var _|Tpat_constant _| Tpat_variant (_,None,_) -> r
| Tpat_tuple ps | Tpat_array ps
-| Tpat_construct ({cstr_tag=Cstr_exception _}, ps)->
+| Tpat_construct (_, _, {cstr_tag=Cstr_exception _}, ps,_)->
List.fold_left collect_paths_from_pat r ps
-| Tpat_record lps ->
+| Tpat_record (lps,_) ->
List.fold_left
- (fun r (_,p) -> collect_paths_from_pat r p)
+ (fun r (_, _, _, p) -> collect_paths_from_pat r p)
r lps
-| Tpat_variant (_, Some p, _) | Tpat_alias (p,_) -> collect_paths_from_pat r p
+| Tpat_variant (_, Some p, _) | Tpat_alias (p,_,_) -> collect_paths_from_pat r p
| Tpat_or (p1,p2,_) ->
collect_paths_from_pat (collect_paths_from_pat r p1) p2
-| Tpat_lazy p ->
+| Tpat_lazy p
+ ->
collect_paths_from_pat r p
@@ -1967,26 +2013,26 @@ let rec inactive pat = match pat with
false
| Tpat_any | Tpat_var _ | Tpat_constant _ | Tpat_variant (_, None, _) ->
true
-| Tpat_tuple ps | Tpat_construct (_, ps) | Tpat_array ps ->
+| Tpat_tuple ps | Tpat_construct (_, _, _, ps,_) | Tpat_array ps ->
List.for_all (fun p -> inactive p.pat_desc) ps
-| Tpat_alias (p,_) | Tpat_variant (_, Some p, _) ->
+| Tpat_alias (p,_,_) | Tpat_variant (_, Some p, _) ->
inactive p.pat_desc
-| Tpat_record ldps ->
- List.exists (fun (_, p) -> inactive p.pat_desc) ldps
+| Tpat_record (ldps,_) ->
+ List.exists (fun (_, _, _, p) -> inactive p.pat_desc) ldps
| Tpat_or (p,q,_) ->
inactive p.pat_desc && inactive q.pat_desc
-
(* A `fluid' pattern is both irrefutable and inactive *)
-let fluid pat = irrefutable pat && inactive pat.pat_desc
+let fluid pat = irrefutable pat && inactive pat.pat_desc
+
+
-
(********************************)
(* Exported exhustiveness check *)
(********************************)
@@ -1996,7 +2042,7 @@ let fluid pat = irrefutable pat && inactive pat.pat_desc
on exhaustive matches only.
*)
-let check_partial_param do_check_partial do_check_fragile loc casel =
+let check_partial_param do_check_partial do_check_fragile loc casel =
if Warnings.is_active (Warnings.Partial_match "") then begin
let pss = initial_matrix casel in
let pss = get_mins le_pats pss in
@@ -2008,11 +2054,11 @@ let check_partial_param do_check_partial do_check_fragile loc casel =
end ;
total
end else
- Partial
+ Partial
-let check_partial =
- check_partial_param
- do_check_partial_normal
+let check_partial =
+ check_partial_param
+ do_check_partial_normal
do_check_fragile_normal
let check_partial_gadt pred loc casel =
@@ -2020,7 +2066,7 @@ let check_partial_gadt pred loc casel =
let first_check = check_partial loc casel in
match first_check with
| Partial -> Partial
- | Total ->
+ | Total ->
(* checks for missing GADT constructors *)
check_partial_param (do_check_partial_gadt pred)
do_check_fragile_gadt loc casel
diff --git a/typing/parmatch.mli b/typing/parmatch.mli
index 0cfaad7b8..a19686c59 100644
--- a/typing/parmatch.mli
+++ b/typing/parmatch.mli
@@ -13,8 +13,9 @@
(* $Id$ *)
(* Detection of partial matches and unused match cases. *)
-open Types
+open Asttypes
open Typedtree
+open Types
val top_pretty : Format.formatter -> pattern -> unit
val pretty_pat : pattern -> unit
@@ -26,7 +27,7 @@ val omegas : int -> pattern list
val omega_list : 'a list -> pattern list
val normalize_pat : pattern -> pattern
val all_record_args :
- (label_description * pattern) list -> (label_description * pattern) list
+ (Path.t * Longident.t loc * label_description * pattern) list -> (Path.t * Longident.t loc * label_description * pattern) list
val le_pat : pattern -> pattern -> bool
val le_pats : pattern list -> pattern list -> bool
@@ -52,10 +53,10 @@ val complete_constrs :
val pressure_variants: Env.t -> pattern list -> unit
val check_partial: Location.t -> (pattern * expression) list -> partial
-val check_partial_gadt:
- ((string,constructor_description) Hashtbl.t ->
- (string,label_description) Hashtbl.t ->
- Parsetree.pattern -> pattern option) ->
+val check_partial_gadt:
+ ((string,Path.t * constructor_description) Hashtbl.t ->
+ (string,Path.t * label_description) Hashtbl.t ->
+ Parsetree.pattern -> pattern option) ->
Location.t -> (pattern * expression) list -> partial
val check_unused: Env.t -> (pattern * expression) list -> unit
diff --git a/typing/predef.ml b/typing/predef.ml
index 432440b17..80c38c6cb 100644
--- a/typing/predef.ml
+++ b/typing/predef.ml
@@ -19,21 +19,31 @@ open Path
open Types
open Btype
-let ident_int = Ident.create "int"
-and ident_char = Ident.create "char"
-and ident_string = Ident.create "string"
-and ident_float = Ident.create "float"
-and ident_bool = Ident.create "bool"
-and ident_unit = Ident.create "unit"
-and ident_exn = Ident.create "exn"
-and ident_array = Ident.create "array"
-and ident_list = Ident.create "list"
-and ident_format6 = Ident.create "format6"
-and ident_option = Ident.create "option"
-and ident_nativeint = Ident.create "nativeint"
-and ident_int32 = Ident.create "int32"
-and ident_int64 = Ident.create "int64"
-and ident_lazy_t = Ident.create "lazy_t"
+let builtin_idents = ref []
+
+let wrap create s =
+ let id = create s in
+ builtin_idents := (s, id) :: !builtin_idents;
+ id
+
+let ident_create = wrap Ident.create
+let ident_create_predef_exn = wrap Ident.create_predef_exn
+
+let ident_int = ident_create "int"
+and ident_char = ident_create "char"
+and ident_string = ident_create "string"
+and ident_float = ident_create "float"
+and ident_bool = ident_create "bool"
+and ident_unit = ident_create "unit"
+and ident_exn = ident_create "exn"
+and ident_array = ident_create "array"
+and ident_list = ident_create "list"
+and ident_format6 = ident_create "format6"
+and ident_option = ident_create "option"
+and ident_nativeint = ident_create "nativeint"
+and ident_int32 = ident_create "int32"
+and ident_int64 = ident_create "int64"
+and ident_lazy_t = ident_create "lazy_t"
let path_int = Pident ident_int
and path_char = Pident ident_char
@@ -66,24 +76,31 @@ and type_int32 = newgenty (Tconstr(path_int32, [], ref Mnil))
and type_int64 = newgenty (Tconstr(path_int64, [], ref Mnil))
and type_lazy_t t = newgenty (Tconstr(path_lazy_t, [t], ref Mnil))
-let ident_match_failure = Ident.create_predef_exn "Match_failure"
-and ident_out_of_memory = Ident.create_predef_exn "Out_of_memory"
-and ident_invalid_argument = Ident.create_predef_exn "Invalid_argument"
-and ident_failure = Ident.create_predef_exn "Failure"
-and ident_not_found = Ident.create_predef_exn "Not_found"
-and ident_sys_error = Ident.create_predef_exn "Sys_error"
-and ident_end_of_file = Ident.create_predef_exn "End_of_file"
-and ident_division_by_zero = Ident.create_predef_exn "Division_by_zero"
-and ident_stack_overflow = Ident.create_predef_exn "Stack_overflow"
-and ident_sys_blocked_io = Ident.create_predef_exn "Sys_blocked_io"
-and ident_assert_failure = Ident.create_predef_exn "Assert_failure"
+let ident_match_failure = ident_create_predef_exn "Match_failure"
+and ident_out_of_memory = ident_create_predef_exn "Out_of_memory"
+and ident_invalid_argument = ident_create_predef_exn "Invalid_argument"
+and ident_failure = ident_create_predef_exn "Failure"
+and ident_not_found = ident_create_predef_exn "Not_found"
+and ident_sys_error = ident_create_predef_exn "Sys_error"
+and ident_end_of_file = ident_create_predef_exn "End_of_file"
+and ident_division_by_zero = ident_create_predef_exn "Division_by_zero"
+and ident_stack_overflow = ident_create_predef_exn "Stack_overflow"
+and ident_sys_blocked_io = ident_create_predef_exn "Sys_blocked_io"
+and ident_assert_failure = ident_create_predef_exn "Assert_failure"
and ident_undefined_recursive_module =
- Ident.create_predef_exn "Undefined_recursive_module"
+ ident_create_predef_exn "Undefined_recursive_module"
let path_match_failure = Pident ident_match_failure
and path_assert_failure = Pident ident_assert_failure
and path_undefined_recursive_module = Pident ident_undefined_recursive_module
+let ident_false = ident_create "false"
+and ident_true = ident_create "true"
+and ident_void = ident_create "()"
+and ident_nil = ident_create "[]"
+and ident_cons = ident_create "::"
+and ident_none = ident_create "None"
+and ident_some = ident_create "Some"
let build_initial_env add_type add_exception empty_env =
let decl_abstr =
{type_params = [];
@@ -97,7 +114,7 @@ let build_initial_env add_type add_exception empty_env =
and decl_bool =
{type_params = [];
type_arity = 0;
- type_kind = Type_variant(["false", [], None; "true", [], None]);
+ type_kind = Type_variant([ident_false, [], None; ident_true, [], None]);
type_loc = Location.none;
type_private = Public;
type_manifest = None;
@@ -106,7 +123,7 @@ let build_initial_env add_type add_exception empty_env =
and decl_unit =
{type_params = [];
type_arity = 0;
- type_kind = Type_variant(["()", [], None]);
+ type_kind = Type_variant([ident_void, [], None]);
type_loc = Location.none;
type_private = Public;
type_manifest = None;
@@ -136,7 +153,7 @@ let build_initial_env add_type add_exception empty_env =
{type_params = [tvar];
type_arity = 1;
type_kind =
- Type_variant(["[]", [], None; "::", [tvar; type_list tvar], None]);
+ Type_variant([ident_nil, [], None; ident_cons, [tvar; type_list tvar], None]);
type_loc = Location.none;
type_private = Public;
type_manifest = None;
@@ -162,7 +179,7 @@ let build_initial_env add_type add_exception empty_env =
let tvar = newgenvar() in
{type_params = [tvar];
type_arity = 1;
- type_kind = Type_variant(["None", [], None; "Some", [tvar], None]);
+ type_kind = Type_variant([ident_none, [], None; ident_some, [tvar], None]);
type_loc = Location.none;
type_private = Public;
type_manifest = None;
@@ -225,4 +242,5 @@ let builtin_values =
be defined in this file (above!) without breaking .cmi
compatibility. *)
-let _ = Ident.set_current_time 999
+let _ = Ident.set_current_time 999
+let builtin_idents = List.rev !builtin_idents
diff --git a/typing/predef.mli b/typing/predef.mli
index 43e37965c..ced95d847 100644
--- a/typing/predef.mli
+++ b/typing/predef.mli
@@ -63,3 +63,4 @@ val build_initial_env:
(* To initialize linker tables *)
val builtin_values: (string * Ident.t) list
+val builtin_idents: (string * Ident.t) list
diff --git a/typing/printtyp.ml b/typing/printtyp.ml
index 09caa227c..49333722a 100644
--- a/typing/printtyp.ml
+++ b/typing/printtyp.ml
@@ -587,8 +587,8 @@ let rec tree_of_type_decl id decl =
begin match decl.type_kind with
| Type_abstract -> ()
| Type_variant cstrs ->
- List.iter
- (fun (_, args,ret_type_opt) ->
+ List.iter
+ (fun (_, args,ret_type_opt) ->
List.iter mark_loops args;
may mark_loops ret_type_opt)
cstrs
@@ -647,6 +647,7 @@ let rec tree_of_type_decl id decl =
(name, args, ty, priv, constraints)
and tree_of_constructor (name, args, ret_type_opt) =
+ let name = Ident.name name in
if ret_type_opt = None then (name, tree_of_typlist false args, None) else
let nm = !names in
names := [];
@@ -654,7 +655,7 @@ and tree_of_constructor (name, args, ret_type_opt) =
let args = tree_of_typlist false args in
names := nm;
(name, args, ret)
-
+
and tree_of_constructor_ret =
function
@@ -662,7 +663,7 @@ and tree_of_constructor_ret =
| Some ret_type -> Some (tree_of_typexp false ret_type)
and tree_of_label (name, mut, arg) =
- (name, mut = Mutable, tree_of_typexp false arg)
+ (Ident.name name, mut = Mutable, tree_of_typexp false arg)
let tree_of_type_declaration id decl rs =
Osig_type (tree_of_type_decl id decl, tree_of_rec rs)
@@ -719,14 +720,14 @@ let tree_of_metho sch concrete csil (lab, kind, ty) =
else csil
let rec prepare_class_type params = function
- | Tcty_constr (p, tyl, cty) ->
+ | Cty_constr (p, tyl, cty) ->
let sty = Ctype.self_type cty in
if List.memq (proxy sty) !visited_objects
|| not (List.for_all is_Tvar params)
|| List.exists (deep_occur sty) tyl
then prepare_class_type params cty
else List.iter mark_loops tyl
- | Tcty_signature sign ->
+ | Cty_signature sign ->
let sty = repr sign.cty_self in
(* Self may have a name *)
let px = proxy sty in
@@ -737,13 +738,13 @@ let rec prepare_class_type params = function
in
List.iter (fun met -> mark_loops (fst (method_type met))) fields;
Vars.iter (fun _ (_, _, ty) -> mark_loops ty) sign.cty_vars
- | Tcty_fun (_, ty, cty) ->
+ | Cty_fun (_, ty, cty) ->
mark_loops ty;
prepare_class_type params cty
let rec tree_of_class_type sch params =
function
- | Tcty_constr (p', tyl, cty) ->
+ | Cty_constr (p', tyl, cty) ->
let sty = Ctype.self_type cty in
if List.memq (proxy sty) !visited_objects
|| not (List.for_all is_Tvar params)
@@ -751,7 +752,7 @@ let rec tree_of_class_type sch params =
tree_of_class_type sch params cty
else
Octy_constr (tree_of_path p', tree_of_typlist true tyl)
- | Tcty_signature sign ->
+ | Cty_signature sign ->
let sty = repr sign.cty_self in
let self_ty =
if is_aliased sty then
@@ -783,7 +784,7 @@ let rec tree_of_class_type sch params =
List.fold_left (tree_of_metho sch sign.cty_concr) csil fields
in
Octy_signature (self_ty, List.rev csil)
- | Tcty_fun (l, ty, cty) ->
+ | Cty_fun (l, ty, cty) ->
let lab = if !print_labels && l <> "" || is_optional l then l else "" in
let ty =
if is_optional l then
@@ -867,33 +868,33 @@ let cltype_declaration id ppf cl =
(* Print a module type *)
let rec tree_of_modtype = function
- | Tmty_ident p ->
+ | Mty_ident p ->
Omty_ident (tree_of_path p)
- | Tmty_signature sg ->
+ | Mty_signature sg ->
Omty_signature (tree_of_signature sg)
- | Tmty_functor(param, ty_arg, ty_res) ->
+ | Mty_functor(param, ty_arg, ty_res) ->
Omty_functor
(Ident.name param, tree_of_modtype ty_arg, tree_of_modtype ty_res)
and tree_of_signature = function
| [] -> []
- | Tsig_value(id, decl) :: rem ->
+ | Sig_value(id, decl) :: rem ->
tree_of_value_description id decl :: tree_of_signature rem
- | Tsig_type(id, _, _) :: rem when is_row_name (Ident.name id) ->
+ | Sig_type(id, _, _) :: rem when is_row_name (Ident.name id) ->
tree_of_signature rem
- | Tsig_type(id, decl, rs) :: rem ->
+ | Sig_type(id, decl, rs) :: rem ->
Osig_type(tree_of_type_decl id decl, tree_of_rec rs) ::
tree_of_signature rem
- | Tsig_exception(id, decl) :: rem ->
+ | Sig_exception(id, decl) :: rem ->
tree_of_exception_declaration id decl :: tree_of_signature rem
- | Tsig_module(id, mty, rs) :: rem ->
+ | Sig_module(id, mty, rs) :: rem ->
Osig_module (Ident.name id, tree_of_modtype mty, tree_of_rec rs) ::
tree_of_signature rem
- | Tsig_modtype(id, decl) :: rem ->
+ | Sig_modtype(id, decl) :: rem ->
tree_of_modtype_declaration id decl :: tree_of_signature rem
- | Tsig_class(id, decl, rs) :: ctydecl :: tydecl1 :: tydecl2 :: rem ->
+ | Sig_class(id, decl, rs) :: ctydecl :: tydecl1 :: tydecl2 :: rem ->
tree_of_class_declaration id decl rs :: tree_of_signature rem
- | Tsig_cltype(id, decl, rs) :: tydecl1 :: tydecl2 :: rem ->
+ | Sig_class_type(id, decl, rs) :: tydecl1 :: tydecl2 :: rem ->
tree_of_cltype_declaration id decl rs :: tree_of_signature rem
| _ ->
assert false
@@ -901,8 +902,8 @@ and tree_of_signature = function
and tree_of_modtype_declaration id decl =
let mty =
match decl with
- | Tmodtype_abstract -> Omty_abstract
- | Tmodtype_manifest mty -> tree_of_modtype mty
+ | Modtype_abstract -> Omty_abstract
+ | Modtype_manifest mty -> tree_of_modtype mty
in
Osig_modtype (Ident.name id, mty)
diff --git a/typing/printtyp.mli b/typing/printtyp.mli
index 5417ebf41..49dba1669 100644
--- a/typing/printtyp.mli
+++ b/typing/printtyp.mli
@@ -46,12 +46,14 @@ val tree_of_module: Ident.t -> module_type -> rec_status -> out_sig_item
val modtype: formatter -> module_type -> unit
val signature: formatter -> signature -> unit
val tree_of_modtype_declaration: Ident.t -> modtype_declaration -> out_sig_item
+val tree_of_signature : Types.signature -> out_sig_item list
+val tree_of_typexp : bool -> type_expr -> out_type
val modtype_declaration: Ident.t -> formatter -> modtype_declaration -> unit
val class_type: formatter -> class_type -> unit
val tree_of_class_declaration: Ident.t -> class_declaration -> rec_status -> out_sig_item
val class_declaration: Ident.t -> formatter -> class_declaration -> unit
-val tree_of_cltype_declaration: Ident.t -> cltype_declaration -> rec_status -> out_sig_item
-val cltype_declaration: Ident.t -> formatter -> cltype_declaration -> unit
+val tree_of_cltype_declaration: Ident.t -> class_type_declaration -> rec_status -> out_sig_item
+val cltype_declaration: Ident.t -> formatter -> class_type_declaration -> unit
val type_expansion: type_expr -> Format.formatter -> type_expr -> unit
val prepare_expansion: type_expr * type_expr -> type_expr * type_expr
val trace: bool -> string -> formatter -> (type_expr * type_expr) list -> unit
diff --git a/typing/stypes.ml b/typing/stypes.ml
index 1d2c0efde..158062f21 100644
--- a/typing/stypes.ml
+++ b/typing/stypes.ml
@@ -157,7 +157,10 @@ let get_info () =
let dump filename =
if !Clflags.annotations then begin
let info = get_info () in
- let pp = formatter_of_out_channel (open_out filename) in
+ let pp =
+ match filename with
+ None -> std_formatter
+ | Some filename -> formatter_of_out_channel (open_out filename) in
sort_filter_phrases ();
ignore (List.fold_left (print_info pp) Location.none info);
phrases := [];
diff --git a/typing/stypes.mli b/typing/stypes.mli
index 02cccd800..c51c45e25 100644
--- a/typing/stypes.mli
+++ b/typing/stypes.mli
@@ -29,7 +29,7 @@ type annotation =
val record : annotation -> unit;;
val record_phrase : Location.t -> unit;;
-val dump : string -> unit;;
+val dump : string option -> unit;;
val get_location : annotation -> Location.t;;
val get_info : unit -> annotation list;;
diff --git a/typing/subst.ml b/typing/subst.ml
index a39c0a035..ce7ec24ed 100644
--- a/typing/subst.ml
+++ b/typing/subst.ml
@@ -49,7 +49,7 @@ let modtype_path s = function
Pident id as p ->
begin try
match Tbl.find id s.modtypes with
- | Tmty_ident p -> p
+ | Mty_ident p -> p
| _ -> fatal_error "Subst.modtype_path"
with Not_found -> p end
| Pdot(p, n, pos) ->
@@ -175,7 +175,7 @@ let type_declaration s decl =
| Type_variant cstrs ->
Type_variant
(List.map
- (fun (n, args, ret_type) ->
+ (fun (n, args, ret_type) ->
(n, List.map (typexp s) args, may_map (typexp s) ret_type))
cstrs)
| Type_record(lbls, rep) ->
@@ -184,7 +184,7 @@ let type_declaration s decl =
rep)
end;
type_manifest =
- begin
+ begin
match decl.type_manifest with
None -> None
| Some ty -> Some(typexp s ty)
@@ -210,12 +210,12 @@ let class_signature s sign =
let rec class_type s =
function
- Tcty_constr (p, tyl, cty) ->
- Tcty_constr (type_path s p, List.map (typexp s) tyl, class_type s cty)
- | Tcty_signature sign ->
- Tcty_signature (class_signature s sign)
- | Tcty_fun (l, ty, cty) ->
- Tcty_fun (l, typexp s ty, class_type s cty)
+ Cty_constr (p, tyl, cty) ->
+ Cty_constr (type_path s p, List.map (typexp s) tyl, class_type s cty)
+ | Cty_signature sign ->
+ Cty_signature (class_signature s sign)
+ | Cty_fun (l, ty, cty) ->
+ Cty_fun (l, typexp s ty, class_type s cty)
let class_declaration s decl =
let decl =
@@ -262,36 +262,36 @@ let exception_declaration s descr =
let rec rename_bound_idents s idents = function
[] -> (List.rev idents, s)
- | Tsig_type(id, d, _) :: sg ->
+ | Sig_type(id, d, _) :: sg ->
let id' = Ident.rename id in
rename_bound_idents (add_type id (Pident id') s) (id' :: idents) sg
- | Tsig_module(id, mty, _) :: sg ->
+ | Sig_module(id, mty, _) :: sg ->
let id' = Ident.rename id in
rename_bound_idents (add_module id (Pident id') s) (id' :: idents) sg
- | Tsig_modtype(id, d) :: sg ->
+ | Sig_modtype(id, d) :: sg ->
let id' = Ident.rename id in
- rename_bound_idents (add_modtype id (Tmty_ident(Pident id')) s)
+ rename_bound_idents (add_modtype id (Mty_ident(Pident id')) s)
(id' :: idents) sg
- | (Tsig_value(id, _) | Tsig_exception(id, _) |
- Tsig_class(id, _, _) | Tsig_cltype(id, _, _)) :: sg ->
+ | (Sig_value(id, _) | Sig_exception(id, _) |
+ Sig_class(id, _, _) | Sig_class_type(id, _, _)) :: sg ->
let id' = Ident.rename id in
rename_bound_idents s (id' :: idents) sg
let rec modtype s = function
- Tmty_ident p as mty ->
+ Mty_ident p as mty ->
begin match p with
Pident id ->
begin try Tbl.find id s.modtypes with Not_found -> mty end
| Pdot(p, n, pos) ->
- Tmty_ident(Pdot(module_path s p, n, pos))
+ Mty_ident(Pdot(module_path s p, n, pos))
| Papply(p1, p2) ->
fatal_error "Subst.modtype"
end
- | Tmty_signature sg ->
- Tmty_signature(signature s sg)
- | Tmty_functor(id, arg, res) ->
+ | Mty_signature sg ->
+ Mty_signature(signature s sg)
+ | Mty_functor(id, arg, res) ->
let id' = Ident.rename id in
- Tmty_functor(id', modtype s arg,
+ Mty_functor(id', modtype s arg,
modtype (add_module id (Pident id') s) res)
and signature s sg =
@@ -304,26 +304,26 @@ and signature s sg =
and signature_component s comp newid =
match comp with
- Tsig_value(id, d) ->
- Tsig_value(newid, value_description s d)
- | Tsig_type(id, d, rs) ->
- Tsig_type(newid, type_declaration s d, rs)
- | Tsig_exception(id, d) ->
- Tsig_exception(newid, exception_declaration s d)
- | Tsig_module(id, mty, rs) ->
- Tsig_module(newid, modtype s mty, rs)
- | Tsig_modtype(id, d) ->
- Tsig_modtype(newid, modtype_declaration s d)
- | Tsig_class(id, d, rs) ->
- Tsig_class(newid, class_declaration s d, rs)
- | Tsig_cltype(id, d, rs) ->
- Tsig_cltype(newid, cltype_declaration s d, rs)
+ Sig_value(id, d) ->
+ Sig_value(newid, value_description s d)
+ | Sig_type(id, d, rs) ->
+ Sig_type(newid, type_declaration s d, rs)
+ | Sig_exception(id, d) ->
+ Sig_exception(newid, exception_declaration s d)
+ | Sig_module(id, mty, rs) ->
+ Sig_module(newid, modtype s mty, rs)
+ | Sig_modtype(id, d) ->
+ Sig_modtype(newid, modtype_declaration s d)
+ | Sig_class(id, d, rs) ->
+ Sig_class(newid, class_declaration s d, rs)
+ | Sig_class_type(id, d, rs) ->
+ Sig_class_type(newid, cltype_declaration s d, rs)
and modtype_declaration s = function
- Tmodtype_abstract -> Tmodtype_abstract
- | Tmodtype_manifest mty -> Tmodtype_manifest(modtype s mty)
+ Modtype_abstract -> Modtype_abstract
+ | Modtype_manifest mty -> Modtype_manifest(modtype s mty)
-(* For every binding k |-> d of m1, add k |-> f d to m2
+(* For every binding k |-> d of m1, add k |-> f d to m2
and return resulting merged map. *)
let merge_tbls f m1 m2 =
diff --git a/typing/subst.mli b/typing/subst.mli
index cf9778854..b5e200829 100644
--- a/typing/subst.mli
+++ b/typing/subst.mli
@@ -48,7 +48,7 @@ val type_declaration: t -> type_declaration -> type_declaration
val exception_declaration:
t -> exception_declaration -> exception_declaration
val class_declaration: t -> class_declaration -> class_declaration
-val cltype_declaration: t -> cltype_declaration -> cltype_declaration
+val cltype_declaration: t -> class_type_declaration -> class_type_declaration
val modtype: t -> module_type -> module_type
val signature: t -> signature -> signature
val modtype_declaration: t -> modtype_declaration -> modtype_declaration
diff --git a/typing/typeclass.ml b/typing/typeclass.ml
index 9ac2bee89..91a9b45d2 100644
--- a/typing/typeclass.ml
+++ b/typing/typeclass.ml
@@ -16,7 +16,6 @@ open Parsetree
open Asttypes
open Path
open Types
-open Typedtree
open Typecore
open Typetexp
open Format
@@ -49,6 +48,14 @@ type error =
| Mutability_mismatch of string * mutable_flag
| No_overriding of string * string
+open Typedtree
+
+let ctyp desc typ env loc = { ctyp_desc = desc; ctyp_type = typ; ctyp_loc = loc; ctyp_env = env }
+let cltyp desc typ env loc = { cltyp_desc = desc; cltyp_type = typ; cltyp_loc = loc; cltyp_env = env }
+let mkcf desc loc = { cf_desc = desc; cf_loc = loc }
+let mkctf desc loc = { ctf_desc = desc; ctf_loc = loc }
+
+
exception Error of Location.t * error
@@ -78,20 +85,20 @@ let unbound_class = Path.Pident (Ident.create "")
(* Fully expand the head of a class type *)
let rec scrape_class_type =
function
- Tcty_constr (_, _, cty) -> scrape_class_type cty
+ Cty_constr (_, _, cty) -> scrape_class_type cty
| cty -> cty
(* Generalize a class type *)
let rec generalize_class_type =
function
- Tcty_constr (_, params, cty) ->
+ Cty_constr (_, params, cty) ->
List.iter Ctype.generalize params;
generalize_class_type cty
- | Tcty_signature {cty_self = sty; cty_vars = vars; cty_inher = inher} ->
+ | Cty_signature {cty_self = sty; cty_vars = vars; cty_inher = inher} ->
Ctype.generalize sty;
Vars.iter (fun _ (_, _, ty) -> Ctype.generalize ty) vars;
List.iter (fun (_,tl) -> List.iter Ctype.generalize tl) inher
- | Tcty_fun (_, ty, cty) ->
+ | Cty_fun (_, ty, cty) ->
Ctype.generalize ty;
generalize_class_type cty
@@ -108,20 +115,20 @@ let virtual_methods sign =
(* Return the constructor type associated to a class type *)
let rec constructor_type constr cty =
match cty with
- Tcty_constr (_, _, cty) ->
+ Cty_constr (_, _, cty) ->
constructor_type constr cty
- | Tcty_signature sign ->
+ | Cty_signature sign ->
constr
- | Tcty_fun (l, ty, cty) ->
+ | Cty_fun (l, ty, cty) ->
Ctype.newty (Tarrow (l, ty, constructor_type constr cty, Cok))
let rec class_body cty =
match cty with
- Tcty_constr (_, _, cty') ->
+ Cty_constr (_, _, cty') ->
cty (* Only class bodies can be abbreviated *)
- | Tcty_signature sign ->
+ | Cty_signature sign ->
cty
- | Tcty_fun (_, ty, cty) ->
+ | Cty_fun (_, ty, cty) ->
class_body cty
let extract_constraints cty =
@@ -139,22 +146,22 @@ let extract_constraints cty =
let rec abbreviate_class_type path params cty =
match cty with
- Tcty_constr (_, _, _) | Tcty_signature _ ->
- Tcty_constr (path, params, cty)
- | Tcty_fun (l, ty, cty) ->
- Tcty_fun (l, ty, abbreviate_class_type path params cty)
+ Cty_constr (_, _, _) | Cty_signature _ ->
+ Cty_constr (path, params, cty)
+ | Cty_fun (l, ty, cty) ->
+ Cty_fun (l, ty, abbreviate_class_type path params cty)
let rec closed_class_type =
function
- Tcty_constr (_, params, _) ->
+ Cty_constr (_, params, _) ->
List.for_all Ctype.closed_schema params
- | Tcty_signature sign ->
+ | Cty_signature sign ->
Ctype.closed_schema sign.cty_self
&&
Vars.fold (fun _ (_, _, ty) cc -> Ctype.closed_schema ty && cc)
sign.cty_vars
true
- | Tcty_fun (_, ty, cty) ->
+ | Cty_fun (_, ty, cty) ->
Ctype.closed_schema ty
&&
closed_class_type cty
@@ -166,22 +173,23 @@ let closed_class cty =
let rec limited_generalize rv =
function
- Tcty_constr (path, params, cty) ->
+ Cty_constr (path, params, cty) ->
List.iter (Ctype.limited_generalize rv) params;
limited_generalize rv cty
- | Tcty_signature sign ->
+ | Cty_signature sign ->
Ctype.limited_generalize rv sign.cty_self;
Vars.iter (fun _ (_, _, ty) -> Ctype.limited_generalize rv ty)
sign.cty_vars;
List.iter (fun (_, tl) -> List.iter (Ctype.limited_generalize rv) tl)
sign.cty_inher
- | Tcty_fun (_, ty, cty) ->
+ | Cty_fun (_, ty, cty) ->
Ctype.limited_generalize rv ty;
limited_generalize rv cty
(* Record a class type *)
let rc node =
- Stypes.record (Stypes.Ti_class node);
+ Cmt_format.add_saved_type (Cmt_format.Partial_class_expr node);
+ Stypes.record (Stypes.Ti_class node); (* moved to genannot *)
node
@@ -193,11 +201,14 @@ let rc node =
(* Enter a value in the method environment only *)
let enter_met_env ?check loc lab kind ty val_env met_env par_env =
let (id, val_env) =
- Env.enter_value lab {val_type = ty; val_kind = Val_unbound; val_loc = loc} val_env
+ Env.enter_value lab {val_type = ty; val_kind = Val_unbound;
+ Types.val_loc = loc} val_env
in
(id, val_env,
- Env.add_value ?check id {val_type = ty; val_kind = kind; val_loc = loc} met_env,
- Env.add_value id {val_type = ty; val_kind = Val_unbound; val_loc = loc} par_env)
+ Env.add_value ?check id {val_type = ty; val_kind = kind;
+ Types.val_loc = loc} met_env,
+ Env.add_value id {val_type = ty; val_kind = Val_unbound;
+ Types.val_loc = loc} par_env)
(* Enter an instance variable in the environment *)
let enter_val cl_num vars inh lab mut virt ty val_env met_env par_env loc =
@@ -229,7 +240,7 @@ let concr_vals vars =
let inheritance self_type env ovf concr_meths warn_vals loc parent =
match scrape_class_type parent with
- Tcty_signature cl_sig ->
+ Cty_signature cl_sig ->
(* Methods *)
begin try
@@ -250,7 +261,7 @@ let inheritance self_type env ovf concr_meths warn_vals loc parent =
Some Fresh ->
let cname =
match parent with
- Tcty_constr (p, _, _) -> Path.name p
+ Cty_constr (p, _, _) -> Path.name p
| _ -> "inherited"
in
if not (Concr.is_empty over_meths) then
@@ -278,9 +289,13 @@ let virtual_method val_env meths self_type lab priv sty loc =
let (_, ty') =
Ctype.filter_self_method val_env lab priv meths self_type
in
- let ty = transl_simple_type val_env false sty in
- try Ctype.unify val_env ty ty' with Ctype.Unify trace ->
- raise(Error(loc, Field_type_mismatch ("method", lab, trace)))
+ let cty = transl_simple_type val_env false sty in
+ let ty = cty.ctyp_type in
+ begin
+ try Ctype.unify val_env ty ty' with Ctype.Unify trace ->
+ raise(Error(loc, Field_type_mismatch ("method", lab, trace)));
+ end;
+ cty
let delayed_meth_specs = ref []
@@ -293,24 +308,43 @@ let declare_method val_env meths self_type lab priv sty loc =
raise(Error(loc, Field_type_mismatch ("method", lab, trace)))
in
match sty.ptyp_desc, priv with
- Ptyp_poly ([],sty), Public ->
+ Ptyp_poly ([],sty'), Public ->
+(* TODO: we moved the [transl_simple_type_univars] outside of the lazy,
+so that we can get an immediate value. Is that correct ? Ask Jacques. *)
+ let returned_cty = ctyp Ttyp_any (Ctype.newty Tnil) val_env loc in
delayed_meth_specs :=
- lazy (unif (transl_simple_type_univars val_env sty)) ::
- !delayed_meth_specs
- | _ -> unif (transl_simple_type val_env false sty)
+ lazy (
+ let cty = transl_simple_type_univars val_env sty' in
+ let ty = cty.ctyp_type in
+ unif ty;
+ returned_cty.ctyp_desc <- Ttyp_poly ([], cty);
+ returned_cty.ctyp_type <- ty;
+ ) ::
+ !delayed_meth_specs;
+ returned_cty
+ | _ ->
+ let cty = transl_simple_type val_env false sty in
+ let ty = cty.ctyp_type in
+ unif ty;
+ cty
let type_constraint val_env sty sty' loc =
- let ty = transl_simple_type val_env false sty in
- let ty' = transl_simple_type val_env false sty' in
- try Ctype.unify val_env ty ty' with Ctype.Unify trace ->
- raise(Error(loc, Unconsistent_constraint trace))
+ let cty = transl_simple_type val_env false sty in
+ let ty = cty.ctyp_type in
+ let cty' = transl_simple_type val_env false sty' in
+ let ty' = cty'.ctyp_type in
+ begin
+ try Ctype.unify val_env ty ty' with Ctype.Unify trace ->
+ raise(Error(loc, Unconsistent_constraint trace));
+ end;
+ (cty, cty')
let mkpat d = { ppat_desc = d; ppat_loc = Location.none }
let make_method cl_num expr =
{ pexp_desc =
Pexp_function ("", None,
- [mkpat (Ppat_alias (mkpat(Ppat_var "self-*"),
- "self-" ^ cl_num)),
+ [mkpat (Ppat_alias (mkpat(Ppat_var (mknoloc "self-*")),
+ mknoloc ("self-" ^ cl_num))),
expr]);
pexp_loc = expr.pexp_loc }
@@ -325,42 +359,55 @@ let add_val env loc lab (mut, virt, ty) val_sig =
in
Vars.add lab (mut, virt, ty) val_sig
-let rec class_type_field env self_type meths (val_sig, concr_meths, inher) =
- function
+let rec class_type_field env self_type meths (fields, val_sig, concr_meths, inher) ctf =
+ let loc = ctf.pctf_loc in
+ match ctf.pctf_desc with
Pctf_inher sparent ->
let parent = class_type env sparent in
let inher =
- match parent with
- Tcty_constr (p, tl, _) -> (p, tl) :: inher
+ match parent.cltyp_type with
+ Cty_constr (p, tl, _) -> (p, tl) :: inher
| _ -> inher
in
let (cl_sig, concr_meths, _) =
inheritance self_type env None concr_meths Concr.empty sparent.pcty_loc
- parent
+ parent.cltyp_type
in
let val_sig =
Vars.fold (add_val env sparent.pcty_loc) cl_sig.cty_vars val_sig in
- (val_sig, concr_meths, inher)
-
- | Pctf_val (lab, mut, virt, sty, loc) ->
- let ty = transl_simple_type env false sty in
- (add_val env loc lab (mut, virt, ty) val_sig, concr_meths, inher)
-
- | Pctf_virt (lab, priv, sty, loc) ->
- declare_method env meths self_type lab priv sty loc;
- (val_sig, concr_meths, inher)
-
- | Pctf_meth (lab, priv, sty, loc) ->
- declare_method env meths self_type lab priv sty loc;
- (val_sig, Concr.add lab concr_meths, inher)
-
- | Pctf_cstr (sty, sty', loc) ->
- type_constraint env sty sty' loc;
- (val_sig, concr_meths, inher)
-
-and class_signature env sty sign =
+ (mkctf (Tctf_inher parent) loc :: fields,
+ val_sig, concr_meths, inher)
+
+ | Pctf_val (lab, mut, virt, sty) ->
+ let cty = transl_simple_type env false sty in
+ let ty = cty.ctyp_type in
+ (mkctf (Tctf_val (lab, mut, virt, cty)) loc :: fields,
+ add_val env ctf.pctf_loc lab (mut, virt, ty) val_sig, concr_meths, inher)
+
+ | Pctf_virt (lab, priv, sty) ->
+ let cty =
+ declare_method env meths self_type lab priv sty ctf.pctf_loc
+ in
+ (mkctf (Tctf_virt (lab, priv, cty)) loc :: fields,
+ val_sig, concr_meths, inher)
+
+ | Pctf_meth (lab, priv, sty) ->
+ let cty =
+ declare_method env meths self_type lab priv sty ctf.pctf_loc in
+ (mkctf (Tctf_meth (lab, priv, cty)) loc :: fields,
+ val_sig, Concr.add lab concr_meths, inher)
+
+ | Pctf_cstr (sty, sty') ->
+ let (cty, cty') = type_constraint env sty sty' ctf.pctf_loc in
+ (mkctf (Tctf_cstr (cty, cty')) loc :: fields,
+ val_sig, concr_meths, inher)
+
+and class_signature env sty sign loc =
let meths = ref Meths.empty in
- let self_type = Ctype.expand_head env (transl_simple_type env false sty) in
+ let self_cty = transl_simple_type env false sty in
+ let self_cty = { self_cty with
+ ctyp_type = Ctype.expand_head env self_cty.ctyp_type } in
+ let self_type = self_cty.ctyp_type in
(* Check that the binder is a correct type, and introduce a dummy
method preventing self type from being closed. *)
@@ -374,45 +421,62 @@ and class_signature env sty sign =
end;
(* Class type fields *)
- let (val_sig, concr_meths, inher) =
+ let (fields, val_sig, concr_meths, inher) =
List.fold_left (class_type_field env self_type meths)
- (Vars.empty, Concr.empty, [])
+ ([], Vars.empty, Concr.empty, [])
sign
in
-
- {cty_self = self_type;
+ let cty = {cty_self = self_type;
cty_vars = val_sig;
cty_concr = concr_meths;
cty_inher = inher}
+ in
+ { csig_self = self_cty;
+ csig_fields = fields;
+ csig_type = cty;
+ csig_loc = loc;
+ }
and class_type env scty =
+ let loc = scty.pcty_loc in
match scty.pcty_desc with
Pcty_constr (lid, styl) ->
- let (path, decl) = Typetexp.find_cltype env scty.pcty_loc lid in
+ let (path, decl) = Typetexp.find_class_type env scty.pcty_loc lid.txt in
if Path.same decl.clty_path unbound_class then
- raise(Error(scty.pcty_loc, Unbound_class_type_2 lid));
+ raise(Error(scty.pcty_loc, Unbound_class_type_2 lid.txt));
let (params, clty) =
Ctype.instance_class decl.clty_params decl.clty_type
in
if List.length params <> List.length styl then
raise(Error(scty.pcty_loc,
- Parameter_arity_mismatch (lid, List.length params,
+ Parameter_arity_mismatch (lid.txt, List.length params,
List.length styl)));
- List.iter2
+ let ctys = List.map2
(fun sty ty ->
- let ty' = transl_simple_type env false sty in
+ let cty' = transl_simple_type env false sty in
+ let ty' = cty'.ctyp_type in
+ begin
try Ctype.unify env ty' ty with Ctype.Unify trace ->
- raise(Error(sty.ptyp_loc, Parameter_mismatch trace)))
- styl params;
- Tcty_constr (path, params, clty)
+ raise(Error(sty.ptyp_loc, Parameter_mismatch trace))
+ end;
+ cty'
+ ) styl params
+ in
+ let typ = Cty_constr (path, params, clty) in
+ cltyp (Tcty_constr ( path, lid , ctys)) typ env loc
- | Pcty_signature (sty, sign) ->
- Tcty_signature (class_signature env sty sign)
+ | Pcty_signature pcsig ->
+ let clsig = class_signature env
+ pcsig.pcsig_self pcsig.pcsig_fields pcsig.pcsig_loc in
+ let typ = Cty_signature clsig.csig_type in
+ cltyp (Tcty_signature clsig) typ env loc
| Pcty_fun (l, sty, scty) ->
- let ty = transl_simple_type env false sty in
- let cty = class_type env scty in
- Tcty_fun (l, ty, cty)
+ let cty = transl_simple_type env false sty in
+ let ty = cty.ctyp_type in
+ let clty = class_type env scty in
+ let typ = Cty_fun (l, ty, clty.cltyp_type) in
+ cltyp (Tcty_fun (l, cty, clty)) typ env loc
let class_type env scty =
delayed_meth_specs := [];
@@ -424,13 +488,15 @@ let class_type env scty =
(*******************************)
let rec class_field cl_num self_type meths vars
- (val_env, met_env, par_env, fields, concr_meths, warn_vals, inher) =
- function
+ (val_env, met_env, par_env, fields, concr_meths, warn_vals, inher)
+ cf =
+ let loc = cf.pcf_loc in
+ match cf.pcf_desc with
Pcf_inher (ovf, sparent, super) ->
let parent = class_expr cl_num val_env par_env sparent in
let inher =
match parent.cl_type with
- Tcty_constr (p, tl, _) -> (p, tl) :: inher
+ Cty_constr (p, tl, _) -> (p, tl) :: inher
| _ -> inher
in
let (cl_sig, concr_meths, warn_vals) =
@@ -468,31 +534,32 @@ let rec class_field cl_num self_type meths vars
(val_env, met_env, par_env)
in
(val_env, met_env, par_env,
- lazy(Cf_inher (parent, inh_vars, inh_meths))::fields,
+ lazy(mkcf (Tcf_inher (ovf, parent, super, inh_vars, inh_meths)) loc)::fields,
concr_meths, warn_vals, inher)
- | Pcf_valvirt (lab, mut, styp, loc) ->
+ | Pcf_valvirt (lab, mut, styp) ->
if !Clflags.principal then Ctype.begin_def ();
- let ty = Typetexp.transl_simple_type val_env false styp in
+ let cty = Typetexp.transl_simple_type val_env false styp in
+ let ty = cty.ctyp_type in
if !Clflags.principal then begin
Ctype.end_def ();
Ctype.generalize_structure ty
end;
let (id, val_env, met_env', par_env) =
- enter_val cl_num vars false lab mut Virtual ty
+ enter_val cl_num vars false lab.txt mut Virtual ty
val_env met_env par_env loc
in
(val_env, met_env', par_env,
- lazy(Cf_val (lab, id, None, met_env' == met_env)) :: fields,
+ lazy(mkcf (Tcf_val (lab.txt, lab, mut, id, Tcfk_virtual cty, met_env' == met_env)) loc) :: fields,
concr_meths, warn_vals, inher)
- | Pcf_val (lab, mut, ovf, sexp, loc) ->
- if Concr.mem lab warn_vals then begin
+ | Pcf_val (lab, mut, ovf, sexp) ->
+ if Concr.mem lab.txt warn_vals then begin
if ovf = Fresh then
- Location.prerr_warning loc (Warnings.Instance_variable_override[lab])
+ Location.prerr_warning lab.loc (Warnings.Instance_variable_override[lab.txt])
end else begin
if ovf = Override then
- raise(Error(loc, No_overriding ("instance variable", lab)))
+ raise(Error(loc, No_overriding ("instance variable", lab.txt)))
end;
if !Clflags.principal then Ctype.begin_def ();
let exp =
@@ -504,33 +571,36 @@ let rec class_field cl_num self_type meths vars
Ctype.generalize_structure exp.exp_type
end;
let (id, val_env, met_env', par_env) =
- enter_val cl_num vars false lab mut Concrete exp.exp_type
+ enter_val cl_num vars false lab.txt mut Concrete exp.exp_type
val_env met_env par_env loc
in
(val_env, met_env', par_env,
- lazy(Cf_val (lab, id, Some exp, met_env' == met_env)) :: fields,
- concr_meths, Concr.add lab warn_vals, inher)
+ lazy(mkcf (Tcf_val (lab.txt, lab, mut, id, Tcfk_concrete exp, met_env' == met_env)) loc) :: fields,
+ concr_meths, Concr.add lab.txt warn_vals, inher)
- | Pcf_virt (lab, priv, sty, loc) ->
- virtual_method val_env meths self_type lab priv sty loc;
- (val_env, met_env, par_env, fields, concr_meths, warn_vals, inher)
+ | Pcf_virt (lab, priv, sty) ->
+ let cty = virtual_method val_env meths self_type lab.txt priv sty loc in
+ (val_env, met_env, par_env,
+ lazy(mkcf(Tcf_meth (lab.txt, lab, priv, Tcfk_virtual cty, true)) loc) ::fields,
+ concr_meths, warn_vals, inher)
- | Pcf_meth (lab, priv, ovf, expr, loc) ->
- if Concr.mem lab concr_meths then begin
+ | Pcf_meth (lab, priv, ovf, expr) ->
+ if Concr.mem lab.txt concr_meths then begin
if ovf = Fresh then
- Location.prerr_warning loc (Warnings.Method_override [lab])
+ Location.prerr_warning loc (Warnings.Method_override [lab.txt])
end else begin
- if ovf = Override then raise(Error(loc, No_overriding("method", lab)))
+ if ovf = Override then raise(Error(loc, No_overriding("method", lab.txt)))
end;
let (_, ty) =
- Ctype.filter_self_method val_env lab priv meths self_type
+ Ctype.filter_self_method val_env lab.txt priv meths self_type
in
begin try match expr.pexp_desc with
Pexp_poly (sbody, sty) ->
begin match sty with None -> ()
- | Some sty ->
- Ctype.unify val_env
- (Typetexp.transl_simple_type val_env false sty) ty
+ | Some sty ->
+ let cty' = Typetexp.transl_simple_type val_env false sty in
+ let ty' = cty'.ctyp_type in
+ Ctype.unify val_env ty' ty
end;
begin match (Ctype.repr ty).desc with
Tvar _ ->
@@ -545,7 +615,7 @@ let rec class_field cl_num self_type meths vars
end
| _ -> assert false
with Ctype.Unify trace ->
- raise(Error(loc, Field_type_mismatch ("method", lab, trace)))
+ raise(Error(loc, Field_type_mismatch ("method", lab.txt, trace)))
end;
let meth_expr = make_method cl_num expr in
(* backup variables for Pexp_override *)
@@ -559,14 +629,19 @@ let rec class_field cl_num self_type meths vars
vars := vars_local;
let texp = type_expect met_env meth_expr meth_type in
Ctype.end_def ();
- Cf_meth (lab, texp)
+ mkcf (Tcf_meth (lab.txt, lab, priv, Tcfk_concrete texp,
+ match ovf with
+ Override -> true
+ | Fresh -> false)) loc
end in
(val_env, met_env, par_env, field::fields,
- Concr.add lab concr_meths, warn_vals, inher)
+ Concr.add lab.txt concr_meths, warn_vals, inher)
- | Pcf_cstr (sty, sty', loc) ->
- type_constraint val_env sty sty' loc;
- (val_env, met_env, par_env, fields, concr_meths, warn_vals, inher)
+ | Pcf_constr (sty, sty') ->
+ let (cty, cty') = type_constraint val_env sty sty' loc in
+ (val_env, met_env, par_env,
+ lazy (mkcf (Tcf_constr (cty, cty')) loc) :: fields,
+ concr_meths, warn_vals, inher)
| Pcf_init expr ->
let expr = make_method cl_num expr in
@@ -581,11 +656,12 @@ let rec class_field cl_num self_type meths vars
vars := vars_local;
let texp = type_expect met_env expr meth_type in
Ctype.end_def ();
- Cf_init texp
+ mkcf (Tcf_init texp) loc
end in
(val_env, met_env, par_env, field::fields, concr_meths, warn_vals, inher)
-and class_structure cl_num final val_env met_env loc (spat, str) =
+and class_structure cl_num final val_env met_env loc
+ { pcstr_pat = spat; pcstr_fields = str } =
(* Environment for substructures *)
let par_env = met_env in
@@ -638,7 +714,7 @@ and class_structure cl_num final val_env met_env loc (spat, str) =
{cty_self = public_self;
cty_vars = Vars.map (fun (id, mut, vr, ty) -> (mut, vr, ty)) !vars;
cty_concr = concr_meths;
- cty_inher = inher} in
+ cty_inher = inher} in
let methods = get_methods self_type in
let priv_meths =
List.filter (fun (_,kind,_) -> Btype.field_kind_repr kind <> Fpresent)
@@ -691,18 +767,22 @@ and class_structure cl_num final val_env met_env loc (spat, str) =
let added = List.filter (fun x -> List.mem x l1) l2 in
if added <> [] then
Location.prerr_warning loc (Warnings.Implicit_public_methods added);
- {cl_field = fields; cl_meths = meths},
- if final then sign else
- {sign with cty_self = Ctype.expand_head val_env public_self}
+ let sign = if final then sign else
+ {sign with cty_self = Ctype.expand_head val_env public_self} in
+ {
+ cstr_pat = pat;
+ cstr_fields = fields;
+ cstr_type = sign;
+ cstr_meths = meths}, sign (* redondant, since already in cstr_type *)
and class_expr cl_num val_env met_env scl =
match scl.pcl_desc with
Pcl_constr (lid, styl) ->
- let (path, decl) = Typetexp.find_class val_env scl.pcl_loc lid in
+ let (path, decl) = Typetexp.find_class val_env scl.pcl_loc lid.txt in
if Path.same decl.cty_path unbound_class then
- raise(Error(scl.pcl_loc, Unbound_class_2 lid));
+ raise(Error(scl.pcl_loc, Unbound_class_2 lid.txt));
let tyl = List.map
- (fun sty -> transl_simple_type val_env false sty, sty.ptyp_loc)
+ (fun sty -> transl_simple_type val_env false sty)
styl
in
let (params, clty) =
@@ -711,51 +791,52 @@ and class_expr cl_num val_env met_env scl =
let clty' = abbreviate_class_type path params clty in
if List.length params <> List.length tyl then
raise(Error(scl.pcl_loc,
- Parameter_arity_mismatch (lid, List.length params,
+ Parameter_arity_mismatch (lid.txt, List.length params,
List.length tyl)));
List.iter2
- (fun (ty',loc) ty ->
+ (fun cty' ty ->
+ let ty' = cty'.ctyp_type in
try Ctype.unify val_env ty' ty with Ctype.Unify trace ->
- raise(Error(loc, Parameter_mismatch trace)))
+ raise(Error(cty'.ctyp_loc, Parameter_mismatch trace)))
tyl params;
let cl =
- rc {cl_desc = Tclass_ident path;
+ rc {cl_desc = Tcl_ident (path, lid, tyl);
cl_loc = scl.pcl_loc;
cl_type = clty';
cl_env = val_env}
in
let (vals, meths, concrs) = extract_constraints clty in
- rc {cl_desc = Tclass_constraint (cl, vals, meths, concrs);
+ rc {cl_desc = Tcl_constraint (cl, None, vals, meths, concrs);
cl_loc = scl.pcl_loc;
cl_type = clty';
cl_env = val_env}
| Pcl_structure cl_str ->
let (desc, ty) =
class_structure cl_num false val_env met_env scl.pcl_loc cl_str in
- rc {cl_desc = Tclass_structure desc;
+ rc {cl_desc = Tcl_structure desc;
cl_loc = scl.pcl_loc;
- cl_type = Tcty_signature ty;
+ cl_type = Cty_signature ty;
cl_env = val_env}
| Pcl_fun (l, Some default, spat, sbody) ->
let loc = default.pexp_loc in
let scases =
[{ppat_loc = loc; ppat_desc =
- Ppat_construct(Longident.(Ldot (Lident"*predef*", "Some")),
- Some{ppat_loc = loc; ppat_desc = Ppat_var"*sth*"},
+ Ppat_construct(mknoloc (Longident.(Ldot (Lident"*predef*", "Some"))),
+ Some{ppat_loc = loc; ppat_desc = Ppat_var (mknoloc "*sth*")},
false)},
- {pexp_loc = loc; pexp_desc = Pexp_ident(Longident.Lident"*sth*")};
+ {pexp_loc = loc; pexp_desc = Pexp_ident(mknoloc (Longident.Lident"*sth*"))};
{ppat_loc = loc; ppat_desc =
- Ppat_construct(Longident.(Ldot (Lident"*predef*", "None")),
+ Ppat_construct(mknoloc (Longident.(Ldot (Lident"*predef*", "None"))),
None, false)},
default] in
let smatch =
{pexp_loc = loc; pexp_desc =
Pexp_match({pexp_loc = loc; pexp_desc =
- Pexp_ident(Longident.Lident"*opt*")},
+ Pexp_ident(mknoloc (Longident.Lident"*opt*"))},
scases)} in
let sfun =
{pcl_loc = scl.pcl_loc; pcl_desc =
- Pcl_fun(l, None, {ppat_loc = loc; ppat_desc = Ppat_var"*opt*"},
+ Pcl_fun(l, None, {ppat_loc = loc; ppat_desc = Ppat_var (mknoloc "*opt*")},
{pcl_loc = scl.pcl_loc; pcl_desc =
Pcl_let(Default, [spat, smatch], sbody)})}
in
@@ -771,13 +852,13 @@ and class_expr cl_num val_env met_env scl =
end;
let pv =
List.map
- (function (id, id', ty) ->
+ (function (id, id_loc, id', ty) ->
let path = Pident id' in
let vd = Env.find_value path val_env' (* do not mark the value as being used *) in
- (id,
+ (id, id_loc,
{
- exp_desc = Texp_ident(path, vd);
- exp_loc = Location.none;
+ exp_desc = Texp_ident(path, mknoloc (Longident.Lident (Ident.name id)), vd);
+ exp_loc = Location.none; exp_extra = [];
exp_type = Ctype.instance val_env' vd.val_type;
exp_env = val_env'
})
@@ -785,16 +866,16 @@ and class_expr cl_num val_env met_env scl =
pv
in
let not_function = function
- Tcty_fun _ -> false
+ Cty_fun _ -> false
| _ -> true
in
let partial =
Parmatch.check_partial pat.pat_loc
[pat, (* Dummy expression *)
{exp_desc = Texp_constant (Asttypes.Const_int 1);
- exp_loc = Location.none;
+ exp_loc = Location.none; exp_extra = [];
exp_type = Ctype.none;
- exp_env = Env.empty }]
+ exp_env = Env.empty }]
in
Ctype.raise_nongen_level ();
let cl = class_expr cl_num val_env' met_env scl' in
@@ -802,16 +883,16 @@ and class_expr cl_num val_env met_env scl =
if Btype.is_optional l && not_function cl.cl_type then
Location.prerr_warning pat.pat_loc
Warnings.Unerasable_optional_argument;
- rc {cl_desc = Tclass_fun (pat, pv, cl, partial);
+ rc {cl_desc = Tcl_fun (l, pat, pv, cl, partial);
cl_loc = scl.pcl_loc;
- cl_type = Tcty_fun
+ cl_type = Cty_fun
(l, Ctype.instance_def pat.pat_type, cl.cl_type);
cl_env = val_env}
| Pcl_apply (scl', sargs) ->
let cl = class_expr cl_num val_env met_env scl' in
let rec nonopt_labels ls ty_fun =
match ty_fun with
- | Tcty_fun (l, _, ty_res) ->
+ | Cty_fun (l, _, ty_res) ->
if Btype.is_optional l then nonopt_labels ls ty_res
else nonopt_labels (l::ls) ty_res
| _ -> ls
@@ -829,7 +910,7 @@ and class_expr cl_num val_env met_env scl =
in
let rec type_args args omitted ty_fun sargs more_sargs =
match ty_fun with
- | Tcty_fun (l, ty, ty_fun) when sargs <> [] || more_sargs <> [] ->
+ | Cty_fun (l, ty, ty_fun) when sargs <> [] || more_sargs <> [] ->
let name = Btype.label_name l
and optional =
if Btype.is_optional l then Optional else Required in
@@ -872,7 +953,7 @@ and class_expr cl_num val_env met_env scl =
else None
in
let omitted = if arg = None then (l,ty) :: omitted else omitted in
- type_args ((arg,optional)::args) omitted ty_fun sargs more_sargs
+ type_args ((l,arg,optional)::args) omitted ty_fun sargs more_sargs
| _ ->
match sargs @ more_sargs with
(l, sarg0)::_ ->
@@ -883,7 +964,7 @@ and class_expr cl_num val_env met_env scl =
| [] ->
(List.rev args,
List.fold_left
- (fun ty_fun (l,ty) -> Tcty_fun(l,ty,ty_fun))
+ (fun ty_fun (l,ty) -> Cty_fun(l,ty,ty_fun))
ty_fun omitted)
in
let (args, cty) =
@@ -892,7 +973,7 @@ and class_expr cl_num val_env met_env scl =
else
type_args [] [] cl.cl_type sargs []
in
- rc {cl_desc = Tclass_apply (cl, args);
+ rc {cl_desc = Tcl_apply (cl, args);
cl_loc = scl.pcl_loc;
cl_type = cty;
cl_env = val_env}
@@ -905,14 +986,14 @@ and class_expr cl_num val_env met_env scl =
in
let (vals, met_env) =
List.fold_right
- (fun id (vals, met_env) ->
+ (fun (id, id_loc) (vals, met_env) ->
let path = Pident id in
let vd = Env.find_value path val_env in (* do not mark the value as used *)
Ctype.begin_def ();
let expr =
{
- exp_desc = Texp_ident(path, vd);
- exp_loc = Location.none;
+ exp_desc = Texp_ident(path, mknoloc (Longident.Lident (Ident.name id)), vd);
+ exp_loc = Location.none; exp_extra = [];
exp_type = Ctype.instance val_env vd.val_type;
exp_env = val_env;
}
@@ -922,18 +1003,18 @@ and class_expr cl_num val_env met_env scl =
let desc =
{val_type = expr.exp_type; val_kind = Val_ivar (Immutable,
cl_num);
- val_loc = vd.val_loc;
+ Types.val_loc = vd.Types.val_loc;
}
in
let id' = Ident.create (Ident.name id) in
- ((id', expr)
+ ((id', id_loc, expr)
:: vals,
Env.add_value id' desc met_env))
- (let_bound_idents defs)
+ (let_bound_idents_with_loc defs)
([], met_env)
in
let cl = class_expr cl_num val_env met_env scl' in
- rc {cl_desc = Tclass_let (rec_flag, defs, vals, cl);
+ rc {cl_desc = Tcl_let (rec_flag, defs, vals, cl);
cl_loc = scl.pcl_loc;
cl_type = cl.cl_type;
cl_env = val_env}
@@ -949,16 +1030,16 @@ and class_expr cl_num val_env met_env scl =
limited_generalize (Ctype.row_variable (Ctype.self_type cl.cl_type))
cl.cl_type;
- limited_generalize (Ctype.row_variable (Ctype.self_type clty)) clty;
+ limited_generalize (Ctype.row_variable (Ctype.self_type clty.cltyp_type)) clty.cltyp_type;
- begin match Includeclass.class_types val_env cl.cl_type clty with
+ begin match Includeclass.class_types val_env cl.cl_type clty.cltyp_type with
[] -> ()
| error -> raise(Error(cl.cl_loc, Class_match_failure error))
end;
- let (vals, meths, concrs) = extract_constraints clty in
- rc {cl_desc = Tclass_constraint (cl, vals, meths, concrs);
+ let (vals, meths, concrs) = extract_constraints clty.cltyp_type in
+ rc {cl_desc = Tcl_constraint (cl, Some clty, vals, meths, concrs);
cl_loc = scl.pcl_loc;
- cl_type = snd (Ctype.instance_class [] clty);
+ cl_type = snd (Ctype.instance_class [] clty.cltyp_type);
cl_env = val_env}
(*******************************)
@@ -1024,7 +1105,7 @@ let initial_env define_class approx
let constr_type = approx cl.pci_expr in
if !Clflags.principal then Ctype.generalize_spine constr_type;
let dummy_cty =
- Tcty_signature
+ Cty_signature
{ cty_self = Ctype.newvar ();
cty_vars = Vars.empty;
cty_concr = Concr.empty;
@@ -1071,7 +1152,7 @@ let class_infos define_class kind
let params =
try
let params, loc = cl.pci_params in
- List.map (enter_type_variable true loc) params
+ List.map (fun x -> enter_type_variable true loc x.txt) params
with Already_bound ->
raise(Error(snd cl.pci_params, Repeated_parameter))
in
@@ -1155,7 +1236,7 @@ let class_infos define_class kind
(Ctype.instance env constr_type)
with Ctype.Unify trace ->
raise(Error(cl.pci_loc,
- Constructor_type_mismatch (cl.pci_name, trace)))
+ Constructor_type_mismatch (cl.pci_name.txt, trace)))
end;
(* Class and class type temporary definitions *)
@@ -1286,23 +1367,38 @@ let final_decl env define_class
raise(Error(cl.pci_loc, Unbound_type_var(printer, reason)))
end;
- (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
- arity, pub_meths, coe, expr, (cl.pci_variance, cl.pci_loc))
+ (id, cl.pci_name, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
+ arity, pub_meths, coe, expr,
+ { ci_variance = cl.pci_variance;
+ ci_loc = cl.pci_loc;
+ ci_virt = cl.pci_virt;
+ ci_params = cl.pci_params;
+(* TODO : check that we have the correct use of identifiers *)
+ ci_id_name = cl.pci_name;
+ ci_id_class = id;
+ ci_id_class_type = ty_id;
+ ci_id_object = obj_id;
+ ci_id_typesharp = cl_id;
+ ci_expr = expr;
+ ci_decl = clty;
+ ci_type_decl = cltydef;
+ })
+(* (cl.pci_variance, cl.pci_loc)) *)
let extract_type_decls
- (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
+ (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
arity, pub_meths, coe, expr, required) decls =
(obj_id, obj_abbr, cl_abbr, clty, cltydef, required) :: decls
let merge_type_decls
- (id, _clty, ty_id, _cltydef, obj_id, _obj_abbr, cl_id, _cl_abbr,
+ (id, id_loc, _clty, ty_id, _cltydef, obj_id, _obj_abbr, cl_id, _cl_abbr,
arity, pub_meths, coe, expr, req) (obj_abbr, cl_abbr, clty, cltydef) =
- (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
- arity, pub_meths, coe, expr)
+ (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
+ arity, pub_meths, coe, expr, req)
let final_env define_class env
- (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
- arity, pub_meths, coe, expr) =
+ (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
+ arity, pub_meths, coe, expr, req) =
(* Add definitions after cleaning them *)
Env.add_type obj_id (Subst.type_declaration Subst.identity obj_abbr) (
Env.add_type cl_id (Subst.type_declaration Subst.identity cl_abbr) (
@@ -1313,8 +1409,8 @@ let final_env define_class env
(* Check that #c is coercible to c if there is a self-coercion *)
let check_coercions env
- (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
- arity, pub_meths, coercion_locs, expr) =
+ (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
+ arity, pub_meths, coercion_locs, expr, req) =
begin match coercion_locs with [] -> ()
| loc :: _ ->
let cl_ty, obj_ty =
@@ -1336,8 +1432,8 @@ let check_coercions env
if not (Ctype.opened_object cl_ty) then
raise(Error(loc, Cannot_coerce_self obj_ty))
end;
- (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
- arity, pub_meths, expr)
+ (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr,
+ arity, pub_meths, req)
(*******************************)
@@ -1346,8 +1442,8 @@ let type_classes define_class approx kind env cls =
List.map
(function cl ->
(cl,
- Ident.create cl.pci_name, Ident.create cl.pci_name,
- Ident.create cl.pci_name, Ident.create ("#" ^ cl.pci_name)))
+ Ident.create cl.pci_name.txt, Ident.create cl.pci_name.txt,
+ Ident.create cl.pci_name.txt, Ident.create ("#" ^ cl.pci_name.txt)))
cls
in
Ctype.init_def (Ident.current_time ());
@@ -1375,7 +1471,7 @@ let class_declaration env sexpr =
let class_description env sexpr =
let expr = class_type env sexpr in
- (expr, expr)
+ (expr, expr.cltyp_type)
let class_declarations env cls =
type_classes true approx_declaration class_declaration env cls
@@ -1389,14 +1485,14 @@ let class_type_declarations env cls =
in
(List.map
(function
- (_, _, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, _, _, _) ->
- (ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr))
+ (_, id_loc, _, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, _, _, ci) ->
+ (ty_id, id_loc, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, ci))
decl,
env)
let rec unify_parents env ty cl =
match cl.cl_desc with
- Tclass_ident p ->
+ Tcl_ident (p, _, _) ->
begin try
let decl = Env.find_class p env in
let _, body = Ctype.find_cltype_for_path env decl.cty_path in
@@ -1405,16 +1501,16 @@ let rec unify_parents env ty cl =
Not_found -> ()
| exn -> assert false
end
- | Tclass_structure st -> unify_parents_struct env ty st
- | Tclass_fun (_, _, cl, _)
- | Tclass_apply (cl, _)
- | Tclass_let (_, _, _, cl)
- | Tclass_constraint (cl, _, _, _) -> unify_parents env ty cl
+ | Tcl_structure st -> unify_parents_struct env ty st
+ | Tcl_fun (_, _, _, cl, _)
+ | Tcl_apply (cl, _)
+ | Tcl_let (_, _, _, cl)
+ | Tcl_constraint (cl, _, _, _, _) -> unify_parents env ty cl
and unify_parents_struct env ty st =
List.iter
- (function Cf_inher (cl, _, _) -> unify_parents env ty cl
+ (function { cf_desc = Tcf_inher (_, cl, _, _, _) } -> unify_parents env ty cl
| _ -> ())
- st.cl_field
+ st.cstr_fields
let type_object env loc s =
incr class_num;
@@ -1437,7 +1533,8 @@ let approx_class sdecl =
let self' =
{ ptyp_desc = Ptyp_any; ptyp_loc = Location.none } in
let clty' =
- { pcty_desc = Pcty_signature(self', []);
+ { pcty_desc = Pcty_signature { pcsig_self = self';
+ pcsig_fields = []; pcsig_loc = Location.none };
pcty_loc = sdecl.pci_expr.pcty_loc } in
{ sdecl with pci_expr = clty' }
@@ -1601,4 +1698,4 @@ let report_error ppf = function
"instance variable"
| No_overriding (kind, name) ->
fprintf ppf "@[The %s `%s'@ has no previous definition@]" kind name
-
+
diff --git a/typing/typeclass.mli b/typing/typeclass.mli
index 9841ed401..3329a8206 100644
--- a/typing/typeclass.mli
+++ b/typing/typeclass.mli
@@ -14,39 +14,70 @@
open Asttypes
open Types
-open Typedtree
open Format
val class_declarations:
Env.t -> Parsetree.class_declaration list ->
- (Ident.t * class_declaration *
- Ident.t * cltype_declaration *
+ (Ident.t * string loc * class_declaration *
+ Ident.t * class_type_declaration *
Ident.t * type_declaration *
Ident.t * type_declaration *
- int * string list * class_expr) list * Env.t
+ int * string list * Typedtree.class_declaration) list * Env.t
+
+(*
+and class_declaration =
+ (class_expr, Types.class_declaration) class_infos
+*)
val class_descriptions:
Env.t -> Parsetree.class_description list ->
- (Ident.t * class_declaration *
- Ident.t * cltype_declaration *
+ (Ident.t * string loc * class_declaration *
+ Ident.t * class_type_declaration *
Ident.t * type_declaration *
Ident.t * type_declaration *
- int * string list * class_type) list * Env.t
+ int * string list * Typedtree.class_description) list * Env.t
+
+(*
+and class_description =
+ (class_type, unit) class_infos
+*)
val class_type_declarations:
Env.t -> Parsetree.class_description list ->
- (Ident.t * cltype_declaration *
+ (Ident.t * string loc * class_type_declaration *
+ Ident.t * type_declaration *
Ident.t * type_declaration *
- Ident.t * type_declaration) list * Env.t
+ Typedtree.class_type_declaration) list * Env.t
+
+(*
+and class_type_declaration =
+ (class_type, Types.class_type_declaration) class_infos
+*)
val approx_class_declarations:
Env.t -> Parsetree.class_description list ->
- (Ident.t * cltype_declaration *
+ (Ident.t * string loc * class_type_declaration *
+ Ident.t * type_declaration *
Ident.t * type_declaration *
- Ident.t * type_declaration) list
+ Typedtree.class_type_declaration) list
val virtual_methods: Types.class_signature -> label list
+(*
+val type_classes :
+ bool ->
+ ('a -> Types.type_expr) ->
+ (Env.t -> 'a -> 'b * Types.class_type) ->
+ Env.t ->
+ 'a Parsetree.class_infos list ->
+ ( Ident.t * Types.class_declaration *
+ Ident.t * Types.class_type_declaration *
+ Ident.t * Types.type_declaration *
+ Ident.t * Types.type_declaration *
+ int * string list * 'b * 'b Typedtree.class_infos)
+ list * Env.t
+*)
+
type error =
Unconsistent_constraint of (type_expr * type_expr) list
| Field_type_mismatch of string * string * (type_expr * type_expr) list
diff --git a/typing/typecore.ml b/typing/typecore.ml
index 9f9cd389a..6724420e5 100644
--- a/typing/typecore.ml
+++ b/typing/typecore.ml
@@ -33,7 +33,7 @@ type error =
| Apply_non_function of type_expr
| Apply_wrong_label of label * type_expr
| Label_multiply_defined of Longident.t
- | Label_missing of string list
+ | Label_missing of Ident.t list
| Label_not_mutable of Longident.t
| Incomplete_format of string
| Bad_conversion of string * int * char
@@ -84,7 +84,7 @@ let type_package =
let type_object =
ref (fun env s -> assert false :
Env.t -> Location.t -> Parsetree.class_structure ->
- class_structure * class_signature * string list)
+ Typedtree.class_structure * Types.class_signature * string list)
(*
Saving and outputting type information.
@@ -93,14 +93,20 @@ let type_object =
or [Typedtree.pattern] that will end up in the typed AST.
*)
let re node =
+ Cmt_format.add_saved_type (Cmt_format.Partial_expression node);
Stypes.record (Stypes.Ti_expr node);
node
;;
let rp node =
+ Cmt_format.add_saved_type (Cmt_format.Partial_pattern node);
Stypes.record (Stypes.Ti_pat node);
node
;;
+
+let snd3 (_,x,_) = x
+let thd4 (_,_, x,_) = x
+
(* Upper approximation of free identifiers on the parse tree *)
let iter_expression f e =
@@ -141,7 +147,7 @@ let iter_expression f e =
| Pexp_for (_, e1, e2, _, e3) -> expr e1; expr e2; expr e3
| Pexp_override sel -> List.iter (fun (_, e) -> expr e) sel
| Pexp_letmodule (_, me, e) -> expr e; module_expr me
- | Pexp_object (_, cs) -> List.iter class_field cs
+ | Pexp_object { pcstr_fields = fs } -> List.iter class_field fs
| Pexp_pack me -> module_expr me
and module_expr me =
@@ -172,7 +178,7 @@ let iter_expression f e =
and class_expr ce =
match ce.pcl_desc with
| Pcl_constr _ -> ()
- | Pcl_structure (_, cfl) -> List.iter class_field cfl
+ | Pcl_structure { pcstr_fields = fs } -> List.iter class_field fs
| Pcl_fun (_, eo, _, ce) -> may expr eo; class_expr ce
| Pcl_apply (ce, lel) ->
class_expr ce; List.iter (fun (_, e) -> expr e) lel
@@ -180,10 +186,11 @@ let iter_expression f e =
List.iter (fun (_, e) -> expr e) pel; class_expr ce
| Pcl_constraint (ce, _) -> class_expr ce
- and class_field = function
+ and class_field cf =
+ match cf.pcf_desc with
| Pcf_inher (_, ce, _) -> class_expr ce
- | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> ()
- | Pcf_val (_,_,_, e, _) | Pcf_meth (_,_,_, e, _) -> expr e
+ | Pcf_valvirt _ | Pcf_virt _ | Pcf_constr _ -> ()
+ | Pcf_val (_,_,_,e) | Pcf_meth (_,_,_,e) -> expr e
| Pcf_init e -> expr e
in
@@ -193,7 +200,7 @@ let iter_expression f e =
let all_idents el =
let idents = Hashtbl.create 8 in
let f = function
- | {pexp_desc=Pexp_ident (Longident.Lident id); _} ->
+ | {pexp_desc=Pexp_ident { txt = Longident.Lident id; _ }; _} ->
Hashtbl.replace idents id ()
| _ -> ()
in
@@ -217,15 +224,19 @@ let type_constant = function
let type_option ty =
newty (Tconstr(Predef.path_option,[ty], ref Mnil))
+let mkexp desc typ loc env =
+ { exp_desc = desc; exp_type = typ; exp_loc = loc; exp_env = env; exp_extra = [] }
+
let option_none ty loc =
- let cnone = Env.lookup_constructor (Longident.Lident "None") Env.initial in
- { exp_desc = Texp_construct(cnone, []);
- exp_type = ty; exp_loc = loc; exp_env = Env.initial }
+ let lid = Longident.Lident "None" in
+ let (path, cnone) = Env.lookup_constructor lid Env.initial in
+ mkexp ( Texp_construct( path, mknoloc lid, cnone, [], false) ) ty loc Env.initial
let option_some texp =
- let csome = Env.lookup_constructor (Longident.Lident "Some") Env.initial in
- { exp_desc = Texp_construct(csome, [texp]); exp_loc = texp.exp_loc;
- exp_type = type_option texp.exp_type; exp_env = texp.exp_env }
+ let lid = Longident.Lident "Some" in
+ let (path, csome) = Env.lookup_constructor lid Env.initial in
+ mkexp ( Texp_construct(path, mknoloc lid , csome, [texp],false) )
+ (type_option texp.exp_type) texp.exp_loc texp.exp_env
let extract_option_type env ty =
match expand_head env ty with {desc = Tconstr(path, [ty], _)}
@@ -296,6 +307,7 @@ let unify_pat_types_gadt loc env ty ty' =
(* Creating new conjunctive types is not allowed when typing patterns *)
+
let unify_pat env pat expected_ty =
unify_pat_types pat.pat_loc env pat.pat_type expected_ty
@@ -341,11 +353,11 @@ let has_variants p =
(* pattern environment *)
-let pattern_variables = ref ([]: (Ident.t * type_expr * Location.t * bool (* as-variable *)) list)
+let pattern_variables = ref ([]: (Ident.t * type_expr * string loc * Location.t * bool (* as-variable *)) list)
let pattern_force = ref ([] : (unit -> unit) list)
let pattern_scope = ref (None : Annot.ident option);;
let allow_modules = ref false
-let module_variables = ref ([] : (string * Location.t) list)
+let module_variables = ref ([] : (string loc * Location.t) list)
let reset_pattern scope allow =
pattern_variables := [];
pattern_force := [];
@@ -355,10 +367,10 @@ let reset_pattern scope allow =
;;
let enter_variable ?(is_module=false) ?(is_as_variable=false) loc name ty =
- if List.exists (fun (id, _, _, _) -> Ident.name id = name) !pattern_variables
- then raise(Error(loc, Multiply_bound_variable name));
- let id = Ident.create name in
- pattern_variables := (id, ty, loc, is_as_variable) :: !pattern_variables;
+ if List.exists (fun (id, _, _, _, _) -> Ident.name id = name.txt) !pattern_variables
+ then raise(Error(loc, Multiply_bound_variable name.txt));
+ let id = Ident.create name.txt in
+ pattern_variables := (id, ty, name, loc, is_as_variable) :: !pattern_variables;
if is_module then begin
(* Note: unpack patterns enter a variable of the same name *)
if not !allow_modules then raise (Error (loc, Modules_not_allowed));
@@ -366,13 +378,13 @@ let enter_variable ?(is_module=false) ?(is_as_variable=false) loc name ty =
end else begin
match !pattern_scope with
| None -> ()
- | Some s -> Stypes.record (Stypes.An_ident (loc, name, s));
+ | Some s -> Stypes.record (Stypes.An_ident (name.loc, name.txt, s)); (* moved to genannot *)
end;
id
let sort_pattern_variables vs =
List.sort
- (fun (x,_,_,_) (y,_,_,_) -> Pervasives.compare (Ident.name x) (Ident.name y))
+ (fun (x,_,_,_,_) (y,_,_,_,_) -> Pervasives.compare (Ident.name x) (Ident.name y))
vs
let enter_orpat_variables loc env p1_vs p2_vs =
@@ -382,7 +394,7 @@ let enter_orpat_variables loc env p1_vs p2_vs =
and p2_vs = sort_pattern_variables p2_vs in
let rec unify_vars p1_vs p2_vs = match p1_vs, p2_vs with
- | (x1,t1,l1,a1)::rem1, (x2,t2,l2,a2)::rem2 when Ident.equal x1 x2 ->
+ | (x1,t1,_,l1,a1)::rem1, (x2,t2,_,l2,a2)::rem2 when Ident.equal x1 x2 ->
if x1==x2 then
unify_vars rem1 rem2
else begin
@@ -395,9 +407,9 @@ let enter_orpat_variables loc env p1_vs p2_vs =
(x2,x1)::unify_vars rem1 rem2
end
| [],[] -> []
- | (x,_,_,_)::_, [] -> raise (Error (loc, Orpat_vars x))
- | [],(x,_,_,_)::_ -> raise (Error (loc, Orpat_vars x))
- | (x,_,_,_)::_, (y,_,_,_)::_ ->
+ | (x,_,_,_,_)::_, [] -> raise (Error (loc, Orpat_vars x))
+ | [],(x,_,_,_,_)::_ -> raise (Error (loc, Orpat_vars x))
+ | (x,_,_,_,_)::_, (y,_,_,_,_)::_ ->
let min_var =
if Ident.name x < Ident.name y then x
else y in
@@ -406,11 +418,11 @@ let enter_orpat_variables loc env p1_vs p2_vs =
let rec build_as_type env p =
match p.pat_desc with
- Tpat_alias(p1, _) -> build_as_type env p1
+ Tpat_alias(p1,_, _) -> build_as_type env p1
| Tpat_tuple pl ->
let tyl = List.map (build_as_type env) pl in
newty (Ttuple tyl)
- | Tpat_construct(cstr, pl) ->
+ | Tpat_construct(_, _, cstr, pl,_) ->
let keep = cstr.cstr_private = Private || cstr.cstr_existentials <> [] in
if keep then p.pat_type else
let tyl = List.map (build_as_type env) pl in
@@ -423,11 +435,11 @@ let rec build_as_type env p =
newty (Tvariant{row_fields=[l, Rpresent ty]; row_more=newvar();
row_bound=(); row_name=None;
row_fixed=false; row_closed=false})
- | Tpat_record lpl ->
- let lbl = fst(List.hd lpl) in
+ | Tpat_record (lpl,_) ->
+ let lbl = thd4 (List.hd lpl) in
if lbl.lbl_private = Private then p.pat_type else
let ty = newvar () in
- let ppl = List.map (fun (l,p) -> l.lbl_pos, p) lpl in
+ let ppl = List.map (fun (_, _, l, p) -> l.lbl_pos, p) lpl in
let do_label lbl =
let _, ty_arg, ty_res = instance_label false lbl in
unify_pat env {p with pat_type = ty} ty_res;
@@ -476,7 +488,7 @@ let build_or_pat env loc lid =
(l, Reither(true,[], true, ref None)) :: fields
| Rpresent (Some ty) ->
(l, Some {pat_desc=Tpat_any; pat_loc=Location.none; pat_env=env;
- pat_type=ty})
+ pat_type=ty; pat_extra=[];})
:: pats,
(l, Reither(false, [ty], true, ref None)) :: fields
| _ -> pats, fields)
@@ -490,7 +502,7 @@ let build_or_pat env loc lid =
let row' = ref {row with row_more=newvar()} in
let pats =
List.map (fun (l,p) -> {pat_desc=Tpat_variant(l,p,row'); pat_loc=gloc;
- pat_env=env; pat_type=ty})
+ pat_env=env; pat_type=ty; pat_extra=[];})
pats
in
match pats with
@@ -498,38 +510,41 @@ let build_or_pat env loc lid =
| pat :: pats ->
let r =
List.fold_left
- (fun pat pat0 -> {pat_desc=Tpat_or(pat0,pat,Some row0);
+ (fun pat pat0 -> {pat_desc=Tpat_or(pat0,pat,Some row0); pat_extra=[];
pat_loc=gloc; pat_env=env; pat_type=ty})
pat pats in
- (rp { r with pat_loc = loc },ty)
+ (path, rp { r with pat_loc = loc },ty)
(* Records *)
let rec find_record_qual = function
| [] -> None
- | (Longident.Ldot (modname, _), _) :: _ -> Some modname
+ | ({ txt = Longident.Ldot (modname, _) }, _) :: _ -> Some modname
| _ :: rest -> find_record_qual rest
-let type_label_a_list ?labels env loc type_lbl_a lid_a_list =
+let type_label_a_list ?(labels : ((string,Path.t * Types.label_description) Hashtbl.t) option) env loc type_lbl_a lid_a_list =
let record_qual = find_record_qual lid_a_list in
let lbl_a_list =
List.map
(fun (lid, a) ->
- match lid, labels, record_qual with
- Longident.Lident s, Some labels, _ when Hashtbl.mem labels s ->
- Hashtbl.find labels s, a
- | Longident.Lident s, _, Some modname ->
- Typetexp.find_label env loc (Longident.Ldot (modname, s)), a
- | _ ->
- Typetexp.find_label env loc lid, a)
- lid_a_list in
+ let path, label =
+ match lid.txt, labels, record_qual with
+ Longident.Lident s, Some labels, _ when Hashtbl.mem labels s ->
+ Hashtbl.find labels s
+ | Longident.Lident s, _, Some modname ->
+ Typetexp.find_label env loc (Longident.Ldot (modname, s))
+ | _ ->
+ Typetexp.find_label env loc lid.txt
+ in (path, lid, label, a)
+ ) lid_a_list in
(* Invariant: records are sorted in the typed tree *)
let lbl_a_list =
List.sort
- (fun (lbl1,_) (lbl2,_) -> compare lbl1.lbl_pos lbl2.lbl_pos)
+ (fun ( _, _, lbl1,_) ( _,_, lbl2,_) -> compare lbl1.lbl_pos lbl2.lbl_pos)
lbl_a_list
in
List.map type_lbl_a lbl_a_list
+;;
let lid_of_label label =
match repr label.lbl_res with
@@ -543,10 +558,10 @@ let lid_of_label label =
let check_recordpat_labels loc lbl_pat_list closed =
match lbl_pat_list with
| [] -> () (* should not happen *)
- | (label1, _) :: _ ->
+ | (_, _, label1, _) :: _ ->
let all = label1.lbl_all in
let defined = Array.make (Array.length all) false in
- let check_defined (label, _) =
+ let check_defined (_, _, label, _) =
if defined.(label.lbl_pos)
then raise(Error(loc, Label_multiply_defined
(Longident.Lident label.lbl_name)))
@@ -594,28 +609,30 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
Ppat_any ->
rp {
pat_desc = Tpat_any;
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_var name ->
let id = enter_variable loc name expected_ty in
rp {
- pat_desc = Tpat_var id;
- pat_loc = loc;
+ pat_desc = Tpat_var (id, name);
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_unpack name ->
let id = enter_variable loc name expected_ty ~is_module:true in
rp {
- pat_desc = Tpat_var id;
- pat_loc = loc;
+ pat_desc = Tpat_var (id, name);
+ pat_loc = sp.ppat_loc;
+ pat_extra=[Tpat_unpack, loc];
pat_type = expected_ty;
pat_env = !env }
- | Ppat_constraint({ppat_desc=Ppat_var name; ppat_loc=loc},
+ | Ppat_constraint({ppat_desc=Ppat_var name; ppat_loc=lloc},
({ptyp_desc=Ptyp_poly _} as sty)) ->
(* explicitly polymorphic type *)
- let ty, force = Typetexp.transl_simple_type_delayed !env sty in
- unify_pat_types loc !env ty expected_ty;
+ let cty, force = Typetexp.transl_simple_type_delayed !env sty in
+ let ty = cty.ctyp_type in
+ unify_pat_types lloc !env ty expected_ty;
pattern_force := force :: !pattern_force;
begin match ty.desc with
| Tpoly (body, tyl) ->
@@ -623,11 +640,14 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
let _, ty' = instance_poly ~keep_names:true false tyl body in
end_def ();
generalize ty';
- let id = enter_variable loc name ty' in
- rp { pat_desc = Tpat_var id;
- pat_loc = loc;
- pat_type = ty;
- pat_env = !env }
+ let id = enter_variable lloc name ty' in
+ rp {
+ pat_desc = Tpat_var (id, name);
+ pat_loc = lloc;
+ pat_extra = [Tpat_constraint cty, loc];
+ pat_type = ty;
+ pat_env = !env
+ }
| _ -> assert false
end
| Ppat_alias(sq, name) ->
@@ -638,15 +658,15 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
generalize ty_var;
let id = enter_variable ~is_as_variable:true loc name ty_var in
rp {
- pat_desc = Tpat_alias(q, id);
- pat_loc = loc;
+ pat_desc = Tpat_alias(q, id, name);
+ pat_loc = loc; pat_extra=[];
pat_type = q.pat_type;
pat_env = !env }
| Ppat_constant cst ->
unify_pat_types loc !env (type_constant cst) expected_ty;
rp {
pat_desc = Tpat_constant cst;
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_tuple spl ->
@@ -656,17 +676,17 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
let pl = List.map (fun (p,t) -> type_pat p t) spl_ann in
rp {
pat_desc = Tpat_tuple pl;
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_construct(lid, sarg, explicit_arity) ->
- let constr =
- match lid, constrs with
+ let (constr_path, constr) =
+ match lid.txt, constrs with
Longident.Lident s, Some constrs when Hashtbl.mem constrs s ->
Hashtbl.find constrs s
- | _ -> Typetexp.find_constructor !env loc lid
+ | _ -> Typetexp.find_constructor !env loc lid.txt
in
- Env.mark_constructor `Pattern !env (Longident.last lid) constr;
+ Env.mark_constructor `Pattern !env (Longident.last lid.txt) constr;
if no_existentials && constr.cstr_existentials <> [] then
raise (Error (loc, Unexpected_existential));
(* if constructor is gadt, we must verify that the expected type has the
@@ -685,7 +705,7 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
replicate_list sp constr.cstr_arity
| Some sp -> [sp] in
if List.length sargs <> constr.cstr_arity then
- raise(Error(loc, Constructor_arity_mismatch(lid,
+ raise(Error(loc, Constructor_arity_mismatch(lid.txt,
constr.cstr_arity, List.length sargs)));
let (ty_args, ty_res) =
instance_constructor ~in_pattern:(env, get_newtype_level ()) constr
@@ -696,8 +716,8 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
unify_pat_types loc !env ty_res expected_ty;
let args = List.map2 (fun p t -> type_pat p t) sargs ty_args in
rp {
- pat_desc = Tpat_construct(constr, args);
- pat_loc = loc;
+ pat_desc = Tpat_construct( constr_path, lid, constr, args,explicit_arity);
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_variant(l, sarg) ->
@@ -713,11 +733,11 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
unify_pat_types loc !env (newty (Tvariant row)) expected_ty;
rp {
pat_desc = Tpat_variant(l, arg, ref {row with row_more = newvar()});
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_record(lid_sp_list, closed) ->
- let type_label_pat (label, sarg) =
+ let type_label_pat (label_path, label_lid, label, sarg) =
begin_def ();
let (vars, ty_arg, ty_res) = instance_label false label in
if vars = [] then end_def ();
@@ -737,14 +757,14 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
if List.exists instantiated vars then
raise (Error(loc, Polymorphic_label (lid_of_label label)))
end;
- (label, arg)
+ (label_path, label_lid, label, arg)
in
let lbl_pat_list =
type_label_a_list ?labels !env loc type_label_pat lid_sp_list in
check_recordpat_labels loc lbl_pat_list closed;
rp {
- pat_desc = Tpat_record lbl_pat_list;
- pat_loc = loc;
+ pat_desc = Tpat_record (lbl_pat_list, closed);
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_array spl ->
@@ -755,7 +775,7 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
let pl = List.map (fun (p,t) -> type_pat p ty_elt) spl_ann in
rp {
pat_desc = Tpat_array pl;
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_or(sp1, sp2) ->
@@ -770,7 +790,7 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
pattern_variables := p1_variables;
rp {
pat_desc = Tpat_or(p1, alpha_pat alpha_env p2, None);
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_lazy sp1 ->
@@ -779,14 +799,15 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
let p1 = type_pat sp1 nv in
rp {
pat_desc = Tpat_lazy p1;
- pat_loc = loc;
+ pat_loc = loc; pat_extra=[];
pat_type = expected_ty;
pat_env = !env }
| Ppat_constraint(sp, sty) ->
(* Separate when not already separated by !principal *)
let separate = true in
if separate then begin_def();
- let ty, force = Typetexp.transl_simple_type_delayed !env sty in
+ let cty, force = Typetexp.transl_simple_type_delayed !env sty in
+ let ty = cty.ctyp_type in
let ty, expected_ty' =
if separate then begin
end_def();
@@ -802,15 +823,17 @@ let rec type_pat ~constrs ~labels ~no_existentials ~mode ~env sp expected_ty =
pattern_force := force :: !pattern_force;
if separate then
match p.pat_desc with
- Tpat_var id ->
+ Tpat_var (id,s) ->
{p with pat_type = ty;
- pat_desc = Tpat_alias ({p with pat_desc = Tpat_any}, id)}
- | _ -> {p with pat_type = ty}
+ pat_desc = Tpat_alias ({p with pat_desc = Tpat_any}, id,s);
+ pat_extra = [Tpat_constraint cty, loc];
+ }
+ | _ -> {p with pat_type = ty; pat_extra = (Tpat_constraint cty,loc) :: p.pat_extra}
else p
| Ppat_type lid ->
- let (r,ty) = build_or_pat !env loc lid in
+ let (path, p,ty) = build_or_pat !env loc lid.txt in
unify_pat_types loc !env ty expected_ty;
- r
+ { p with pat_extra = (Tpat_type (path, lid), loc) :: p.pat_extra }
let type_pat ?(allow_existentials=false) ?constrs ?labels
?(lev=get_current_level()) env sp expected_ty =
@@ -857,10 +880,10 @@ let rec iter3 f lst1 lst2 lst3 =
let add_pattern_variables ?check ?check_as env =
let pv = get_ref pattern_variables in
(List.fold_right
- (fun (id, ty, loc, as_var) env ->
+ (fun (id, ty, name, loc, as_var) env ->
let check = if as_var then check_as else check in
let e1 = Env.add_value ?check id
- {val_type = ty; val_kind = Val_reg; val_loc = loc} env in
+ {val_type = ty; val_kind = Val_reg; Types.val_loc = loc} env in
Env.add_annot id (Annot.Iref_internal loc) e1)
pv env,
get_ref module_variables)
@@ -894,15 +917,15 @@ let type_class_arg_pattern cl_num val_env met_env l spat =
if is_optional l then unify_pat val_env pat (type_option (newvar ()));
let (pv, met_env) =
List.fold_right
- (fun (id, ty, loc, as_var) (pv, env) ->
+ (fun (id, ty, name, loc, as_var) (pv, env) ->
let check s =
if as_var then Warnings.Unused_var s
else Warnings.Unused_var_strict s in
let id' = Ident.create (Ident.name id) in
- ((id', id, ty)::pv,
+ ((id', name, id, ty)::pv,
Env.add_value id' {val_type = ty;
val_kind = Val_ivar (Immutable, cl_num);
- val_loc = loc;
+ Types.val_loc = loc;
} ~check
env))
!pattern_variables ([], met_env)
@@ -914,8 +937,8 @@ let mkpat d = { ppat_desc = d; ppat_loc = Location.none }
let type_self_pattern cl_num privty val_env met_env par_env spat =
let spat =
- mkpat (Ppat_alias (mkpat(Ppat_alias (spat, "selfpat-*")),
- "selfpat-" ^ cl_num))
+ mkpat (Ppat_alias (mkpat(Ppat_alias (spat, mknoloc "selfpat-*")),
+ mknoloc ("selfpat-" ^ cl_num)))
in
reset_pattern None false;
let nv = newvar() in
@@ -927,20 +950,20 @@ let type_self_pattern cl_num privty val_env met_env par_env spat =
pattern_variables := [];
let (val_env, met_env, par_env) =
List.fold_right
- (fun (id, ty, loc, as_var) (val_env, met_env, par_env) ->
+ (fun (id, ty, name, loc, as_var) (val_env, met_env, par_env) ->
(Env.add_value id {val_type = ty;
val_kind = Val_unbound;
- val_loc = loc;
+ Types.val_loc = loc;
} val_env,
Env.add_value id {val_type = ty;
val_kind = Val_self (meths, vars, cl_num, privty);
- val_loc = loc;
+ Types.val_loc = loc;
}
~check:(fun s -> if as_var then Warnings.Unused_var s
else Warnings.Unused_var_strict s)
met_env,
Env.add_value id {val_type = ty; val_kind = Val_unbound;
- val_loc = loc;
+ Types.val_loc = loc;
} par_env))
pv (val_env, met_env, par_env)
in
@@ -956,46 +979,55 @@ let force_delayed_checks () =
reset_delayed_checks ();
Btype.backtrack snap
+let fst3 (x, _, _) = x
+let snd3 (_, x, _) = x
(* Generalization criterion for expressions *)
let rec is_nonexpansive exp =
match exp.exp_desc with
- Texp_ident(_,_) -> true
+ Texp_ident(_,_,_) -> true
| Texp_constant _ -> true
+ | Texp_poly (e, _)
+ | Texp_newtype (_, e)
+ -> is_nonexpansive e
| Texp_let(rec_flag, pat_exp_list, body) ->
List.for_all (fun (pat, exp) -> is_nonexpansive exp) pat_exp_list &&
is_nonexpansive body
| Texp_function _ -> true
- | Texp_apply(e, (None,_)::el) ->
- is_nonexpansive e && List.for_all is_nonexpansive_opt (List.map fst el)
+ | Texp_apply(e, (_,None,_)::el) ->
+ is_nonexpansive e && List.for_all is_nonexpansive_opt (List.map snd3 el)
| Texp_tuple el ->
List.for_all is_nonexpansive el
- | Texp_construct(_, el) ->
+ | Texp_construct(_, _, _, el,_) ->
List.for_all is_nonexpansive el
| Texp_variant(_, arg) -> is_nonexpansive_opt arg
| Texp_record(lbl_exp_list, opt_init_exp) ->
List.for_all
- (fun (lbl, exp) -> lbl.lbl_mut = Immutable && is_nonexpansive exp)
+ (fun (_, _, lbl, exp) -> lbl.lbl_mut = Immutable && is_nonexpansive exp)
lbl_exp_list
&& is_nonexpansive_opt opt_init_exp
- | Texp_field(exp, lbl) -> is_nonexpansive exp
+ | Texp_field(exp, _, lbl, _) -> is_nonexpansive exp
| Texp_array [] -> true
| Texp_ifthenelse(cond, ifso, ifnot) ->
is_nonexpansive ifso && is_nonexpansive_opt ifnot
| Texp_sequence (e1, e2) -> is_nonexpansive e2 (* PR#4354 *)
- | Texp_new (_, cl_decl) when Ctype.class_type_arity cl_decl.cty_type > 0 ->
+ | Texp_new (_, _, cl_decl) when Ctype.class_type_arity cl_decl.cty_type > 0 ->
true
(* Note: nonexpansive only means no _observable_ side effects *)
| Texp_lazy e -> is_nonexpansive e
- | Texp_object ({cl_field=fields}, {cty_vars=vars}, _) ->
+ | Texp_object ({cstr_fields=fields; cstr_type = { cty_vars=vars}}, _) ->
let count = ref 0 in
List.for_all
- (function
- Cf_meth _ -> true
- | Cf_val (_,_,e,_) -> incr count; is_nonexpansive_opt e
- | Cf_init e -> is_nonexpansive e
- | Cf_inher _ -> false)
+ (fun field -> match field.cf_desc with
+ Tcf_meth _ -> true
+ | Tcf_val (_,_, _, _, Tcfk_concrete e,_) ->
+ incr count; is_nonexpansive e
+ | Tcf_val (_,_, _, _, Tcfk_virtual _,_) ->
+ incr count; true
+ | Tcf_init e -> is_nonexpansive e
+ | Tcf_constr _ -> true
+ | Tcf_inher _ -> false)
fields &&
Vars.fold (fun _ (mut,_,_) b -> decr count; b && mut = Immutable)
vars true &&
@@ -1009,21 +1041,21 @@ and is_nonexpansive_mod mexp =
| Tmod_ident _ -> true
| Tmod_functor _ -> true
| Tmod_unpack (e, _) -> is_nonexpansive e
- | Tmod_constraint (m, _, _) -> is_nonexpansive_mod m
- | Tmod_structure items ->
+ | Tmod_constraint (m, _, _, _) -> is_nonexpansive_mod m
+ | Tmod_structure str ->
List.for_all
- (function
+ (fun item -> match item.str_desc with
| Tstr_eval _ | Tstr_primitive _ | Tstr_type _ | Tstr_modtype _
- | Tstr_open _ | Tstr_cltype _ | Tstr_exn_rebind _ -> true
+ | Tstr_open _ | Tstr_class_type _ | Tstr_exn_rebind _ -> true
| Tstr_value (_, pat_exp_list) ->
List.for_all (fun (_, exp) -> is_nonexpansive exp) pat_exp_list
- | Tstr_module (_, m) | Tstr_include (m, _) -> is_nonexpansive_mod m
+ | Tstr_module (_, _, m) | Tstr_include (m, _) -> is_nonexpansive_mod m
| Tstr_recmodule id_mod_list ->
- List.for_all (fun (_, m) -> is_nonexpansive_mod m) id_mod_list
+ List.for_all (fun (_, _, _, m) -> is_nonexpansive_mod m) id_mod_list
| Tstr_exception _ -> false (* true would be unsound *)
| Tstr_class _ -> false (* could be more precise *)
)
- items
+ str.str_items
| Tmod_apply _ -> false
and is_nonexpansive_opt = function
@@ -1246,7 +1278,7 @@ let rec approx_type env sty =
newty (Ttuple (List.map (approx_type env) args))
| Ptyp_constr (lid, ctl) ->
begin try
- let (path, decl) = Env.lookup_type lid env in
+ let (path, decl) = Env.lookup_type lid.txt env in
if List.length ctl <> decl.type_arity then raise Not_found;
let tyl = List.map (approx_type env) ctl in
newconstr path tyl
@@ -1347,26 +1379,29 @@ let self_coercion = ref ([] : (Path.t * Location.t list ref) list)
(* Helpers for packaged modules. *)
let create_package_type loc env (p, l) =
let s = !Typetexp.transl_modtype_longident loc env p in
- newty (Tpackage (s,
- List.map fst l,
- List.map (Typetexp.transl_simple_type env false)
- (List.map snd l)))
-
-let wrap_unpacks sexp unpacks =
- List.fold_left
- (fun sexp (name, loc) ->
- {pexp_loc = sexp.pexp_loc; pexp_desc = Pexp_letmodule (
- name,
- {pmod_loc = loc; pmod_desc = Pmod_unpack
- {pexp_desc=Pexp_ident(Longident.Lident name); pexp_loc=loc}},
+ let fields = List.map (fun (name, ct) ->
+ name, Typetexp.transl_simple_type env false ct) l in
+ let ty = newty (Tpackage (s,
+ List.map fst l,
+ List.map (fun (_, cty) -> cty.ctyp_type) fields))
+ in
+ (s, fields, ty)
+
+ let wrap_unpacks sexp unpacks =
+ List.fold_left
+ (fun sexp (name, loc) ->
+ {pexp_loc = sexp.pexp_loc; pexp_desc = Pexp_letmodule (
+ name,
+ {pmod_loc = loc; pmod_desc = Pmod_unpack
+ {pexp_desc=Pexp_ident(mkloc (Longident.Lident name.txt) name.loc); pexp_loc=name.loc}},
sexp)})
sexp unpacks
(* Helpers for type_cases *)
-let iter_ppat f p =
+let iter_ppat f p =
match p.ppat_desc with
- | Ppat_any | Ppat_var _ | Ppat_constant _
- | Ppat_type _ | Ppat_unpack _ -> ()
+ | Ppat_any | Ppat_var _ | Ppat_constant _
+ | Ppat_type _ | Ppat_unpack _ -> ()
| Ppat_array pats -> List.iter f pats
| Ppat_or (p1,p2) -> f p1; f p2
| Ppat_variant (_, arg) | Ppat_construct (_, arg, _) -> may f arg
@@ -1387,7 +1422,8 @@ let contains_gadt env p =
match p.ppat_desc with
Ppat_construct (lid, _, _) ->
begin try
- if (Env.lookup_constructor lid env).cstr_generalized then raise Exit
+ let (_path, cstr) = Env.lookup_constructor lid.txt env in
+ if cstr.cstr_generalized then raise Exit
with Not_found -> ()
end; iter_ppat loop p
| _ -> iter_ppat loop p
@@ -1438,6 +1474,7 @@ and type_expect ?in_function env sexp ty_expected =
let loc = sexp.pexp_loc in
(* Record the expression type before unifying it with the expected type *)
let rue exp =
+ Cmt_format.add_saved_type (Cmt_format.Partial_expression exp);
Stypes.record (Stypes.Ti_expr exp);
unify_exp env exp (instance env ty_expected);
exp
@@ -1446,13 +1483,13 @@ and type_expect ?in_function env sexp ty_expected =
| Pexp_ident lid ->
begin
if !Clflags.annotations then begin
- try let (path, annot) = Env.lookup_annot lid env in
+ try let (path, annot) = Env.lookup_annot lid.txt env in
Stypes.record
(Stypes.An_ident (
loc, Path.name ~paren:Oprint.parenthesized_ident path, annot))
with _ -> ()
end;
- let (path, desc) = Typetexp.find_value env loc lid in
+ let (path, desc) = Typetexp.find_value env loc lid.txt in
rue {
exp_desc =
begin match desc.val_kind with
@@ -1460,25 +1497,28 @@ and type_expect ?in_function env sexp ty_expected =
let (self_path, _) =
Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env
in
- Texp_instvar(self_path, path)
+ Texp_instvar(self_path, path,
+ match lid.txt with
+ Longident.Lident txt -> { txt; loc = lid.loc }
+ | _ -> assert false)
| Val_self (_, _, cl_num, _) ->
let (path, _) =
Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env
in
- Texp_ident(path, desc)
+ Texp_ident(path, lid, desc)
| Val_unbound ->
- raise(Error(loc, Masked_instance_variable lid))
+ raise(Error(loc, Masked_instance_variable lid.txt))
| _ ->
- Texp_ident(path, desc)
- end;
- exp_loc = loc;
+ Texp_ident(path, lid, desc)
+ end;
+ exp_loc = loc; exp_extra = [];
exp_type = instance env desc.val_type;
exp_env = env }
end
| Pexp_constant(Const_string s as cst) ->
rue {
exp_desc = Texp_constant cst;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type =
(* Terrible hack for format strings *)
begin match (repr (expand_head env ty_expected)).desc with
@@ -1490,7 +1530,7 @@ and type_expect ?in_function env sexp ty_expected =
| Pexp_constant cst ->
rue {
exp_desc = Texp_constant cst;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = type_constant cst;
exp_env = env }
| Pexp_let(Nonrecursive, [spat, sval], sbody) when contains_gadt env spat ->
@@ -1510,7 +1550,7 @@ and type_expect ?in_function env sexp ty_expected =
type_expect new_env (wrap_unpacks sbody unpacks) ty_expected in
re {
exp_desc = Texp_let(rec_flag, pat_exp_list, body);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = body.exp_type;
exp_env = env }
| Pexp_function (l, Some default, [spat, sbody]) ->
@@ -1519,14 +1559,15 @@ and type_expect ?in_function env sexp ty_expected =
{ppat_loc = default_loc;
ppat_desc =
Ppat_construct
- (Longident.(Ldot (Lident "*predef*", "Some")),
- Some {ppat_loc = default_loc; ppat_desc = Ppat_var "*sth*"},
+ (mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))),
+ Some {ppat_loc = default_loc; ppat_desc = Ppat_var (mknoloc "*sth*")},
false)},
{pexp_loc = default_loc;
- pexp_desc = Pexp_ident(Longident.Lident "*sth*")};
+ pexp_desc = Pexp_ident(mknoloc (Longident.Lident "*sth*"))};
{ppat_loc = default_loc;
ppat_desc = Ppat_construct
- (Longident.(Ldot (Lident "*predef*", "None")), None, false)},
+ (mknoloc (Longident.(Ldot (Lident "*predef*", "None"))),
+ None, false)},
default;
] in
let smatch = {
@@ -1534,7 +1575,7 @@ and type_expect ?in_function env sexp ty_expected =
pexp_desc =
Pexp_match ({
pexp_loc = loc;
- pexp_desc = Pexp_ident(Longident.Lident "*opt*")
+ pexp_desc = Pexp_ident(mknoloc (Longident.Lident "*opt*"))
},
scases
)
@@ -1545,7 +1586,7 @@ and type_expect ?in_function env sexp ty_expected =
Pexp_function (
l, None,
[ {ppat_loc = loc;
- ppat_desc = Ppat_var "*opt*"},
+ ppat_desc = Ppat_var (mknoloc "*opt*")},
{pexp_loc = loc;
pexp_desc = Pexp_let(Default, [spat, smatch], sbody);
}
@@ -1596,8 +1637,8 @@ and type_expect ?in_function env sexp ty_expected =
Location.prerr_warning (fst (List.hd cases)).pat_loc
Warnings.Unerasable_optional_argument;
re {
- exp_desc = Texp_function(cases, partial);
- exp_loc = loc;
+ exp_desc = Texp_function(l,cases, partial);
+ exp_loc = loc; exp_extra = [];
exp_type = instance env (newgenty (Tarrow(l, ty_arg, ty_res, Cok)));
exp_env = env }
| Pexp_apply(sfunct, sargs) ->
@@ -1605,9 +1646,9 @@ and type_expect ?in_function env sexp ty_expected =
if !Clflags.principal then begin_def ();
let funct = type_exp env sfunct in
if !Clflags.principal then begin
- end_def ();
- generalize_structure funct.exp_type
- end;
+ end_def ();
+ generalize_structure funct.exp_type
+ end;
let rec lower_args seen ty_fun =
let ty = expand_head env ty_fun in
if List.memq ty seen then () else
@@ -1626,7 +1667,7 @@ and type_expect ?in_function env sexp ty_expected =
unify_var env (newvar()) funct.exp_type;
rue {
exp_desc = Texp_apply(funct, args);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = ty_res;
exp_env = env }
| Pexp_match(sarg, caselist) ->
@@ -1640,7 +1681,7 @@ and type_expect ?in_function env sexp ty_expected =
in
re {
exp_desc = Texp_match(arg, cases, partial);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance env ty_expected;
exp_env = env }
| Pexp_try(sbody, caselist) ->
@@ -1649,7 +1690,7 @@ and type_expect ?in_function env sexp ty_expected =
type_cases env Predef.type_exn ty_expected false loc caselist in
re {
exp_desc = Texp_try(body, cases);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = body.exp_type;
exp_env = env }
| Pexp_tuple sexpl ->
@@ -1661,7 +1702,7 @@ and type_expect ?in_function env sexp ty_expected =
in
re {
exp_desc = Texp_tuple expl;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
(* Keep sharing *)
exp_type = newty (Ttuple (List.map (fun e -> e.exp_type) expl));
exp_env = env }
@@ -1679,7 +1720,7 @@ and type_expect ?in_function env sexp ty_expected =
Rpresent (Some ty), Rpresent (Some ty0) ->
let arg = type_argument env sarg ty ty0 in
re { exp_desc = Texp_variant(l, Some arg);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = ty_expected0;
exp_env = env }
| _ -> raise Not_found
@@ -1690,7 +1731,7 @@ and type_expect ?in_function env sexp ty_expected =
let arg_type = may_map (fun arg -> arg.exp_type) arg in
rue {
exp_desc = Texp_variant(l, arg);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type= newty (Tvariant{row_fields = [l, Rpresent arg_type];
row_more = newvar ();
row_bound = ();
@@ -1705,20 +1746,20 @@ and type_expect ?in_function env sexp ty_expected =
lid_sexp_list in
let rec check_duplicates seen_pos lid_sexp lbl_exp =
match (lid_sexp, lbl_exp) with
- ((lid, _) :: rem1, (lbl, _) :: rem2) ->
+ ((lid, _) :: rem1, (_, _, lbl, _) :: rem2) ->
if List.mem lbl.lbl_pos seen_pos
- then raise(Error(loc, Label_multiply_defined lid))
+ then raise(Error(loc, Label_multiply_defined lid.txt))
else check_duplicates (lbl.lbl_pos :: seen_pos) rem1 rem2
| (_, _) -> () in
check_duplicates [] lid_sexp_list lbl_exp_list;
let opt_exp =
match opt_sexp, lbl_exp_list with
None, _ -> None
- | Some sexp, (lbl, _) :: _ ->
+ | Some sexp, (_, _, lbl, _) :: _ ->
if !Clflags.principal then begin_def ();
let ty_exp = newvar () in
let unify_kept lbl =
- if List.for_all (fun (lbl',_) -> lbl'.lbl_pos <> lbl.lbl_pos)
+ if List.for_all (fun (_, _, lbl',_) -> lbl'.lbl_pos <> lbl.lbl_pos)
lbl_exp_list
then begin
let _, ty_arg1, ty_res1 = instance_label false lbl
@@ -1737,10 +1778,10 @@ and type_expect ?in_function env sexp ty_expected =
in
let num_fields =
match lbl_exp_list with [] -> assert false
- | (lbl,_)::_ -> Array.length lbl.lbl_all in
+ | (_,_, lbl,_)::_ -> Array.length lbl.lbl_all in
if opt_sexp = None && List.length lid_sexp_list <> num_fields then begin
let present_indices =
- List.map (fun (lbl, _) -> lbl.lbl_pos) lbl_exp_list in
+ List.map (fun (_,_, lbl, _) -> lbl.lbl_pos) lbl_exp_list in
let label_names = extract_label_names sexp env ty_expected in
let rec missing_labels n = function
[] -> []
@@ -1755,29 +1796,29 @@ and type_expect ?in_function env sexp ty_expected =
Location.prerr_warning loc Warnings.Useless_record_with;
re {
exp_desc = Texp_record(lbl_exp_list, opt_exp);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance env ty_expected;
exp_env = env }
| Pexp_field(sarg, lid) ->
let arg = type_exp env sarg in
- let label = Typetexp.find_label env loc lid in
+ let (label_path,label) = Typetexp.find_label env loc lid.txt in
let (_, ty_arg, ty_res) = instance_label false label in
unify_exp env arg ty_res;
rue {
- exp_desc = Texp_field(arg, label);
- exp_loc = loc;
+ exp_desc = Texp_field(arg, label_path, lid, label);
+ exp_loc = loc; exp_extra = [];
exp_type = ty_arg;
exp_env = env }
| Pexp_setfield(srecord, lid, snewval) ->
let record = type_exp env srecord in
- let label = Typetexp.find_label env loc lid in
- let (label, newval) =
- type_label_exp false env loc record.exp_type (label, snewval) in
+ let (label_path, label) = Typetexp.find_label env loc lid.txt in
+ let (label_path, label_loc, label, newval) =
+ type_label_exp false env loc record.exp_type (label_path, lid, label, snewval) in
if label.lbl_mut = Immutable then
- raise(Error(loc, Label_not_mutable lid));
+ raise(Error(loc, Label_not_mutable lid.txt));
rue {
- exp_desc = Texp_setfield(record, label, newval);
- exp_loc = loc;
+ exp_desc = Texp_setfield(record, label_path, label_loc, label, newval);
+ exp_loc = loc; exp_extra = [];
exp_type = instance_def Predef.type_unit;
exp_env = env }
| Pexp_array(sargl) ->
@@ -1787,7 +1828,7 @@ and type_expect ?in_function env sexp ty_expected =
let argl = List.map (fun sarg -> type_expect env sarg ty) sargl in
re {
exp_desc = Texp_array argl;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance env ty_expected;
exp_env = env }
| Pexp_ifthenelse(scond, sifso, sifnot) ->
@@ -1797,7 +1838,7 @@ and type_expect ?in_function env sexp ty_expected =
let ifso = type_expect env sifso Predef.type_unit in
rue {
exp_desc = Texp_ifthenelse(cond, ifso, None);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = ifso.exp_type;
exp_env = env }
| Some sifnot ->
@@ -1807,7 +1848,7 @@ and type_expect ?in_function env sexp ty_expected =
unify_exp env ifnot ifso.exp_type;
re {
exp_desc = Texp_ifthenelse(cond, ifso, Some ifnot);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = ifso.exp_type;
exp_env = env }
end
@@ -1816,7 +1857,7 @@ and type_expect ?in_function env sexp ty_expected =
let exp2 = type_expect env sexp2 ty_expected in
re {
exp_desc = Texp_sequence(exp1, exp2);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = exp2.exp_type;
exp_env = env }
| Pexp_while(scond, sbody) ->
@@ -1824,46 +1865,47 @@ and type_expect ?in_function env sexp ty_expected =
let body = type_statement env sbody in
rue {
exp_desc = Texp_while(cond, body);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance_def Predef.type_unit;
exp_env = env }
| Pexp_for(param, slow, shigh, dir, sbody) ->
let low = type_expect env slow Predef.type_int in
let high = type_expect env shigh Predef.type_int in
let (id, new_env) =
- Env.enter_value param {val_type = instance_def Predef.type_int;
- val_kind = Val_reg;
- val_loc = loc;
- } env
+ Env.enter_value param.txt {val_type = instance_def Predef.type_int;
+ val_kind = Val_reg; Types.val_loc = loc; } env
~check:(fun s -> Warnings.Unused_for_index s)
in
let body = type_statement new_env sbody in
rue {
- exp_desc = Texp_for(id, low, high, dir, body);
- exp_loc = loc;
+ exp_desc = Texp_for(id, param, low, high, dir, body);
+ exp_loc = loc; exp_extra = [];
exp_type = instance_def Predef.type_unit;
exp_env = env }
| Pexp_constraint(sarg, sty, sty') ->
+
let separate = true (* always separate, 1% slowdown for lablgtk *)
(* !Clflags.principal || Env.has_local_constraints env *) in
- let (arg, ty') =
+ let (arg, ty',cty,cty') =
match (sty, sty') with
(None, None) -> (* Case actually unused *)
let arg = type_exp env sarg in
- (arg, arg.exp_type)
+ (arg, arg.exp_type,None,None)
| (Some sty, None) ->
if separate then begin_def ();
- let ty = Typetexp.transl_simple_type env false sty in
+ let cty = Typetexp.transl_simple_type env false sty in
+ let ty = cty.ctyp_type in
if separate then begin
end_def ();
generalize_structure ty;
- (type_argument env sarg ty (instance env ty), instance env ty)
+ (type_argument env sarg ty (instance env ty), instance env ty, Some cty, None)
end else
- (type_argument env sarg ty ty, ty)
+ (type_argument env sarg ty ty, ty, Some cty, None)
| (None, Some sty') ->
- let (ty', force) =
+ let (cty', force) =
Typetexp.transl_simple_type_delayed env sty'
in
+ let ty' = cty'.ctyp_type in
if separate then begin_def ();
let arg = type_exp env sarg in
let gen =
@@ -1876,7 +1918,7 @@ and type_expect ?in_function env sexp ty_expected =
end else true
in
begin match arg.exp_desc, !self_coercion, (repr ty').desc with
- Texp_ident(_, {val_kind=Val_self _}), (path,r) :: _,
+ Texp_ident(_, _, {val_kind=Val_self _}), (path,r) :: _,
Tconstr(path',_,_) when Path.same path path' ->
(* prerr_endline "self coercion"; *)
r := loc :: !r;
@@ -1909,14 +1951,16 @@ and type_expect ?in_function env sexp ty_expected =
Coercion_failure(ty', full_expand env ty', trace, b)))
end
end;
- (arg, ty')
+ (arg, ty', None, Some cty')
| (Some sty, Some sty') ->
if separate then begin_def ();
- let (ty, force) =
+ let (cty, force) =
Typetexp.transl_simple_type_delayed env sty
- and (ty', force') =
+ and (cty', force') =
Typetexp.transl_simple_type_delayed env sty'
in
+ let ty = cty.ctyp_type in
+ let ty' = cty'.ctyp_type in
begin try
let force'' = subtype env ty ty' in
force (); force' (); force'' ()
@@ -1927,38 +1971,40 @@ and type_expect ?in_function env sexp ty_expected =
end_def ();
generalize_structure ty;
generalize_structure ty';
- (type_argument env sarg ty (instance env ty), instance env ty')
+ (type_argument env sarg ty (instance env ty), instance env ty', Some cty, Some cty')
end else
- (type_argument env sarg ty ty, ty')
+ (type_argument env sarg ty ty, ty', Some cty, Some cty')
in
rue {
exp_desc = arg.exp_desc;
exp_loc = arg.exp_loc;
exp_type = ty';
- exp_env = env }
+ exp_env = env;
+ exp_extra = (Texp_constraint (cty, cty'), loc) :: arg.exp_extra;
+ }
| Pexp_when(scond, sbody) ->
let cond = type_expect env scond Predef.type_bool in
let body = type_expect env sbody ty_expected in
re {
exp_desc = Texp_when(cond, body);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = body.exp_type;
exp_env = env }
| Pexp_send (e, met) ->
if !Clflags.principal then begin_def ();
let obj = type_exp env e in
begin try
- let (exp, typ) =
+ let (meth, exp, typ) =
match obj.exp_desc with
- Texp_ident(path, {val_kind = Val_self (meths, _, _, privty)}) ->
+ Texp_ident(path, _, {val_kind = Val_self (meths, _, _, privty)}) ->
let (id, typ) =
filter_self_method env met Private meths privty
in
if is_Tvar (repr typ) then
Location.prerr_warning loc
(Warnings.Undeclared_virtual_method met);
- (Texp_send(obj, Tmeth_val id), typ)
- | Texp_ident(path, {val_kind = Val_anc (methods, cl_num)}) ->
+ (Tmeth_val id, None, typ)
+ | Texp_ident(path, lid, {val_kind = Val_anc (methods, cl_num)}) ->
let method_id =
begin try List.assoc met methods with Not_found ->
raise(Error(e.pexp_loc, Undefined_inherited_method met))
@@ -1977,25 +2023,32 @@ and type_expect ?in_function env sexp ty_expected =
let (obj_ty, res_ty) = filter_arrow env method_type "" in
unify env obj_ty desc.val_type;
unify env res_ty (instance env typ);
- (Texp_apply({ exp_desc = Texp_ident(Path.Pident method_id,
+ let exp =
+ Texp_apply({ exp_desc = Texp_ident(Path.Pident method_id, lid,
{val_type = method_type;
val_kind = Val_reg;
- val_loc = Location.none;
+ Types.val_loc = Location.none;
});
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = method_type;
exp_env = env },
- [Some {exp_desc = Texp_ident(path, desc);
- exp_loc = obj.exp_loc;
+ ["",
+ Some {exp_desc = Texp_ident(path, lid, desc);
+ exp_loc = obj.exp_loc; exp_extra = [];
exp_type = desc.val_type;
exp_env = env },
- Required]),
- typ)
+ Required])
+ in
+ (Tmeth_name met, Some (re {
+ exp_desc = exp;
+ exp_loc = loc; exp_extra = [];
+ exp_type = typ;
+ exp_env = env }), typ)
| _ ->
assert false
end
| _ ->
- (Texp_send(obj, Tmeth_name met),
+ (Tmeth_name met, None,
filter_method env met Public obj.exp_type)
in
if !Clflags.principal then begin
@@ -2021,28 +2074,28 @@ and type_expect ?in_function env sexp ty_expected =
assert false
in
rue {
- exp_desc = exp;
- exp_loc = loc;
+ exp_desc = Texp_send(obj, meth, exp);
+ exp_loc = loc; exp_extra = [];
exp_type = typ;
exp_env = env }
with Unify _ ->
raise(Error(e.pexp_loc, Undefined_method (obj.exp_type, met)))
end
| Pexp_new cl ->
- let (cl_path, cl_decl) = Typetexp.find_class env loc cl in
+ let (cl_path, cl_decl) = Typetexp.find_class env loc cl.txt in
begin match cl_decl.cty_new with
None ->
- raise(Error(loc, Virtual_class cl))
+ raise(Error(loc, Virtual_class cl.txt))
| Some ty ->
rue {
- exp_desc = Texp_new (cl_path, cl_decl);
- exp_loc = loc;
+ exp_desc = Texp_new (cl_path, cl, cl_decl);
+ exp_loc = loc; exp_extra = [];
exp_type = instance_def ty;
exp_env = env }
end
| Pexp_setinstvar (lab, snewval) ->
begin try
- let (path, desc) = Env.lookup_value (Longident.Lident lab) env in
+ let (path, desc) = Env.lookup_value (Longident.Lident lab.txt) env in
match desc.val_kind with
Val_ivar (Mutable, cl_num) ->
let newval = type_expect env snewval (instance env desc.val_type) in
@@ -2050,25 +2103,25 @@ and type_expect ?in_function env sexp ty_expected =
Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env
in
rue {
- exp_desc = Texp_setinstvar(path_self, path, newval);
- exp_loc = loc;
+ exp_desc = Texp_setinstvar(path_self, path, lab, newval);
+ exp_loc = loc; exp_extra = [];
exp_type = instance_def Predef.type_unit;
exp_env = env }
| Val_ivar _ ->
- raise(Error(loc,Instance_variable_not_mutable(true,lab)))
+ raise(Error(loc,Instance_variable_not_mutable(true,lab.txt)))
| _ ->
- raise(Error(loc,Instance_variable_not_mutable(false,lab)))
+ raise(Error(loc,Instance_variable_not_mutable(false,lab.txt)))
with
Not_found ->
- raise(Error(loc, Unbound_instance_variable lab))
+ raise(Error(loc, Unbound_instance_variable lab.txt))
end
| Pexp_override lst ->
let _ =
List.fold_right
(fun (lab, _) l ->
- if List.exists ((=) lab) l then
+ if List.exists (fun l -> l.txt = lab.txt) l then
raise(Error(loc,
- Value_multiply_overridden lab));
+ Value_multiply_overridden lab.txt));
lab::l)
lst
[] in
@@ -2083,17 +2136,17 @@ and type_expect ?in_function env sexp ty_expected =
(path_self, _) ->
let type_override (lab, snewval) =
begin try
- let (id, _, _, ty) = Vars.find lab !vars in
- (Path.Pident id, type_expect env snewval (instance env ty))
+ let (id, _, _, ty) = Vars.find lab.txt !vars in
+ (Path.Pident id, lab, type_expect env snewval (instance env ty))
with
Not_found ->
- raise(Error(loc, Unbound_instance_variable lab))
+ raise(Error(loc, Unbound_instance_variable lab.txt))
end
in
let modifs = List.map type_override lst in
rue {
exp_desc = Texp_override(path_self, modifs);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = self_ty;
exp_env = env }
| _ ->
@@ -2106,7 +2159,7 @@ and type_expect ?in_function env sexp ty_expected =
Ident.set_current_time ty.level;
let context = Typetexp.narrow () in
let modl = !type_module env smodl in
- let (id, new_env) = Env.enter_module name modl.mod_type env in
+ let (id, new_env) = Env.enter_module name.txt modl.mod_type env in
Ctype.init_def(Ident.current_time());
Typetexp.widen context;
let body = type_expect new_env sbody ty_expected in
@@ -2120,25 +2173,25 @@ and type_expect ?in_function env sexp ty_expected =
begin try
Ctype.unify_var new_env ty body.exp_type
with Unify _ ->
- raise(Error(loc, Scoping_let_module(name, body.exp_type)))
+ raise(Error(loc, Scoping_let_module(name.txt, body.exp_type)))
end;
re {
- exp_desc = Texp_letmodule(id, modl, body);
- exp_loc = loc;
+ exp_desc = Texp_letmodule(id, name, modl, body);
+ exp_loc = loc; exp_extra = [];
exp_type = ty;
exp_env = env }
| Pexp_assert (e) ->
let cond = type_expect env e Predef.type_bool in
rue {
exp_desc = Texp_assert (cond);
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance_def Predef.type_unit;
exp_env = env;
}
| Pexp_assertfalse ->
re {
exp_desc = Texp_assertfalse;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance env ty_expected;
exp_env = env;
}
@@ -2149,25 +2202,25 @@ and type_expect ?in_function env sexp ty_expected =
let arg = type_expect env e ty in
re {
exp_desc = Texp_lazy arg;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = instance env ty_expected;
exp_env = env;
}
| Pexp_object s ->
let desc, sign, meths = !type_object env loc s in
rue {
- exp_desc = Texp_object (desc, sign, meths);
- exp_loc = loc;
+ exp_desc = Texp_object (desc, (*sign,*) meths);
+ exp_loc = loc; exp_extra = [];
exp_type = sign.cty_self;
exp_env = env;
}
| Pexp_poly(sbody, sty) ->
if !Clflags.principal then begin_def ();
- let ty =
- match sty with None -> repr ty_expected
+ let ty, cty =
+ match sty with None -> repr ty_expected, None
| Some sty ->
- let ty = Typetexp.transl_simple_type env false sty in
- repr ty
+ let cty = Typetexp.transl_simple_type env false sty in
+ repr cty.ctyp_type, Some cty
in
if !Clflags.principal then begin
end_def ();
@@ -2175,7 +2228,7 @@ and type_expect ?in_function env sexp ty_expected =
end;
if sty <> None then
unify_exp_types loc env (instance env ty) (instance env ty_expected);
- begin
+ let exp =
match (expand_head env ty).desc with
Tpoly (ty', []) ->
let exp = type_expect env sbody ty' in
@@ -2199,7 +2252,8 @@ and type_expect ?in_function env sexp ty_expected =
unify_exp env exp ty;
re exp
| _ -> assert false
- end
+ in
+ re { exp with exp_desc = Texp_poly(exp, cty) }
| Pexp_newtype(name, sbody) ->
(* Create a fake abstract type declaration for name. *)
let level = get_current_level () in
@@ -2262,13 +2316,18 @@ and type_expect ?in_function env sexp ty_expected =
let (modl, tl') = !type_package env m p nl tl in
rue {
exp_desc = Texp_pack modl;
- exp_loc = loc;
+ exp_loc = loc; exp_extra = [];
exp_type = newty (Tpackage (p, nl, tl'));
exp_env = env }
| Pexp_open (lid, e) ->
- type_expect (!type_open env sexp.pexp_loc lid) e ty_expected
+ let (path, newenv) = !type_open env sexp.pexp_loc lid in
+ let exp = type_expect newenv e ty_expected in
+ { exp with
+ exp_extra = (Texp_open (path, lid, newenv), loc) :: exp.exp_extra;
+ }
-and type_label_exp create env loc ty_expected (label, sarg) =
+and type_label_exp create env loc ty_expected
+ (label_path, lid, label, sarg) =
(* Here also ty_expected may be at generic_level *)
begin_def ();
let separate = !Clflags.principal || Env.has_local_constraints env in
@@ -2315,7 +2374,7 @@ and type_label_exp create env loc ty_expected (label, sarg) =
with Error (_, Less_general _) as e -> raise e
| _ -> raise exn (* In case of failure return the first error *)
in
- (label, {arg with exp_type = instance env arg.exp_type})
+ (label_path, lid, label, {arg with exp_type = instance env arg.exp_type})
and type_argument env sarg ty_expected' ty_expected =
(* ty_expected' may be generic *)
@@ -2365,18 +2424,23 @@ and type_argument env sarg ty_expected' ty_expected =
(* eta-expand to avoid side effects *)
let var_pair name ty =
let id = Ident.create name in
- {pat_desc = Tpat_var id; pat_type = ty;
+ {pat_desc = Tpat_var (id, mknoloc name); pat_type = ty;pat_extra=[];
pat_loc = Location.none; pat_env = env},
- {exp_type = ty; exp_loc = Location.none; exp_env = env; exp_desc =
- Texp_ident(Path.Pident id, {val_type = ty; val_kind = Val_reg;
- val_loc = Location.none})}
+ {exp_type = ty; exp_loc = Location.none; exp_env = env;
+ exp_extra = [];
+ exp_desc =
+ Texp_ident(Path.Pident id, mknoloc (Longident.Lident name),
+ {val_type = ty; val_kind = Val_reg;
+ Types.val_loc = Location.none})}
in
let eta_pat, eta_var = var_pair "eta" ty_arg in
let func texp =
{ texp with exp_type = ty_fun; exp_desc =
- Texp_function([eta_pat, {texp with exp_type = ty_res; exp_desc =
- Texp_apply (texp, args@
- [Some eta_var, Required])}],
+ Texp_function("", [eta_pat, {texp with exp_type = ty_res; exp_desc =
+ Texp_apply (texp,
+ (List.map (fun (label, exp) ->
+ ("", label, exp)) args)@
+ ["", Some eta_var, Required])}],
Total) } in
if warn then Location.prerr_warning texp.exp_loc
(Warnings.Without_principality "eliminated optional argument");
@@ -2403,10 +2467,15 @@ and type_application env funct sargs =
tvar || List.mem l ls
in
let ignored = ref [] in
- let rec type_unknown_args args omitted ty_fun = function
+ let rec type_unknown_args
+ (args :
+ (Asttypes.label * (unit -> Typedtree.expression) option *
+ Typedtree.optional) list)
+ omitted ty_fun = function
[] ->
(List.map
- (function None, x -> None, x | Some f, x -> Some (f ()), x)
+ (function l, None, x -> l, None, x
+ | l, Some f, x -> l, Some (f ()), x)
(List.rev args),
instance env (result_type omitted ty_fun))
| (l1, sarg1) :: sargl ->
@@ -2416,7 +2485,7 @@ and type_application env funct sargs =
Tvar _ ->
let t1 = newvar () and t2 = newvar () in
let not_identity = function
- Texp_ident(_,{val_kind=Val_prim
+ Texp_ident(_,_,{val_kind=Val_prim
{Primitive.prim_name="%identity"}}) ->
false
| _ -> true
@@ -2449,7 +2518,7 @@ and type_application env funct sargs =
unify_exp env arg1 (type_option(newvar()));
arg1
in
- type_unknown_args ((Some arg1, optional) :: args) omitted ty2 sargl
+ type_unknown_args ((l1, Some arg1, optional) :: args) omitted ty2 sargl
in
let ignore_labels =
!Clflags.classic ||
@@ -2537,7 +2606,7 @@ and type_application env funct sargs =
let omitted =
if arg = None then (l,ty,lv) :: omitted else omitted in
let ty_old = if sargs = [] then ty_fun else ty_old in
- type_args ((arg,optional)::args) omitted ty_fun ty_fun0
+ type_args ((l,arg,optional)::args) omitted ty_fun ty_fun0
ty_old sargs more_sargs
| _ ->
match sargs with
@@ -2549,7 +2618,7 @@ and type_application env funct sargs =
in
match funct.exp_desc, sargs with
(* Special case for ignore: avoid discarding warning *)
- Texp_ident (_, {val_kind=Val_prim{Primitive.prim_name="%ignore"}}),
+ Texp_ident (_, _, {val_kind=Val_prim{Primitive.prim_name="%ignore"}}),
["", sarg] ->
let ty_arg, ty_res = filter_arrow env (instance env funct.exp_type) "" in
let exp = type_expect env sarg ty_arg in
@@ -2560,7 +2629,7 @@ and type_application env funct sargs =
add_delayed_check (fun () -> check_application_result env false exp)
| _ -> ()
end;
- ([Some exp, Required], ty_res)
+ (["", Some exp, Required], ty_res)
| _ ->
let ty = funct.exp_type in
if ignore_labels then
@@ -2569,8 +2638,8 @@ and type_application env funct sargs =
type_args [] [] ty (instance env ty) ty sargs []
and type_construct env loc lid sarg explicit_arity ty_expected =
- let constr = Typetexp.find_constructor env loc lid in
- Env.mark_constructor `Positive env (Longident.last lid) constr;
+ let (path,constr) = Typetexp.find_constructor env loc lid.txt in
+ Env.mark_constructor `Positive env (Longident.last lid.txt) constr;
let sargs =
match sarg with
None -> []
@@ -2579,14 +2648,14 @@ and type_construct env loc lid sarg explicit_arity ty_expected =
| Some se -> [se] in
if List.length sargs <> constr.cstr_arity then
raise(Error(loc, Constructor_arity_mismatch
- (lid, constr.cstr_arity, List.length sargs)));
+ (lid.txt, constr.cstr_arity, List.length sargs)));
let separate = !Clflags.principal || Env.has_local_constraints env in
if separate then (begin_def (); begin_def ());
let (ty_args, ty_res) = instance_constructor constr in
let texp =
re {
- exp_desc = Texp_construct(constr, []);
- exp_loc = loc;
+ exp_desc = Texp_construct(path, lid, constr, [],explicit_arity);
+ exp_loc = loc; exp_extra = [];
exp_type = ty_res;
exp_env = env } in
if separate then begin
@@ -2609,7 +2678,7 @@ and type_construct env loc lid sarg explicit_arity ty_expected =
(List.combine ty_args ty_args0) in
if constr.cstr_private = Private then
raise(Error(loc, Private_type ty_res));
- { texp with exp_desc = Texp_construct(constr, args)}
+ { texp with exp_desc = Texp_construct(path, lid, constr, args, explicit_arity)}
(* Typing of statements (expressions whose values are discarded) *)
@@ -2645,7 +2714,7 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist =
let patterns = List.map fst caselist in
List.exists contains_polymorphic_variant patterns,
List.exists (contains_gadt env) patterns in
- (* prerr_endline ( if has_gadts then "contains gadt" else "no gadt"); *)
+(* prerr_endline ( if has_gadts then "contains gadt" else "no gadt"); *)
let ty_arg, ty_res, env =
if has_gadts && not !Clflags.principal then
correct_levels ty_arg, correct_levels ty_res,
@@ -2655,18 +2724,18 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist =
if has_gadts then begin
(* raise level for existentials *)
begin_def ();
- Ident.set_current_time (get_current_level ());
+ Ident.set_current_time (get_current_level ());
let lev = Ident.current_time () in
Ctype.init_def (lev+1000); (* up to 1000 existentials *)
(lev, Env.add_gadt_instance_level lev env)
end else (get_current_level (), env)
in
- (* if has_gadts then
- Format.printf "lev = %d@.%a@." lev Printtyp.raw_type_expr ty_res;*)
+(* if has_gadts then
+ Format.printf "lev = %d@.%a@." lev Printtyp.raw_type_expr ty_res; *)
begin_def (); (* propagation of the argument *)
let ty_arg' = newvar () in
let pattern_force = ref [] in
- (* Format.printf "@[%i %i@ %a@]@." lev (get_current_level())
+(* Format.printf "@[%i %i@ %a@]@." lev (get_current_level())
Printtyp.raw_type_expr ty_arg; *)
let pat_env_list =
List.map
@@ -2722,7 +2791,7 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist =
end
else if contains_gadt env spat then correct_levels ty_res
else ty_res in
- (* Format.printf "@[%i %i, ty_res' =@ %a@]@." lev (get_current_level())
+(* Format.printf "@[%i %i, ty_res' =@ %a@]@." lev (get_current_level())
Printtyp.raw_type_expr ty_res'; *)
let exp = type_expect ?in_function ext_env sexp ty_res' in
(pat, {exp with exp_type = instance env ty_res'}))
@@ -2757,7 +2826,7 @@ and type_let ?(check = fun s -> Warnings.Unused_var s)
let is_fake_let =
match spat_sexp_list with
| [_, {pexp_desc=Pexp_match(
- {pexp_desc=Pexp_ident(Longident.Lident "*opt*")},_)}] ->
+ {pexp_desc=Pexp_ident({ txt = Longident.Lident "*opt*"})},_)}] ->
true (* the fake let-declaration introduced by fun ?(x = e) -> ... *)
| _ ->
false
@@ -2846,7 +2915,7 @@ and type_let ?(check = fun s -> Warnings.Unused_var s)
(* has one of the identifier of this pattern been used? *)
let slot = ref [] in
List.iter
- (fun id ->
+ (fun (id,_) ->
let vd = Env.find_value (Path.Pident id) new_env in
(* note: Env.find_value does not trigger the value_used event *)
let name = Ident.name id in
@@ -2855,7 +2924,7 @@ and type_let ?(check = fun s -> Warnings.Unused_var s)
add_delayed_check
(fun () ->
if not !used then
- Location.prerr_warning vd.val_loc
+ Location.prerr_warning vd.Types.val_loc
((if !some_used then check_strict else check) name)
);
Env.set_value_used_callback
@@ -2944,7 +3013,7 @@ let type_expression env sexp =
match sexp.pexp_desc with
Pexp_ident lid ->
(* Special case for keeping type variables when looking-up a variable *)
- let (path, desc) = Env.lookup_value lid env in
+ let (path, desc) = Env.lookup_value lid.txt env in
{exp with exp_type = desc.val_type}
| _ -> exp
@@ -3014,7 +3083,7 @@ let report_error ppf = function
fprintf ppf "The record field label %a is defined several times"
longident lid
| Label_missing labels ->
- let print_labels ppf = List.iter (fun lbl -> fprintf ppf "@ %s" lbl) in
+ let print_labels ppf = List.iter (fun lbl -> fprintf ppf "@ %s" (Ident.name lbl)) in
fprintf ppf "@[<hov>Some record field labels are undefined:%a@]"
print_labels labels
| Label_not_mutable lid ->
@@ -3126,3 +3195,4 @@ let report_error ppf = function
let () =
Env.add_delayed_check_forward := add_delayed_check
+
diff --git a/typing/typecore.mli b/typing/typecore.mli
index 8b9ce86f0..ddc6699f2 100644
--- a/typing/typecore.mli
+++ b/typing/typecore.mli
@@ -34,7 +34,7 @@ val type_expression:
Env.t -> Parsetree.expression -> Typedtree.expression
val type_class_arg_pattern:
string -> Env.t -> Env.t -> label -> Parsetree.pattern ->
- Typedtree.pattern * (Ident.t * Ident.t * type_expr) list *
+ Typedtree.pattern * (Ident.t * string loc * Ident.t * type_expr) list *
Env.t * Env.t
val type_self_pattern:
string -> type_expr -> Env.t -> Env.t -> Env.t -> Parsetree.pattern ->
@@ -75,7 +75,7 @@ type error =
| Apply_non_function of type_expr
| Apply_wrong_label of label * type_expr
| Label_multiply_defined of Longident.t
- | Label_missing of string list
+ | Label_missing of Ident.t list
| Label_not_mutable of Longident.t
| Incomplete_format of string
| Bad_conversion of string * int * char
@@ -111,13 +111,15 @@ val report_error: formatter -> error -> unit
(* Forward declaration, to be filled in by Typemod.type_module *)
val type_module: (Env.t -> Parsetree.module_expr -> Typedtree.module_expr) ref
(* Forward declaration, to be filled in by Typemod.type_open *)
-val type_open: (Env.t -> Location.t -> Longident.t -> Env.t) ref
+val type_open: (Env.t -> Location.t -> Longident.t loc -> Path.t * Env.t) ref
(* Forward declaration, to be filled in by Typeclass.class_structure *)
val type_object:
(Env.t -> Location.t -> Parsetree.class_structure ->
- Typedtree.class_structure * class_signature * string list) ref
+ Typedtree.class_structure * Types.class_signature * string list) ref
val type_package:
(Env.t -> Parsetree.module_expr -> Path.t -> Longident.t list -> type_expr list ->
Typedtree.module_expr * type_expr list) ref
-val create_package_type: Location.t -> Env.t -> Parsetree.package_type -> type_expr
+val create_package_type : Location.t -> Env.t ->
+ Longident.t * (Longident.t * Parsetree.core_type) list ->
+ Path.t * (Longident.t * Typedtree.core_type) list * Types.type_expr
diff --git a/typing/typedecl.ml b/typing/typedecl.ml
index e7ebd9688..1fc319d4a 100644
--- a/typing/typedecl.ml
+++ b/typing/typedecl.ml
@@ -43,6 +43,8 @@ type error =
| Unbound_type_var_exc of type_expr * type_expr
| Varying_anonymous
+open Typedtree
+
exception Error of Location.t * error
(* Enter all declared types in the environment as abstract types *)
@@ -124,11 +126,11 @@ module StringSet =
end)
let make_params sdecl =
- try
- List.map
+ try
+ List.map
(function
None -> Ctype.new_global_var ~name:"_" ()
- | Some x -> enter_type_variable true sdecl.ptype_loc x)
+ | Some x -> enter_type_variable true sdecl.ptype_loc x.txt)
sdecl.ptype_params
with Already_bound ->
raise(Error(sdecl.ptype_loc, Repeated_parameter))
@@ -139,106 +141,131 @@ let transl_declaration env (name, sdecl) id =
Ctype.begin_def ();
let params = make_params sdecl in
let cstrs = List.map
- (fun (sty, sty', loc) ->
- transl_simple_type env false sty,
- transl_simple_type env false sty', loc)
- sdecl.ptype_cstrs
+ (fun (sty, sty', loc) ->
+ transl_simple_type env false sty,
+ transl_simple_type env false sty', loc)
+ sdecl.ptype_cstrs
in
- let decl =
- { type_params = params;
- type_arity = List.length params;
- type_kind =
- begin match sdecl.ptype_kind with
- Ptype_abstract -> Type_abstract
- | Ptype_variant cstrs ->
- let all_constrs = ref StringSet.empty in
- List.iter
- (fun (name, _, _, loc) ->
- if StringSet.mem name !all_constrs then
- raise(Error(sdecl.ptype_loc, Duplicate_constructor name));
- all_constrs := StringSet.add name !all_constrs)
- cstrs;
- if List.length
- (List.filter (fun (_, args, _, _) -> args <> []) cstrs)
- > (Config.max_tag + 1) then
- raise(Error(sdecl.ptype_loc, Too_many_constructors));
- let make_cstr (name, args, ret_type, loc) =
- match ret_type with
- | None ->
- (name, List.map (transl_simple_type env true) args, None)
- | Some sty ->
- (* if it's a generalized constructor we must first narrow and
- then widen so as to not introduce any new constraints *)
- let z = narrow () in
- reset_type_variables ();
- let args = List.map (transl_simple_type env false) args in
- let ret_type =
- let ty = transl_simple_type env false sty in
- let p = Path.Pident id in
- match (Ctype.repr ty).desc with
- Tconstr (p', _, _) when Path.same p p' -> ty
- | _ -> raise(Error(sty.ptyp_loc,
- Constraint_failed (ty, Ctype.newconstr p params)))
- in
- widen z;
- (name, args, Some ret_type)
- in
- Type_variant (List.map make_cstr cstrs)
-
- | Ptype_record lbls ->
- let all_labels = ref StringSet.empty in
- List.iter
- (fun (name, mut, arg, loc) ->
- if StringSet.mem name !all_labels then
- raise(Error(sdecl.ptype_loc, Duplicate_label name));
- all_labels := StringSet.add name !all_labels)
- lbls;
- let lbls' =
- List.map
- (fun (name, mut, arg, loc) ->
- let ty = transl_simple_type env true arg in
- name, mut, match ty.desc with Tpoly(t,[]) -> t | _ -> ty)
- lbls in
- let rep =
- if List.for_all (fun (name, mut, arg) -> is_float env arg) lbls'
- then Record_float
- else Record_regular in
- Type_record(lbls', rep)
- end;
- type_private = sdecl.ptype_private;
- type_manifest =
- begin match sdecl.ptype_manifest with
- None -> None
- | Some sty ->
- let no_row = not (is_fixed_type sdecl) in
- Some (transl_simple_type env no_row sty)
- end;
- type_variance = List.map (fun _ -> true, true, true) params;
- type_newtype_level = None;
- type_loc = sdecl.ptype_loc;
- } in
+ let (tkind, kind) =
+ match sdecl.ptype_kind with
+ Ptype_abstract -> Ttype_abstract, Type_abstract
+ | Ptype_variant cstrs ->
+ let all_constrs = ref StringSet.empty in
+ List.iter
+ (fun ({ txt = name}, _, _, loc) ->
+ if StringSet.mem name !all_constrs then
+ raise(Error(sdecl.ptype_loc, Duplicate_constructor name));
+ all_constrs := StringSet.add name !all_constrs)
+ cstrs;
+ if List.length
+ (List.filter (fun (_, args, _, _) -> args <> []) cstrs)
+ > (Config.max_tag + 1) then
+ raise(Error(sdecl.ptype_loc, Too_many_constructors));
+ let make_cstr (lid, args, ret_type, loc) =
+ let name = Ident.create lid.txt in
+ match ret_type with
+ | None ->
+ (name, lid, List.map (transl_simple_type env true) args, None, loc)
+ | Some sty ->
+ (* if it's a generalized constructor we must first narrow and
+ then widen so as to not introduce any new constraints *)
+ let z = narrow () in
+ reset_type_variables ();
+ let args = List.map (transl_simple_type env false) args in
+ let ret_type =
+ let cty = transl_simple_type env false sty in
+ let ty = cty.ctyp_type in
+ let p = Path.Pident id in
+ match (Ctype.repr ty).desc with
+ Tconstr (p', _, _) when Path.same p p' -> ty
+ | _ -> raise(Error(sty.ptyp_loc,
+ Constraint_failed (ty, Ctype.newconstr p params)))
+ in
+ widen z;
+ (name, lid, args, Some ret_type, loc)
+ in
+ let cstrs = List.map make_cstr cstrs in
+ Ttype_variant (List.map (fun (name, lid, ctys, _, loc) ->
+ name, lid, ctys, loc
+ ) cstrs),
+ Type_variant (List.map (fun (name, name_loc, ctys, option, loc) ->
+ name, List.map (fun cty -> cty.ctyp_type) ctys, option) cstrs)
+
+ | Ptype_record lbls ->
+ let all_labels = ref StringSet.empty in
+ List.iter
+ (fun ({ txt = name }, mut, arg, loc) ->
+ if StringSet.mem name !all_labels then
+ raise(Error(sdecl.ptype_loc, Duplicate_label name));
+ all_labels := StringSet.add name !all_labels)
+ lbls;
+ let lbls = List.map (fun (name, mut, arg, loc) ->
+ let cty = transl_simple_type env true arg in
+ (Ident.create name.txt, name, mut, cty, loc)
+ ) lbls in
+ let lbls' =
+ List.map
+ (fun (name, name_loc, mut, cty, loc) ->
+ let ty = cty.ctyp_type in
+ name, mut, match ty.desc with Tpoly(t,[]) -> t | _ -> ty)
+ lbls in
+ let rep =
+ if List.for_all (fun (name, mut, arg) -> is_float env arg) lbls'
+ then Record_float
+ else Record_regular in
+ Ttype_record lbls, Type_record(lbls', rep)
+ in
+ let (tman, man) = match sdecl.ptype_manifest with
+ None -> None, None
+ | Some sty ->
+ let no_row = not (is_fixed_type sdecl) in
+ let cty = transl_simple_type env no_row sty in
+ Some cty, Some cty.ctyp_type
+ in
+ let decl =
+ { type_params = params;
+ type_arity = List.length params;
+ type_kind = kind;
+ type_private = sdecl.ptype_private;
+ type_manifest = man;
+ type_variance = List.map (fun _ -> true, true, true) params;
+ type_newtype_level = None;
+ type_loc = sdecl.ptype_loc;
+ } in
(* Check constraints *)
- List.iter
- (fun (ty, ty', loc) ->
- try Ctype.unify env ty ty' with Ctype.Unify tr ->
- raise(Error(loc, Inconsistent_constraint tr)))
- cstrs;
- Ctype.end_def ();
+ List.iter
+ (fun (cty, cty', loc) ->
+ let ty = cty.ctyp_type in
+ let ty' = cty'.ctyp_type in
+ try Ctype.unify env ty ty' with Ctype.Unify tr ->
+ raise(Error(loc, Inconsistent_constraint tr)))
+ cstrs;
+ Ctype.end_def ();
(* Add abstract row *)
- if is_fixed_type sdecl then begin
- let (p, _) =
- try Env.lookup_type (Longident.Lident(Ident.name id ^ "#row")) env
- with Not_found -> assert false in
- set_fixed_row env sdecl.ptype_loc p decl
- end;
+ if is_fixed_type sdecl then begin
+ let (p, _) =
+ try Env.lookup_type (Longident.Lident(Ident.name id ^ "#row")) env
+ with Not_found -> assert false in
+ set_fixed_row env sdecl.ptype_loc p decl
+ end;
(* Check for cyclic abbreviations *)
- begin match decl.type_manifest with None -> ()
- | Some ty ->
- if Ctype.cyclic_abbrev env id ty then
- raise(Error(sdecl.ptype_loc, Recursive_abbrev name));
- end;
- (id, decl)
+ begin match decl.type_manifest with None -> ()
+ | Some ty ->
+ if Ctype.cyclic_abbrev env id ty then
+ raise(Error(sdecl.ptype_loc, Recursive_abbrev name.txt));
+ end;
+ let tdecl = {
+ typ_params = sdecl.ptype_params;
+ typ_type = decl;
+ typ_cstrs = cstrs;
+ typ_loc = sdecl.ptype_loc;
+ typ_manifest = tman;
+ typ_kind = tkind;
+ typ_variance = sdecl.ptype_variance;
+ typ_private = sdecl.ptype_private;
+ } in
+ (id, name, tdecl)
(* Generalize a type declaration *)
@@ -302,7 +329,7 @@ let check_constraints env (_, sdecl) (_, decl) =
let (styl, sret_type) =
try
let (_, sty, sret_type, _) =
- List.find (fun (n,_,_,_) -> n = name) pl
+ List.find (fun (n,_,_,_) -> n.txt = Ident.name name) pl
in (sty, sret_type)
with Not_found -> assert false in
List.iter2
@@ -324,11 +351,11 @@ let check_constraints env (_, sdecl) (_, decl) =
let rec get_loc name = function
[] -> assert false
| (name', _, sty, _) :: tl ->
- if name = name' then sty.ptyp_loc else get_loc name tl
+ if name = name'.txt then sty.ptyp_loc else get_loc name tl
in
List.iter
(fun (name, _, ty) ->
- check_constraints_rec env (get_loc name pl) visited ty)
+ check_constraints_rec env (get_loc (Ident.name name) pl) visited ty)
l
end;
begin match decl.type_manifest with
@@ -438,7 +465,8 @@ let check_recursion env loc path decl to_check =
Ctype.instance_parameterized_type decl.type_params body in
check_regular path args [] body
-let check_abbrev_recursion env id_loc_list (id, decl) =
+let check_abbrev_recursion env id_loc_list (id, _, tdecl) =
+ let decl = tdecl.typ_type in
check_recursion env (List.assoc id id_loc_list) (Path.Pident id) decl
(function Path.Pident id -> List.mem_assoc id id_loc_list | _ -> false)
@@ -519,7 +547,7 @@ let whole_type decl =
match decl.type_kind with
Type_variant tll ->
Btype.newgenty
- (Ttuple (List.map (fun (_, tl, _) -> Btype.newgenty (Ttuple tl)) tll))
+ (Ttuple (List.map (fun (_, tl, _) -> Btype.newgenty (Ttuple tl)) tll))
| Type_record (ftl, _) ->
Btype.newgenty
(Ttuple (List.map (fun (_, _, ty) -> ty) ftl))
@@ -600,7 +628,7 @@ let compute_variance_gadt env check (required, loc as rloc) decl
{decl with type_params = tyl; type_private = Private}
(add_false tl)
| _ -> assert false
-
+
let compute_variance_decl env check decl (required, loc as rloc) =
if decl.type_kind = Type_abstract && decl.type_manifest = None then
List.map (fun (c, n) -> if c || n then (c, n, n) else (true, true, true))
@@ -664,8 +692,8 @@ let init_variance (id, decl) =
let compute_variance_decls env cldecls =
let decls, required =
List.fold_right
- (fun (obj_id, obj_abbr, cl_abbr, clty, cltydef, required) (decls, req) ->
- (obj_id, obj_abbr) :: decls, required :: req)
+ (fun (obj_id, obj_abbr, cl_abbr, clty, cltydef, ci) (decls, req) ->
+ (obj_id, obj_abbr) :: decls, (ci.ci_variance, ci.ci_loc) :: req)
cldecls ([],[])
in
let variances = List.map init_variance decls in
@@ -688,20 +716,20 @@ let check_duplicates name_sdecl_list =
List.iter
(fun (cname, _, _, loc) ->
try
- let name' = Hashtbl.find constrs cname in
+ let name' = Hashtbl.find constrs cname.txt in
Location.prerr_warning loc
(Warnings.Duplicate_definitions
- ("constructor", cname, name', name))
- with Not_found -> Hashtbl.add constrs cname name)
+ ("constructor", cname.txt, name', name.txt))
+ with Not_found -> Hashtbl.add constrs cname.txt name.txt)
cl
| Ptype_record fl ->
List.iter
(fun (cname, _, _, loc) ->
try
- let name' = Hashtbl.find labels cname in
+ let name' = Hashtbl.find labels cname.txt in
Location.prerr_warning loc
- (Warnings.Duplicate_definitions ("label", cname, name', name))
- with Not_found -> Hashtbl.add labels cname name)
+ (Warnings.Duplicate_definitions ("label", cname.txt, name', name.txt))
+ with Not_found -> Hashtbl.add labels cname.txt name.txt)
fl
| Ptype_abstract -> ())
name_sdecl_list
@@ -729,15 +757,15 @@ let transl_type_decl env name_sdecl_list =
in
let name_sdecl_list =
List.map
- (fun (name,sdecl) ->
- name^"#row",
+ (fun (name, sdecl) ->
+ mkloc (name.txt ^"#row") name.loc,
{sdecl with ptype_kind = Ptype_abstract; ptype_manifest = None})
fixed_types
@ name_sdecl_list
in
(* Create identifiers. *)
let id_list =
- List.map (fun (name, _) -> Ident.create name) name_sdecl_list
+ List.map (fun (name, _) -> Ident.create name.txt) name_sdecl_list
in
(*
Since we've introduced fresh idents, make sure the definition
@@ -774,8 +802,9 @@ let transl_type_decl env name_sdecl_list =
in
let transl_declaration name_sdecl (id, slot) =
current_slot := slot; transl_declaration temp_env name_sdecl id in
- let decls =
+ let tdecls =
List.map2 transl_declaration name_sdecl_list (List.map id_slots id_list) in
+ let decls = List.map (fun (id, name_loc, tdecl) -> (id, tdecl.typ_type)) tdecls in
current_slot := None;
(* Check for duplicates *)
check_duplicates name_sdecl_list;
@@ -797,21 +826,23 @@ let transl_type_decl env name_sdecl_list =
List.map2 (fun id (_,sdecl) -> (id, sdecl.ptype_loc))
id_list name_sdecl_list
in
- List.iter (check_abbrev_recursion newenv id_loc_list) decls;
+ List.iter (check_abbrev_recursion newenv id_loc_list) tdecls;
(* Check that all type variable are closed *)
List.iter2
- (fun (_, sdecl) (id, decl) ->
+ (fun (_, sdecl) (id, _, tdecl) ->
+ let decl = tdecl.typ_type in
match Ctype.closed_type_decl decl with
Some ty -> raise(Error(sdecl.ptype_loc, Unbound_type_var(ty,decl)))
| None -> ())
- name_sdecl_list decls;
+ name_sdecl_list tdecls;
(* Check re-exportation *)
List.iter2 (check_abbrev newenv) name_sdecl_list decls;
(* Check that constraints are enforced *)
List.iter2 (check_constraints newenv) name_sdecl_list decls;
(* Name recursion *)
let decls =
- List.map2 (fun (_, sdecl) (id, decl) -> id, name_recursion sdecl id decl)
+ List.map2 (fun (_, sdecl) (id, decl) ->
+ id, name_recursion sdecl id decl)
name_sdecl_list decls
in
(* Add variances to the environment *)
@@ -822,28 +853,36 @@ let transl_type_decl env name_sdecl_list =
let final_decls, final_env =
compute_variance_fixpoint env decls required (List.map init_variance decls)
in
+ let final_decls = List.map2 (fun (id, name_loc, tdecl) (id2, decl) ->
+ (id, name_loc, { tdecl with typ_type = decl })
+ ) tdecls final_decls in
(* Done *)
(final_decls, final_env)
(* Translate an exception declaration *)
let transl_closed_type env sty =
- let ty = transl_simple_type env true sty in
+ let cty = transl_simple_type env true sty in
+ let ty = cty.ctyp_type in
+ let ty =
match Ctype.free_variables ty with
| [] -> ty
| tv :: _ -> raise (Error (sty.ptyp_loc, Unbound_type_var_exc (tv, ty)))
+ in
+ { cty with ctyp_type = ty }
let transl_exception env loc excdecl =
reset_type_variables();
Ctype.begin_def();
- let types = List.map (transl_closed_type env) excdecl in
+ let ttypes = List.map (transl_closed_type env) excdecl in
Ctype.end_def();
+ let types = List.map (fun cty -> cty.ctyp_type) ttypes in
List.iter Ctype.generalize types;
- { exn_args = types;
- exn_loc = loc }
+ let exn_decl = { exn_args = types; Types.exn_loc = loc } in
+ { exn_params = ttypes; exn_exn = exn_decl; Typedtree.exn_loc = loc }
(* Translate an exception rebinding *)
let transl_exn_rebind env loc lid =
- let cdescr =
+ let (path, cdescr) =
try
Env.lookup_constructor lid env
with Not_found ->
@@ -851,15 +890,17 @@ let transl_exn_rebind env loc lid =
Env.mark_constructor `Positive env (Longident.last lid) cdescr;
match cdescr.cstr_tag with
Cstr_exception (path, _) ->
- (path, {exn_args = cdescr.cstr_args; exn_loc = loc})
+ (path, {exn_args = cdescr.cstr_args; Types.exn_loc = loc})
| _ -> raise(Error(loc, Not_an_exception lid))
(* Translate a value declaration *)
let transl_value_decl env loc valdecl =
- let ty = Typetexp.transl_type_scheme env valdecl.pval_type in
+ let cty = Typetexp.transl_type_scheme env valdecl.pval_type in
+ let ty = cty.ctyp_type in
+ let v =
match valdecl.pval_prim with
[] ->
- { val_type = ty; val_kind = Val_reg; val_loc = loc }
+ { val_type = ty; val_kind = Val_reg; Types.val_loc = loc }
| decl ->
let arity = Ctype.arity ty in
if arity = 0 then
@@ -869,7 +910,11 @@ let transl_value_decl env loc valdecl =
&& prim.prim_arity > 5
&& prim.prim_native_name = ""
then raise(Error(valdecl.pval_type.ptyp_loc, Missing_native_external));
- { val_type = ty; val_kind = Val_prim prim; val_loc = loc }
+ { val_type = ty; val_kind = Val_prim prim; Types.val_loc = loc }
+ in
+ { val_desc = cty; val_val = v;
+ val_prim = valdecl.pval_prim;
+ val_loc = valdecl.pval_loc; }
(* Translate a "with" constraint -- much simplified version of
transl_type_decl. *)
@@ -881,26 +926,32 @@ let transl_with_constraint env id row_path orig_decl sdecl =
let arity_ok = List.length params = orig_decl.type_arity in
if arity_ok then
List.iter2 (Ctype.unify_var env) params orig_decl.type_params;
- List.iter
+ let constraints = List.map
(function (ty, ty', loc) ->
try
- Ctype.unify env (transl_simple_type env false ty)
- (transl_simple_type env false ty')
+ let cty = transl_simple_type env false ty in
+ let cty' = transl_simple_type env false ty' in
+ let ty = cty.ctyp_type in
+ let ty' = cty'.ctyp_type in
+ Ctype.unify env ty ty';
+ (cty, cty', loc)
with Ctype.Unify tr ->
raise(Error(loc, Inconsistent_constraint tr)))
- sdecl.ptype_cstrs;
+ sdecl.ptype_cstrs
+ in
let no_row = not (is_fixed_type sdecl) in
+ let (tman, man) = match sdecl.ptype_manifest with
+ None -> None, None
+ | Some sty ->
+ let cty = transl_simple_type env no_row sty in
+ Some cty, Some cty.ctyp_type
+ in
let decl =
{ type_params = params;
type_arity = List.length params;
type_kind = if arity_ok then orig_decl.type_kind else Type_abstract;
type_private = sdecl.ptype_private;
- type_manifest =
- begin match sdecl.ptype_manifest with
- None -> None
- | Some sty ->
- Some(transl_simple_type env no_row sty)
- end;
+ type_manifest = man;
type_variance = [];
type_newtype_level = None;
type_loc = sdecl.ptype_loc;
@@ -919,7 +970,16 @@ let transl_with_constraint env id row_path orig_decl sdecl =
(sdecl.ptype_variance, sdecl.ptype_loc)} in
Ctype.end_def();
generalize_decl decl;
- decl
+ {
+ typ_params = sdecl.ptype_params;
+ typ_type = decl;
+ typ_cstrs = constraints;
+ typ_loc = sdecl.ptype_loc;
+ typ_manifest = tman;
+ typ_kind = Ttype_abstract;
+ typ_variance = sdecl.ptype_variance;
+ typ_private = sdecl.ptype_private;
+ }
(* Approximate a type declaration: just make all types abstract *)
@@ -944,7 +1004,7 @@ let abstract_type_decl arity =
let approx_type_decl env name_sdecl_list =
List.map
(fun (name, sdecl) ->
- (Ident.create name,
+ (Ident.create name.txt,
abstract_type_decl (List.length sdecl.ptype_params)))
name_sdecl_list
@@ -1048,12 +1108,12 @@ let report_error ppf = function
let ty = Ctype.repr ty in
begin match decl.type_kind, decl.type_manifest with
| Type_variant tl, _ ->
- explain_unbound ppf ty tl (fun (_,tl,_) ->
- Btype.newgenty (Ttuple tl))
- "case" (fun (lab,_,_) -> lab ^ " of ")
+ explain_unbound ppf ty tl (fun (_,tl,_) ->
+ Btype.newgenty (Ttuple tl))
+ "case" (fun (lab,_,_) -> Ident.name lab ^ " of ")
| Type_record (tl, _), _ ->
explain_unbound ppf ty tl (fun (_,_,t) -> t)
- "field" (fun (lab,_,_) -> lab ^ ": ")
+ "field" (fun (lab,_,_) -> Ident.name lab ^ ": ")
| Type_abstract, Some ty' ->
explain_unbound_single ppf ty ty'
| _ -> ()
diff --git a/typing/typedecl.mli b/typing/typedecl.mli
index 36b0aac62..7f3b53fdb 100644
--- a/typing/typedecl.mli
+++ b/typing/typedecl.mli
@@ -14,28 +14,27 @@
(* Typing of type definitions and primitive definitions *)
+open Asttypes
open Types
open Format
val transl_type_decl:
- Env.t -> (string * Parsetree.type_declaration) list ->
- (Ident.t * type_declaration) list * Env.t
+ Env.t -> (string loc * Parsetree.type_declaration) list ->
+ (Ident.t * string Asttypes.loc * Typedtree.type_declaration) list * Env.t
val transl_exception:
- Env.t -> Location.t -> Parsetree.exception_declaration -> exception_declaration
+ Env.t -> Location.t -> Parsetree.exception_declaration -> Typedtree.exception_declaration
val transl_exn_rebind:
Env.t -> Location.t -> Longident.t -> Path.t * exception_declaration
val transl_value_decl:
- Env.t -> Location.t -> Parsetree.value_description -> value_description
+ Env.t -> Location.t -> Parsetree.value_description -> Typedtree.value_description
-val transl_with_constraint:
- Env.t -> Ident.t -> Path.t option -> type_declaration ->
- Parsetree.type_declaration -> type_declaration
+val transl_with_constraint : Env.t -> Ident.t -> Path.t option -> Types.type_declaration -> Parsetree.type_declaration -> Typedtree.type_declaration
val abstract_type_decl: int -> type_declaration
val approx_type_decl:
- Env.t -> (string * Parsetree.type_declaration) list ->
+ Env.t -> (string loc * Parsetree.type_declaration) list ->
(Ident.t * type_declaration) list
val check_recmod_typedecl:
Env.t -> Location.t -> Ident.t list -> Path.t -> type_declaration -> unit
@@ -44,12 +43,7 @@ val check_recmod_typedecl:
val is_fixed_type : Parsetree.type_declaration -> bool
(* for typeclass.ml *)
-val compute_variance_decls:
- Env.t ->
- (Ident.t * type_declaration * type_declaration * class_declaration *
- cltype_declaration * ((bool * bool) list * Location.t)) list ->
- (type_declaration * type_declaration * class_declaration *
- cltype_declaration) list
+val compute_variance_decls : Env.t -> (Ident.t * Types.type_declaration * Types.type_declaration * Types.class_declaration * Types.class_type_declaration * 'a Typedtree.class_infos) list -> (Types.type_declaration * Types.type_declaration * Types.class_declaration * Types.class_type_declaration) list
type error =
Repeated_parameter
diff --git a/typing/typedtree.ml b/typing/typedtree.ml
index 0feca199a..f315c86b9 100644
--- a/typing/typedtree.ml
+++ b/typing/typedtree.ml
@@ -20,65 +20,78 @@ open Types
(* Value expressions for the core language *)
+type partial = Partial | Total
+type optional = Required | Optional
+
type pattern =
{ pat_desc: pattern_desc;
pat_loc: Location.t;
+ pat_extra : (pat_extra * Location.t) list;
pat_type: type_expr;
mutable pat_env: Env.t }
+and pat_extra =
+ | Tpat_constraint of core_type
+ | Tpat_type of Path.t * Longident.t loc
+ | Tpat_unpack
+
and pattern_desc =
Tpat_any
- | Tpat_var of Ident.t
- | Tpat_alias of pattern * Ident.t
+ | Tpat_var of Ident.t * string loc
+ | Tpat_alias of pattern * Ident.t * string loc
| Tpat_constant of constant
| Tpat_tuple of pattern list
- | Tpat_construct of constructor_description * pattern list
+ | Tpat_construct of Path.t * Longident.t loc * constructor_description * pattern list * bool
| Tpat_variant of label * pattern option * row_desc ref
- | Tpat_record of (label_description * pattern) list
+ | Tpat_record of ( Path.t * Longident.t loc * label_description * pattern) list * closed_flag
| Tpat_array of pattern list
| Tpat_or of pattern * pattern * row_desc option
| Tpat_lazy of pattern
-type partial = Partial | Total
-type optional = Required | Optional
-
-type expression =
+and expression =
{ exp_desc: expression_desc;
exp_loc: Location.t;
+ exp_extra : (exp_extra * Location.t) list;
exp_type: type_expr;
exp_env: Env.t }
+and exp_extra =
+ | Texp_constraint of core_type option * core_type option
+ | Texp_open of Path.t * Longident.t loc * Env.t
+
and expression_desc =
- Texp_ident of Path.t * value_description
+ Texp_ident of Path.t * Longident.t loc * Types.value_description
| Texp_constant of constant
| Texp_let of rec_flag * (pattern * expression) list * expression
- | Texp_function of (pattern * expression) list * partial
- | Texp_apply of expression * (expression option * optional) list
+ | Texp_function of label * (pattern * expression) list * partial
+ | Texp_apply of expression * (label * expression option * optional) list
| Texp_match of expression * (pattern * expression) list * partial
| Texp_try of expression * (pattern * expression) list
| Texp_tuple of expression list
- | Texp_construct of constructor_description * expression list
+ | Texp_construct of Path.t * Longident.t loc * constructor_description * expression list * bool
| Texp_variant of label * expression option
- | Texp_record of (label_description * expression) list * expression option
- | Texp_field of expression * label_description
- | Texp_setfield of expression * label_description * expression
+ | Texp_record of (Path.t * Longident.t loc * label_description * expression) list * expression option
+ | Texp_field of expression * Path.t * Longident.t loc * label_description
+ | Texp_setfield of expression * Path.t * Longident.t loc * label_description * expression
| Texp_array of expression list
| Texp_ifthenelse of expression * expression * expression option
| Texp_sequence of expression * expression
| Texp_while of expression * expression
| Texp_for of
- Ident.t * expression * expression * direction_flag * expression
+ Ident.t * string loc * expression * expression * direction_flag * expression
| Texp_when of expression * expression
- | Texp_send of expression * meth
- | Texp_new of Path.t * class_declaration
- | Texp_instvar of Path.t * Path.t
- | Texp_setinstvar of Path.t * Path.t * expression
- | Texp_override of Path.t * (Path.t * expression) list
- | Texp_letmodule of Ident.t * module_expr * expression
+ | Texp_send of expression * meth * expression option
+ | Texp_new of Path.t * Longident.t loc * Types.class_declaration
+ | Texp_instvar of Path.t * Path.t * string loc
+ | Texp_setinstvar of Path.t * Path.t * string loc * expression
+ | Texp_override of Path.t * (Path.t * string loc * expression) list
+ | Texp_letmodule of Ident.t * string loc * module_expr * expression
| Texp_assert of expression
| Texp_assertfalse
| Texp_lazy of expression
- | Texp_object of class_structure * class_signature * string list
+ | Texp_poly of expression * core_type option
+ | Texp_object of class_structure * string list
+ | Texp_newtype of string * expression
| Texp_pack of module_expr
and meth =
@@ -90,60 +103,91 @@ and meth =
and class_expr =
{ cl_desc: class_expr_desc;
cl_loc: Location.t;
- cl_type: class_type;
+ cl_type: Types.class_type;
cl_env: Env.t }
and class_expr_desc =
- Tclass_ident of Path.t
- | Tclass_structure of class_structure
- | Tclass_fun of pattern * (Ident.t * expression) list * class_expr * partial
- | Tclass_apply of class_expr * (expression option * optional) list
- | Tclass_let of rec_flag * (pattern * expression) list *
- (Ident.t * expression) list * class_expr
- | Tclass_constraint of class_expr * string list * string list * Concr.t
+ Tcl_ident of Path.t * Longident.t loc * core_type list (* Pcl_constr *)
+ | Tcl_structure of class_structure
+ | Tcl_fun of label * pattern * (Ident.t * string loc * expression) list * class_expr * partial
+ | Tcl_apply of class_expr * (label * expression option * optional) list
+ | Tcl_let of rec_flag * (pattern * expression) list *
+ (Ident.t * string loc * expression) list * class_expr
+ | Tcl_constraint of class_expr * class_type option * string list * string list * Concr.t
+ (* Visible instance variables, methods and concretes methods *)
and class_structure =
- { cl_field: class_field list;
- cl_meths: Ident.t Meths.t }
+ { cstr_pat : pattern;
+ cstr_fields: class_field list;
+ cstr_type : Types.class_signature;
+ cstr_meths: Ident.t Meths.t }
and class_field =
- Cf_inher of class_expr * (string * Ident.t) list * (string * Ident.t) list
- | Cf_val of string * Ident.t * expression option * bool
- | Cf_meth of string * expression
- | Cf_init of expression
+ {
+ cf_desc : class_field_desc;
+ cf_loc : Location.t;
+ }
+
+and class_field_kind =
+ Tcfk_virtual of core_type
+| Tcfk_concrete of expression
+
+and class_field_desc =
+ Tcf_inher of override_flag * class_expr * string option * (string * Ident.t) list * (string * Ident.t) list
+ (* Inherited instance variables and concrete methods *)
+ | Tcf_val of string * string loc * mutable_flag * Ident.t * class_field_kind * bool
+ (* None = virtual, true = override *)
+ | Tcf_meth of string * string loc * private_flag * class_field_kind * bool
+ | Tcf_constr of core_type * core_type
+(* | Tcf_let of rec_flag * (pattern * expression) list *
+ (Ident.t * string loc * expression) list *)
+ | Tcf_init of expression
(* Value expressions for the module language *)
and module_expr =
{ mod_desc: module_expr_desc;
mod_loc: Location.t;
- mod_type: module_type;
+ mod_type: Types.module_type;
mod_env: Env.t }
+and module_type_constraint =
+ Tmodtype_implicit
+| Tmodtype_explicit of module_type
+
and module_expr_desc =
- Tmod_ident of Path.t
+ Tmod_ident of Path.t * Longident.t loc
| Tmod_structure of structure
- | Tmod_functor of Ident.t * module_type * module_expr
+ | Tmod_functor of Ident.t * string loc * module_type * module_expr
| Tmod_apply of module_expr * module_expr * module_coercion
- | Tmod_constraint of module_expr * module_type * module_coercion
- | Tmod_unpack of expression * module_type
+ | Tmod_constraint of module_expr * Types.module_type * module_type_constraint * module_coercion
+ | Tmod_unpack of expression * Types.module_type
-and structure = structure_item list
+and structure = {
+ str_items : structure_item list;
+ str_type : Types.signature;
+ str_final_env : Env.t;
+}
and structure_item =
+ { str_desc : structure_item_desc;
+ str_loc : Location.t;
+ str_env : Env.t
+ }
+
+and structure_item_desc =
Tstr_eval of expression
| Tstr_value of rec_flag * (pattern * expression) list
- | Tstr_primitive of Ident.t * value_description
- | Tstr_type of (Ident.t * type_declaration) list
- | Tstr_exception of Ident.t * exception_declaration
- | Tstr_exn_rebind of Ident.t * Path.t
- | Tstr_module of Ident.t * module_expr
- | Tstr_recmodule of (Ident.t * module_expr) list
- | Tstr_modtype of Ident.t * module_type
- | Tstr_open of Path.t
- | Tstr_class of
- (Ident.t * int * string list * class_expr * virtual_flag) list
- | Tstr_cltype of (Ident.t * cltype_declaration) list
+ | Tstr_primitive of Ident.t * string loc * value_description
+ | Tstr_type of (Ident.t * string loc * type_declaration) list
+ | Tstr_exception of Ident.t * string loc * exception_declaration
+ | Tstr_exn_rebind of Ident.t * string loc * Path.t * Longident.t loc
+ | Tstr_module of Ident.t * string loc * module_expr
+ | Tstr_recmodule of (Ident.t * string loc * module_type * module_expr) list
+ | Tstr_modtype of Ident.t * string loc * module_type
+ | Tstr_open of Path.t * Longident.t loc
+ | Tstr_class of (class_declaration * string list * virtual_flag) list
+ | Tstr_class_type of (Ident.t * string loc * class_type_declaration) list
| Tstr_include of module_expr * Ident.t list
and module_coercion =
@@ -152,15 +196,181 @@ and module_coercion =
| Tcoerce_functor of module_coercion * module_coercion
| Tcoerce_primitive of Primitive.description
+and module_type =
+ { mty_desc: module_type_desc;
+ mty_type : Types.module_type;
+ mty_env : Env.t; (* BINANNOT ADDED *)
+ mty_loc: Location.t }
+
+and module_type_desc =
+ Tmty_ident of Path.t * Longident.t loc
+ | Tmty_signature of signature
+ | Tmty_functor of Ident.t * string loc * module_type * module_type
+ | Tmty_with of module_type * (Path.t * Longident.t loc * with_constraint) list
+ | Tmty_typeof of module_expr
+
+and signature = {
+ sig_items : signature_item list;
+ sig_type : Types.signature;
+ sig_final_env : Env.t;
+}
+
+and signature_item =
+ { sig_desc: signature_item_desc;
+ sig_env : Env.t; (* BINANNOT ADDED *)
+ sig_loc: Location.t }
+
+and signature_item_desc =
+ Tsig_value of Ident.t * string loc * value_description
+ | Tsig_type of (Ident.t * string loc * type_declaration) list
+ | Tsig_exception of Ident.t * string loc * exception_declaration
+ | Tsig_module of Ident.t * string loc * module_type
+ | Tsig_recmodule of (Ident.t * string loc * module_type) list
+ | Tsig_modtype of Ident.t * string loc * modtype_declaration
+ | Tsig_open of Path.t * Longident.t loc
+ | Tsig_include of module_type * Types.signature
+ | Tsig_class of class_description list
+ | Tsig_class_type of class_type_declaration list
+
+and modtype_declaration =
+ Tmodtype_abstract
+ | Tmodtype_manifest of module_type
+
+and with_constraint =
+ Twith_type of type_declaration
+ | Twith_module of Path.t * Longident.t loc
+ | Twith_typesubst of type_declaration
+ | Twith_modsubst of Path.t * Longident.t loc
+
+and core_type =
+(* mutable because of [Typeclass.declare_method] *)
+ { mutable ctyp_desc : core_type_desc;
+ mutable ctyp_type : type_expr;
+ ctyp_env : Env.t; (* BINANNOT ADDED *)
+ ctyp_loc : Location.t }
+
+and core_type_desc =
+ Ttyp_any
+ | Ttyp_var of string
+ | Ttyp_arrow of label * core_type * core_type
+ | Ttyp_tuple of core_type list
+ | Ttyp_constr of Path.t * Longident.t loc * core_type list
+ | Ttyp_object of core_field_type list
+ | Ttyp_class of Path.t * Longident.t loc * core_type list * label list
+ | Ttyp_alias of core_type * string
+ | Ttyp_variant of row_field list * bool * label list option
+ | Ttyp_poly of string list * core_type
+ | Ttyp_package of package_type
+
+and package_type = {
+ pack_name : Path.t;
+ pack_fields : (Longident.t loc * core_type) list;
+ pack_type : Types.module_type;
+ pack_txt : Longident.t loc;
+}
+
+and core_field_type =
+ { field_desc: core_field_desc;
+ field_loc: Location.t }
+
+and core_field_desc =
+ Tcfield of string * core_type
+ | Tcfield_var
+
+and row_field =
+ Ttag of label * bool * core_type list
+ | Tinherit of core_type
+
+and value_description =
+ { val_desc : core_type;
+ val_val : Types.value_description;
+ val_prim : string list;
+ val_loc : Location.t;
+ }
+
+and type_declaration =
+ { typ_params: string loc option list;
+ typ_type : Types.type_declaration;
+ typ_cstrs: (core_type * core_type * Location.t) list;
+ typ_kind: type_kind;
+ typ_private: private_flag;
+ typ_manifest: core_type option;
+ typ_variance: (bool * bool) list;
+ typ_loc: Location.t }
+
+and type_kind =
+ Ttype_abstract
+ | Ttype_variant of (Ident.t * string loc * core_type list * Location.t) list
+ | Ttype_record of
+ (Ident.t * string loc * mutable_flag * core_type * Location.t) list
+
+and exception_declaration =
+ { exn_params : core_type list;
+ exn_exn : Types.exception_declaration;
+ exn_loc : Location.t }
+
+and class_type =
+ { cltyp_desc: class_type_desc;
+ cltyp_type : Types.class_type;
+ cltyp_env : Env.t; (* BINANNOT ADDED *)
+ cltyp_loc: Location.t }
+
+and class_type_desc =
+ Tcty_constr of Path.t * Longident.t loc * core_type list
+ | Tcty_signature of class_signature
+ | Tcty_fun of label * core_type * class_type
+
+and class_signature = {
+ csig_self : core_type;
+ csig_fields : class_type_field list;
+ csig_type : Types.class_signature;
+ csig_loc : Location.t;
+ }
+
+and class_type_field = {
+ ctf_desc : class_type_field_desc;
+ ctf_loc : Location.t;
+ }
+
+and class_type_field_desc =
+ Tctf_inher of class_type
+ | Tctf_val of (string * mutable_flag * virtual_flag * core_type)
+ | Tctf_virt of (string * private_flag * core_type)
+ | Tctf_meth of (string * private_flag * core_type)
+ | Tctf_cstr of (core_type * core_type)
+
+and class_declaration =
+ class_expr class_infos
+
+and class_description =
+ class_type class_infos
+
+and class_type_declaration =
+ class_type class_infos
+
+and 'a class_infos =
+ { ci_virt: virtual_flag;
+ ci_params: string loc list * Location.t;
+ ci_id_name : string loc;
+ ci_id_class: Ident.t;
+ ci_id_class_type : Ident.t;
+ ci_id_object : Ident.t;
+ ci_id_typesharp : Ident.t;
+ ci_expr: 'a;
+ ci_decl: Types.class_declaration;
+ ci_type_decl : Types.class_type_declaration;
+ ci_variance: (bool * bool) list;
+ ci_loc: Location.t }
+
(* Auxiliary functions over the a.s.t. *)
let iter_pattern_desc f = function
- | Tpat_alias(p, id) -> f p
+ | Tpat_alias(p, _, _) -> f p
| Tpat_tuple patl -> List.iter f patl
- | Tpat_construct(cstr, patl) -> List.iter f patl
+ | Tpat_construct(_, _, cstr, patl, _) -> List.iter f patl
| Tpat_variant(_, pat, _) -> may f pat
- | Tpat_record lbl_pat_list ->
- List.iter (fun (lbl, pat) -> f pat) lbl_pat_list
+ | Tpat_record (lbl_pat_list, _) ->
+ List.iter (fun (_, _, lbl, pat) -> f pat) lbl_pat_list
| Tpat_array patl -> List.iter f patl
| Tpat_or(p1, p2, _) -> f p1; f p2
| Tpat_lazy p -> f p
@@ -170,14 +380,14 @@ let iter_pattern_desc f = function
let map_pattern_desc f d =
match d with
- | Tpat_alias (p1, id) ->
- Tpat_alias (f p1, id)
+ | Tpat_alias (p1, id, s) ->
+ Tpat_alias (f p1, id, s)
| Tpat_tuple pats ->
Tpat_tuple (List.map f pats)
- | Tpat_record lpats ->
- Tpat_record (List.map (fun (l,p) -> l, f p) lpats)
- | Tpat_construct (c,pats) ->
- Tpat_construct (c, List.map f pats)
+ | Tpat_record (lpats, closed) ->
+ Tpat_record (List.map (fun ( lid, lid_loc, l,p) -> lid, lid_loc, l, f p) lpats, closed)
+ | Tpat_construct (lid, lid_loc, c,pats, arity) ->
+ Tpat_construct (lid, lid_loc, c, List.map f pats, arity)
| Tpat_array pats ->
Tpat_array (List.map f pats)
| Tpat_lazy p1 -> Tpat_lazy (f p1)
@@ -192,12 +402,13 @@ let map_pattern_desc f d =
(* List the identifiers bound by a pattern or a let *)
-let idents = ref([]: Ident.t list)
+let idents = ref([]: (Ident.t * string loc) list)
let rec bound_idents pat =
match pat.pat_desc with
- | Tpat_var id -> idents := id :: !idents
- | Tpat_alias(p, id) -> bound_idents p; idents := id :: !idents
+ | Tpat_var (id,s) -> idents := (id,s) :: !idents
+ | Tpat_alias(p, id, s ) ->
+ bound_idents p; idents := (id,s) :: !idents
| Tpat_or(p1, _, _) ->
(* Invariant : both arguments binds the same variables *)
bound_idents p1
@@ -206,27 +417,33 @@ let rec bound_idents pat =
let pat_bound_idents pat =
idents := []; bound_idents pat; let res = !idents in idents := []; res
-let rev_let_bound_idents pat_expr_list =
+let rev_let_bound_idents_with_loc pat_expr_list =
idents := [];
List.iter (fun (pat, expr) -> bound_idents pat) pat_expr_list;
let res = !idents in idents := []; res
-let let_bound_idents pat_expr_list =
- List.rev(rev_let_bound_idents pat_expr_list)
+let let_bound_idents_with_loc pat_expr_list =
+ List.rev(rev_let_bound_idents_with_loc pat_expr_list)
+
+let rev_let_bound_idents pat = List.map fst (rev_let_bound_idents_with_loc pat)
+let let_bound_idents pat = List.map fst (let_bound_idents_with_loc pat)
let alpha_var env id = List.assoc id env
let rec alpha_pat env p = match p.pat_desc with
-| Tpat_var id -> (* note the ``Not_found'' case *)
+| Tpat_var (id, s) -> (* note the ``Not_found'' case *)
{p with pat_desc =
- try Tpat_var (alpha_var env id) with
+ try Tpat_var (alpha_var env id, s) with
| Not_found -> Tpat_any}
-| Tpat_alias (p1, id) ->
+| Tpat_alias (p1, id, s) ->
let new_p = alpha_pat env p1 in
begin try
- {p with pat_desc = Tpat_alias (new_p, alpha_var env id)}
+ {p with pat_desc = Tpat_alias (new_p, alpha_var env id, s)}
with
| Not_found -> new_p
end
| d ->
{p with pat_desc = map_pattern_desc (alpha_pat env) d}
+
+let mkloc = Location.mkloc
+let mknoloc = Location.mknoloc
diff --git a/typing/typedtree.mli b/typing/typedtree.mli
index 0c5efa8ea..8b7671334 100644
--- a/typing/typedtree.mli
+++ b/typing/typedtree.mli
@@ -19,65 +19,78 @@ open Types
(* Value expressions for the core language *)
+type partial = Partial | Total
+type optional = Required | Optional
+
type pattern =
{ pat_desc: pattern_desc;
pat_loc: Location.t;
+ pat_extra : (pat_extra * Location.t) list;
pat_type: type_expr;
mutable pat_env: Env.t }
+and pat_extra =
+ | Tpat_constraint of core_type
+ | Tpat_type of Path.t * Longident.t loc
+ | Tpat_unpack
+
and pattern_desc =
Tpat_any
- | Tpat_var of Ident.t
- | Tpat_alias of pattern * Ident.t
+ | Tpat_var of Ident.t * string loc
+ | Tpat_alias of pattern * Ident.t * string loc
| Tpat_constant of constant
| Tpat_tuple of pattern list
- | Tpat_construct of constructor_description * pattern list
+ | Tpat_construct of Path.t * Longident.t loc * constructor_description * pattern list * bool
| Tpat_variant of label * pattern option * row_desc ref
- | Tpat_record of (label_description * pattern) list
+ | Tpat_record of ( Path.t * Longident.t loc * label_description * pattern) list * closed_flag
| Tpat_array of pattern list
| Tpat_or of pattern * pattern * row_desc option
| Tpat_lazy of pattern
-type partial = Partial | Total
-type optional = Required | Optional
-
-type expression =
+and expression =
{ exp_desc: expression_desc;
exp_loc: Location.t;
+ exp_extra : (exp_extra * Location.t) list;
exp_type: type_expr;
exp_env: Env.t }
+and exp_extra =
+ Texp_constraint of core_type option * core_type option
+ | Texp_open of Path.t * Longident.t loc * Env.t
+
and expression_desc =
- Texp_ident of Path.t * value_description
+ Texp_ident of Path.t * Longident.t loc * Types.value_description
| Texp_constant of constant
| Texp_let of rec_flag * (pattern * expression) list * expression
- | Texp_function of (pattern * expression) list * partial
- | Texp_apply of expression * (expression option * optional) list
+ | Texp_function of label * (pattern * expression) list * partial
+ | Texp_apply of expression * (label * expression option * optional) list
| Texp_match of expression * (pattern * expression) list * partial
| Texp_try of expression * (pattern * expression) list
| Texp_tuple of expression list
- | Texp_construct of constructor_description * expression list
+ | Texp_construct of Path.t * Longident.t loc * constructor_description * expression list * bool
| Texp_variant of label * expression option
- | Texp_record of (label_description * expression) list * expression option
- | Texp_field of expression * label_description
- | Texp_setfield of expression * label_description * expression
+ | Texp_record of (Path.t * Longident.t loc * label_description * expression) list * expression option
+ | Texp_field of expression * Path.t * Longident.t loc * label_description
+ | Texp_setfield of expression * Path.t * Longident.t loc * label_description * expression
| Texp_array of expression list
| Texp_ifthenelse of expression * expression * expression option
| Texp_sequence of expression * expression
| Texp_while of expression * expression
| Texp_for of
- Ident.t * expression * expression * direction_flag * expression
+ Ident.t * string loc * expression * expression * direction_flag * expression
| Texp_when of expression * expression
- | Texp_send of expression * meth
- | Texp_new of Path.t * class_declaration
- | Texp_instvar of Path.t * Path.t
- | Texp_setinstvar of Path.t * Path.t * expression
- | Texp_override of Path.t * (Path.t * expression) list
- | Texp_letmodule of Ident.t * module_expr * expression
+ | Texp_send of expression * meth * expression option
+ | Texp_new of Path.t * Longident.t loc * Types.class_declaration
+ | Texp_instvar of Path.t * Path.t * string loc
+ | Texp_setinstvar of Path.t * Path.t * string loc * expression
+ | Texp_override of Path.t * (Path.t * string loc * expression) list
+ | Texp_letmodule of Ident.t * string loc * module_expr * expression
| Texp_assert of expression
| Texp_assertfalse
| Texp_lazy of expression
- | Texp_object of class_structure * class_signature * string list
+ | Texp_poly of expression * core_type option
+ | Texp_object of class_structure * string list
+ | Texp_newtype of string * expression
| Texp_pack of module_expr
and meth =
@@ -89,63 +102,92 @@ and meth =
and class_expr =
{ cl_desc: class_expr_desc;
cl_loc: Location.t;
- cl_type: class_type;
+ cl_type: Types.class_type;
cl_env: Env.t }
and class_expr_desc =
- Tclass_ident of Path.t
- | Tclass_structure of class_structure
- | Tclass_fun of pattern * (Ident.t * expression) list * class_expr * partial
- | Tclass_apply of class_expr * (expression option * optional) list
- | Tclass_let of rec_flag * (pattern * expression) list *
- (Ident.t * expression) list * class_expr
- | Tclass_constraint of class_expr * string list * string list * Concr.t
+ Tcl_ident of Path.t * Longident.t loc * core_type list
+ | Tcl_structure of class_structure
+ | Tcl_fun of label * pattern * (Ident.t * string loc * expression) list * class_expr * partial
+ | Tcl_apply of class_expr * (label * expression option * optional) list
+ | Tcl_let of rec_flag * (pattern * expression) list *
+ (Ident.t * string loc * expression) list * class_expr
+ | Tcl_constraint of class_expr * class_type option * string list * string list * Concr.t
(* Visible instance variables, methods and concretes methods *)
and class_structure =
- { cl_field: class_field list;
- cl_meths: Ident.t Meths.t }
+ {
+ cstr_pat : pattern;
+ cstr_fields: class_field list;
+ cstr_type : Types.class_signature;
+ cstr_meths: Ident.t Meths.t }
and class_field =
- Cf_inher of class_expr * (string * Ident.t) list * (string * Ident.t) list
+ {
+ cf_desc : class_field_desc;
+ cf_loc : Location.t;
+ }
+
+and class_field_kind =
+ Tcfk_virtual of core_type
+| Tcfk_concrete of expression
+
+and class_field_desc =
+ Tcf_inher of override_flag * class_expr * string option * (string * Ident.t) list * (string * Ident.t) list
(* Inherited instance variables and concrete methods *)
- | Cf_val of string * Ident.t * expression option * bool
+ | Tcf_val of string * string loc * mutable_flag * Ident.t * class_field_kind * bool
(* None = virtual, true = override *)
- | Cf_meth of string * expression
- | Cf_init of expression
+ | Tcf_meth of string * string loc * private_flag * class_field_kind * bool
+ | Tcf_constr of core_type * core_type
+(* | Tcf_let of rec_flag * (pattern * expression) list *
+ (Ident.t * string loc * expression) list *)
+ | Tcf_init of expression
(* Value expressions for the module language *)
and module_expr =
{ mod_desc: module_expr_desc;
mod_loc: Location.t;
- mod_type: module_type;
+ mod_type: Types.module_type;
mod_env: Env.t }
+and module_type_constraint =
+ Tmodtype_implicit
+| Tmodtype_explicit of module_type
+
and module_expr_desc =
- Tmod_ident of Path.t
+ Tmod_ident of Path.t * Longident.t loc
| Tmod_structure of structure
- | Tmod_functor of Ident.t * module_type * module_expr
+ | Tmod_functor of Ident.t * string loc * module_type * module_expr
| Tmod_apply of module_expr * module_expr * module_coercion
- | Tmod_constraint of module_expr * module_type * module_coercion
- | Tmod_unpack of expression * module_type
+ | Tmod_constraint of module_expr * Types.module_type * module_type_constraint * module_coercion
+ | Tmod_unpack of expression * Types.module_type
-and structure = structure_item list
+and structure = {
+ str_items : structure_item list;
+ str_type : Types.signature;
+ str_final_env : Env.t;
+}
and structure_item =
+ { str_desc : structure_item_desc;
+ str_loc : Location.t;
+ str_env : Env.t
+ }
+
+and structure_item_desc =
Tstr_eval of expression
| Tstr_value of rec_flag * (pattern * expression) list
- | Tstr_primitive of Ident.t * value_description
- | Tstr_type of (Ident.t * type_declaration) list
- | Tstr_exception of Ident.t * exception_declaration
- | Tstr_exn_rebind of Ident.t * Path.t
- | Tstr_module of Ident.t * module_expr
- | Tstr_recmodule of (Ident.t * module_expr) list
- | Tstr_modtype of Ident.t * module_type
- | Tstr_open of Path.t
- | Tstr_class of
- (Ident.t * int * string list * class_expr * virtual_flag) list
- | Tstr_cltype of (Ident.t * cltype_declaration) list
+ | Tstr_primitive of Ident.t * string loc * value_description
+ | Tstr_type of (Ident.t * string loc * type_declaration) list
+ | Tstr_exception of Ident.t * string loc * exception_declaration
+ | Tstr_exn_rebind of Ident.t * string loc * Path.t * Longident.t loc
+ | Tstr_module of Ident.t * string loc * module_expr
+ | Tstr_recmodule of (Ident.t * string loc * module_type * module_expr) list
+ | Tstr_modtype of Ident.t * string loc * module_type
+ | Tstr_open of Path.t * Longident.t loc
+ | Tstr_class of (class_declaration * string list * virtual_flag) list
+ | Tstr_class_type of (Ident.t * string loc * class_type_declaration) list
| Tstr_include of module_expr * Ident.t list
and module_coercion =
@@ -154,6 +196,172 @@ and module_coercion =
| Tcoerce_functor of module_coercion * module_coercion
| Tcoerce_primitive of Primitive.description
+and module_type =
+ { mty_desc: module_type_desc;
+ mty_type : Types.module_type;
+ mty_env : Env.t;
+ mty_loc: Location.t }
+
+and module_type_desc =
+ Tmty_ident of Path.t * Longident.t loc
+ | Tmty_signature of signature
+ | Tmty_functor of Ident.t * string loc * module_type * module_type
+ | Tmty_with of module_type * (Path.t * Longident.t loc * with_constraint) list
+ | Tmty_typeof of module_expr
+
+and signature = {
+ sig_items : signature_item list;
+ sig_type : Types.signature;
+ sig_final_env : Env.t;
+}
+
+and signature_item =
+ { sig_desc: signature_item_desc;
+ sig_env : Env.t; (* BINANNOT ADDED *)
+ sig_loc: Location.t }
+
+and signature_item_desc =
+ Tsig_value of Ident.t * string loc * value_description
+ | Tsig_type of (Ident.t * string loc * type_declaration) list
+ | Tsig_exception of Ident.t * string loc * exception_declaration
+ | Tsig_module of Ident.t * string loc * module_type
+ | Tsig_recmodule of (Ident.t * string loc * module_type) list
+ | Tsig_modtype of Ident.t * string loc * modtype_declaration
+ | Tsig_open of Path.t * Longident.t loc
+ | Tsig_include of module_type * Types.signature
+ | Tsig_class of class_description list
+ | Tsig_class_type of class_type_declaration list
+
+and modtype_declaration =
+ Tmodtype_abstract
+ | Tmodtype_manifest of module_type
+
+and with_constraint =
+ Twith_type of type_declaration
+ | Twith_module of Path.t * Longident.t loc
+ | Twith_typesubst of type_declaration
+ | Twith_modsubst of Path.t * Longident.t loc
+
+and core_type =
+(* mutable because of [Typeclass.declare_method] *)
+ { mutable ctyp_desc : core_type_desc;
+ mutable ctyp_type : type_expr;
+ ctyp_env : Env.t; (* BINANNOT ADDED *)
+ ctyp_loc : Location.t }
+
+and core_type_desc =
+ Ttyp_any
+ | Ttyp_var of string
+ | Ttyp_arrow of label * core_type * core_type
+ | Ttyp_tuple of core_type list
+ | Ttyp_constr of Path.t * Longident.t loc * core_type list
+ | Ttyp_object of core_field_type list
+ | Ttyp_class of Path.t * Longident.t loc * core_type list * label list
+ | Ttyp_alias of core_type * string
+ | Ttyp_variant of row_field list * bool * label list option
+ | Ttyp_poly of string list * core_type
+ | Ttyp_package of package_type
+
+and package_type = {
+ pack_name : Path.t;
+ pack_fields : (Longident.t loc * core_type) list;
+ pack_type : Types.module_type;
+ pack_txt : Longident.t loc;
+}
+
+and core_field_type =
+ { field_desc: core_field_desc;
+ field_loc: Location.t }
+
+and core_field_desc =
+ Tcfield of string * core_type
+ | Tcfield_var
+
+and row_field =
+ Ttag of label * bool * core_type list
+ | Tinherit of core_type
+
+and value_description =
+ { val_desc : core_type;
+ val_val : Types.value_description;
+ val_prim : string list;
+ val_loc : Location.t;
+ }
+
+and type_declaration =
+ { typ_params: string loc option list;
+ typ_type : Types.type_declaration;
+ typ_cstrs: (core_type * core_type * Location.t) list;
+ typ_kind: type_kind;
+ typ_private: private_flag;
+ typ_manifest: core_type option;
+ typ_variance: (bool * bool) list;
+ typ_loc: Location.t }
+
+and type_kind =
+ Ttype_abstract
+ | Ttype_variant of (Ident.t * string loc * core_type list * Location.t) list
+ | Ttype_record of
+ (Ident.t * string loc * mutable_flag * core_type * Location.t) list
+
+and exception_declaration =
+ { exn_params : core_type list;
+ exn_exn : Types.exception_declaration;
+ exn_loc : Location.t }
+
+and class_type =
+ { cltyp_desc: class_type_desc;
+ cltyp_type : Types.class_type;
+ cltyp_env : Env.t; (* BINANNOT ADDED *)
+ cltyp_loc: Location.t }
+
+and class_type_desc =
+ Tcty_constr of Path.t * Longident.t loc * core_type list
+ | Tcty_signature of class_signature
+ | Tcty_fun of label * core_type * class_type
+
+and class_signature = {
+ csig_self : core_type;
+ csig_fields : class_type_field list;
+ csig_type : Types.class_signature;
+ csig_loc : Location.t;
+ }
+
+and class_type_field = {
+ ctf_desc : class_type_field_desc;
+ ctf_loc : Location.t;
+ }
+
+and class_type_field_desc =
+ Tctf_inher of class_type
+ | Tctf_val of (string * mutable_flag * virtual_flag * core_type)
+ | Tctf_virt of (string * private_flag * core_type)
+ | Tctf_meth of (string * private_flag * core_type)
+ | Tctf_cstr of (core_type * core_type)
+
+and class_declaration =
+ class_expr class_infos
+
+and class_description =
+ class_type class_infos
+
+and class_type_declaration =
+ class_type class_infos
+
+and 'a class_infos =
+ { ci_virt: virtual_flag;
+ ci_params: string loc list * Location.t;
+ ci_id_name : string loc;
+ ci_id_class: Ident.t;
+ ci_id_class_type : Ident.t;
+ ci_id_object : Ident.t;
+ ci_id_typesharp : Ident.t;
+ ci_expr: 'a;
+ ci_decl: Types.class_declaration;
+ ci_type_decl : Types.class_type_declaration;
+ ci_variance: (bool * bool) list;
+ ci_loc: Location.t }
+
(* Auxiliary functions over the a.s.t. *)
val iter_pattern_desc : (pattern -> unit) -> pattern_desc -> unit
@@ -163,5 +371,13 @@ val let_bound_idents: (pattern * expression) list -> Ident.t list
val rev_let_bound_idents: (pattern * expression) list -> Ident.t list
val pat_bound_idents: pattern -> Ident.t list
+val let_bound_idents_with_loc: (pattern * expression) list -> (Ident.t * string loc) list
+val rev_let_bound_idents_with_loc: (pattern * expression) list -> (Ident.t * string loc) list
+
(* Alpha conversion of patterns *)
val alpha_pat : (Ident.t * Ident.t) list -> pattern -> pattern
+
+val mknoloc : 'a -> 'a Asttypes.loc
+val mkloc : 'a -> Location.t -> 'a Asttypes.loc
+
+val pat_bound_idents : pattern -> (Ident.t * string Asttypes.loc) list
diff --git a/typing/typemod.ml b/typing/typemod.ml
index 0a3f24e28..f2eca2602 100644
--- a/typing/typemod.ml
+++ b/typing/typemod.ml
@@ -12,15 +12,12 @@
(* $Id$ *)
-(* Type-checking of the module language *)
-
open Misc
open Longident
open Path
open Asttypes
open Parsetree
open Types
-open Typedtree
open Format
type error =
@@ -45,24 +42,34 @@ type error =
exception Error of Location.t * error
+open Typedtree
+
+let fst3 (x,_,_) = x
+
+let rec path_concat head p =
+ match p with
+ Pident tail -> Pdot (Pident head, Ident.name tail, 0)
+ | Pdot (pre, s, pos) -> Pdot (path_concat head pre, s, pos)
+ | Papply _ -> assert false
+
(* Extract a signature from a module type *)
let extract_sig env loc mty =
match Mtype.scrape env mty with
- Tmty_signature sg -> sg
+ Mty_signature sg -> sg
| _ -> raise(Error(loc, Signature_expected))
let extract_sig_open env loc mty =
match Mtype.scrape env mty with
- Tmty_signature sg -> sg
+ Mty_signature sg -> sg
| _ -> raise(Error(loc, Structure_expected mty))
(* Compute the environment after opening a module *)
let type_open env loc lid =
- let (path, mty) = Typetexp.find_module env loc lid in
+ let (path, mty) = Typetexp.find_module env loc lid.txt in
let sg = extract_sig_open env loc mty in
- Env.open_signature ~loc path sg env
+ path, Env.open_signature ~loc path sg env
(* Record a module type *)
let rm node =
@@ -70,14 +77,14 @@ let rm node =
node
(* Forward declaration, to be filled in by type_module_type_of *)
-let type_module_type_of_fwd
- : (Env.t -> Parsetree.module_expr -> module_type) ref
+let type_module_type_of_fwd
+ : (Env.t -> Parsetree.module_expr -> Typedtree.module_expr * Types.module_type) ref
= ref (fun env m -> assert false)
(* Merge one "with" constraint in a signature *)
let rec add_rec_types env = function
- Tsig_type(id, decl, Trec_next) :: rem ->
+ Sig_type(id, decl, Trec_next) :: rem ->
add_rec_types (Env.add_type id decl env) rem
| _ -> env
@@ -97,20 +104,24 @@ let wrap_param s = {ptyp_desc=Ptyp_var s; ptyp_loc=Location.none}
let make_next_first rs rem =
if rs = Trec_first then
match rem with
- Tsig_type (id, decl, Trec_next) :: rem ->
- Tsig_type (id, decl, Trec_first) :: rem
- | Tsig_module (id, mty, Trec_next) :: rem ->
- Tsig_module (id, mty, Trec_first) :: rem
+ Sig_type (id, decl, Trec_next) :: rem ->
+ Sig_type (id, decl, Trec_first) :: rem
+ | Sig_module (id, mty, Trec_next) :: rem ->
+ Sig_module (id, mty, Trec_first) :: rem
| _ -> rem
else rem
-let merge_constraint initial_env loc sg lid constr =
+let sig_item desc typ env loc = {
+ Typedtree.sig_desc = desc; sig_loc = loc; sig_env = env
+}
+
+let merge_constraint initial_env loc sg lid constr =
let real_id = ref None in
let rec merge env sg namelist row_id =
match (sg, namelist, constr) with
([], _, _) ->
- raise(Error(loc, With_no_component lid))
- | (Tsig_type(id, decl, rs) :: rem, [s],
+ raise(Error(loc, With_no_component lid.txt))
+ | (Sig_type(id, decl, rs) :: rem, [s],
Pwith_type ({ptype_kind = Ptype_abstract} as sdecl))
when Ident.name id = s && Typedecl.is_fixed_type sdecl ->
let decl_row =
@@ -127,51 +138,64 @@ let merge_constraint initial_env loc sg lid constr =
type_newtype_level = None }
and id_row = Ident.create (s^"#row") in
let initial_env = Env.add_type id_row decl_row initial_env in
- let newdecl = Typedecl.transl_with_constraint
+ let tdecl = Typedecl.transl_with_constraint
initial_env id (Some(Pident id_row)) decl sdecl in
+ let newdecl = tdecl.typ_type in
check_type_decl env id row_id newdecl decl rs rem;
let decl_row = {decl_row with type_params = newdecl.type_params} in
let rs' = if rs = Trec_first then Trec_not else rs in
- Tsig_type(id_row, decl_row, rs') :: Tsig_type(id, newdecl, rs) :: rem
- | (Tsig_type(id, decl, rs) :: rem, [s], Pwith_type sdecl)
+ (Pident id, lid, Twith_type tdecl),
+ Sig_type(id_row, decl_row, rs') :: Sig_type(id, newdecl, rs) :: rem
+ | (Sig_type(id, decl, rs) :: rem , [s], Pwith_type sdecl)
when Ident.name id = s ->
- let newdecl =
+ let tdecl =
Typedecl.transl_with_constraint initial_env id None decl sdecl in
+ let newdecl = tdecl.typ_type in
check_type_decl env id row_id newdecl decl rs rem;
- Tsig_type(id, newdecl, rs) :: rem
- | (Tsig_type(id, decl, rs) :: rem, [s], (Pwith_type _ | Pwith_typesubst _))
+ (Pident id, lid, Twith_type tdecl), Sig_type(id, newdecl, rs) :: rem
+ | (Sig_type(id, decl, rs) :: rem, [s], (Pwith_type _ | Pwith_typesubst _))
when Ident.name id = s ^ "#row" ->
merge env rem namelist (Some id)
- | (Tsig_type(id, decl, rs) :: rem, [s], Pwith_typesubst sdecl)
+ | (Sig_type(id, decl, rs) :: rem, [s], Pwith_typesubst sdecl)
when Ident.name id = s ->
(* Check as for a normal with constraint, but discard definition *)
- let newdecl =
+ let tdecl =
Typedecl.transl_with_constraint initial_env id None decl sdecl in
+ let newdecl = tdecl.typ_type in
check_type_decl env id row_id newdecl decl rs rem;
real_id := Some id;
+ (Pident id, lid, Twith_typesubst tdecl),
make_next_first rs rem
- | (Tsig_module(id, mty, rs) :: rem, [s], Pwith_module lid)
+ | (Sig_module(id, mty, rs) :: rem, [s], Pwith_module (lid))
when Ident.name id = s ->
- let (path, mty') = Typetexp.find_module initial_env loc lid in
+ let (path, mty') = Typetexp.find_module initial_env loc lid.txt in
let newmty = Mtype.strengthen env mty' path in
ignore(Includemod.modtypes env newmty mty);
- Tsig_module(id, newmty, rs) :: rem
- | (Tsig_module(id, mty, rs) :: rem, [s], Pwith_modsubst lid)
+ (Pident id, lid, Twith_module (path, lid)),
+ Sig_module(id, newmty, rs) :: rem
+ | (Sig_module(id, mty, rs) :: rem, [s], Pwith_modsubst (lid))
when Ident.name id = s ->
- let (path, mty') = Typetexp.find_module initial_env loc lid in
+ let (path, mty') = Typetexp.find_module initial_env loc lid.txt in
let newmty = Mtype.strengthen env mty' path in
ignore(Includemod.modtypes env newmty mty);
real_id := Some id;
+ (Pident id, lid, Twith_modsubst (path, lid)),
make_next_first rs rem
- | (Tsig_module(id, mty, rs) :: rem, s :: namelist, _)
+ | (Sig_module(id, mty, rs) :: rem, s :: namelist, _)
when Ident.name id = s ->
- let newsg = merge env (extract_sig env loc mty) namelist None in
- Tsig_module(id, Tmty_signature newsg, rs) :: rem
+ let ((path, path_loc, tcstr), newsg) =
+ merge env (extract_sig env loc mty) namelist None in
+ (path_concat id path, lid, tcstr),
+ Sig_module(id, Mty_signature newsg, rs) :: rem
| (item :: rem, _, _) ->
- item :: merge (Env.add_item item env) rem namelist row_id in
+ let (cstr, items) = merge (Env.add_item item env) rem namelist row_id
+ in
+ cstr, item :: items
+ in
try
- let names = Longident.flatten lid in
- let sg = merge initial_env sg names None in
+ let names = Longident.flatten lid.txt in
+ let (tcstr, sg) = merge initial_env sg names None in
+ let sg =
match names, constr with
[s], Pwith_typesubst sdecl ->
let id =
@@ -183,27 +207,32 @@ let merge_constraint initial_env loc sg lid constr =
List.map
(function {ptyp_desc=Ptyp_var s} -> s | _ -> raise Exit)
stl in
- if List.map (fun x -> Some x) params <> sdecl.ptype_params
- then raise Exit;
+ List.iter2 (fun x ox ->
+ match ox with
+ Some y when x = y.txt -> ()
+ | _ -> raise Exit
+ ) params sdecl.ptype_params;
lid
| _ -> raise Exit
with Exit -> raise (Error (sdecl.ptype_loc, With_need_typeconstr))
in
let (path, _) =
- try Env.lookup_type lid initial_env with Not_found -> assert false
+ try Env.lookup_type lid.txt initial_env with Not_found -> assert false
in
let sub = Subst.add_type id path Subst.identity in
Subst.signature sub sg
- | [s], Pwith_modsubst lid ->
+ | [s], Pwith_modsubst (lid) ->
let id =
match !real_id with None -> assert false | Some id -> id in
- let (path, _) = Typetexp.find_module initial_env loc lid in
+ let (path, _) = Typetexp.find_module initial_env loc lid.txt in
let sub = Subst.add_module id path Subst.identity in
Subst.signature sub sg
| _ ->
- sg
+ sg
+ in
+ (tcstr, sg)
with Includemod.Error explanation ->
- raise(Error(loc, With_mismatch(lid, explanation)))
+ raise(Error(loc, With_mismatch(lid.txt, explanation)))
(* Add recursion flags on declarations arising from a mutually recursive
block. *)
@@ -219,6 +248,12 @@ let rec map_rec' fn decls rem =
fn Trec_not d1 :: map_rec' fn dl rem
| _ -> map_rec fn decls rem
+let rec map_rec'' fn decls rem =
+ match decls with
+ | (id, _,_ as d1) :: dl when Btype.is_row_name (Ident.name id) ->
+ fn Trec_not d1 :: map_rec'' fn dl rem
+ | _ -> map_rec fn decls rem
+
(* Auxiliary for translating recursively-defined module types.
Return a module type that approximates the shape of the given module
type AST. Retain only module, type, and module type
@@ -228,19 +263,20 @@ let rec map_rec' fn decls rem =
let rec approx_modtype env smty =
match smty.pmty_desc with
Pmty_ident lid ->
- let (path, info) = Typetexp.find_modtype env smty.pmty_loc lid in
- Tmty_ident path
+ let (path, info) = Typetexp.find_modtype env smty.pmty_loc lid.txt in
+ Mty_ident path
| Pmty_signature ssg ->
- Tmty_signature(approx_sig env ssg)
+ Mty_signature(approx_sig env ssg)
| Pmty_functor(param, sarg, sres) ->
let arg = approx_modtype env sarg in
- let (id, newenv) = Env.enter_module param arg env in
+ let (id, newenv) = Env.enter_module param.txt arg env in
let res = approx_modtype newenv sres in
- Tmty_functor(id, arg, res)
+ Mty_functor(id, arg, res)
| Pmty_with(sbody, constraints) ->
approx_modtype env sbody
| Pmty_typeof smod ->
- !type_module_type_of_fwd env smod
+ let (_, mty) = !type_module_type_of_fwd env smod in
+ mty
and approx_sig env ssg =
match ssg with
@@ -250,28 +286,29 @@ and approx_sig env ssg =
| Psig_type sdecls ->
let decls = Typedecl.approx_type_decl env sdecls in
let rem = approx_sig env srem in
- map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls rem
+ map_rec' (fun rs (id, info) -> Sig_type(id, info, rs)) decls rem
| Psig_module(name, smty) ->
let mty = approx_modtype env smty in
- let (id, newenv) = Env.enter_module name mty env in
- Tsig_module(id, mty, Trec_not) :: approx_sig newenv srem
+ let (id, newenv) = Env.enter_module name.txt mty env in
+ Sig_module(id, mty, Trec_not) :: approx_sig newenv srem
| Psig_recmodule sdecls ->
let decls =
List.map
(fun (name, smty) ->
- (Ident.create name, approx_modtype env smty))
+ (Ident.create name.txt, approx_modtype env smty))
sdecls in
let newenv =
List.fold_left (fun env (id, mty) -> Env.add_module id mty env)
env decls in
- map_rec (fun rs (id, mty) -> Tsig_module(id, mty, rs)) decls
+ map_rec (fun rs (id, mty) -> Sig_module(id, mty, rs)) decls
(approx_sig newenv srem)
| Psig_modtype(name, sinfo) ->
let info = approx_modtype_info env sinfo in
- let (id, newenv) = Env.enter_modtype name info env in
- Tsig_modtype(id, info) :: approx_sig newenv srem
+ let (id, newenv) = Env.enter_modtype name.txt info env in
+ Sig_modtype(id, info) :: approx_sig newenv srem
| Psig_open lid ->
- approx_sig (type_open env item.psig_loc lid) srem
+ let (path, mty) = type_open env item.psig_loc lid in
+ approx_sig mty srem
| Psig_include smty ->
let mty = approx_modtype env smty in
let sg = Subst.signature Subst.identity
@@ -283,10 +320,10 @@ and approx_sig env ssg =
let rem = approx_sig env srem in
List.flatten
(map_rec
- (fun rs (i1, d1, i2, d2, i3, d3) ->
- [Tsig_cltype(i1, d1, rs);
- Tsig_type(i2, d2, rs);
- Tsig_type(i3, d3, rs)])
+ (fun rs (i1, _, d1, i2, d2, i3, d3, _) ->
+ [Sig_class_type(i1, d1, rs);
+ Sig_type(i2, d2, rs);
+ Sig_type(i3, d3, rs)])
decls [rem])
| _ ->
approx_sig env srem
@@ -294,17 +331,18 @@ and approx_sig env ssg =
and approx_modtype_info env sinfo =
match sinfo with
Pmodtype_abstract ->
- Tmodtype_abstract
+ Modtype_abstract
| Pmodtype_manifest smty ->
- Tmodtype_manifest(approx_modtype env smty)
+ Modtype_manifest(approx_modtype env smty)
(* Additional validity checks on type definitions arising from
recursive modules *)
let check_recmod_typedecls env sdecls decls =
- let recmod_ids = List.map fst decls in
+ let recmod_ids = List.map fst3 decls in
List.iter2
- (fun (_, smty) (id, mty) ->
+ (fun (_, smty) (id, _, mty) ->
+ let mty = mty.mty_type in
List.iter
(fun path ->
Typedecl.check_recmod_typedecl env smty.pmty_loc recmod_ids
@@ -322,23 +360,23 @@ let check cl loc set_ref name =
else set_ref := StringSet.add name !set_ref
let check_sig_item type_names module_names modtype_names loc = function
- Tsig_type(id, _, _) ->
+ Sig_type(id, _, _) ->
check "type" loc type_names (Ident.name id)
- | Tsig_module(id, _, _) ->
+ | Sig_module(id, _, _) ->
check "module" loc module_names (Ident.name id)
- | Tsig_modtype(id, _) ->
+ | Sig_modtype(id, _) ->
check "module type" loc modtype_names (Ident.name id)
| _ -> ()
let rec remove_values ids = function
[] -> []
- | Tsig_value (id, _) :: rem
+ | Sig_value (id, _) :: rem
when List.exists (Ident.equal id) ids -> remove_values ids rem
| f :: rem -> f :: remove_values ids rem
let rec get_values = function
[] -> []
- | Tsig_value (id, _) :: rem -> id :: get_values rem
+ | Sig_value (id, _) :: rem -> id :: get_values rem
| f :: rem -> get_values rem
(* Check and translate a module type expression *)
@@ -347,28 +385,55 @@ let transl_modtype_longident loc env lid =
let (path, info) = Typetexp.find_modtype env loc lid in
path
+let mkmty desc typ env loc =
+ let mty = {
+ mty_desc = desc;
+ mty_type = typ;
+ mty_loc = loc;
+ mty_env = env;
+ } in
+ Cmt_format.add_saved_type (Cmt_format.Partial_module_type mty);
+ mty
+
+let mksig desc env loc =
+ let sg = { sig_desc = desc; sig_loc = loc; sig_env = env } in
+ Cmt_format.add_saved_type (Cmt_format.Partial_signature_item sg);
+ sg
+
+(* let signature sg = List.map (fun item -> item.sig_type) sg *)
+
let rec transl_modtype env smty =
+ let loc = smty.pmty_loc in
match smty.pmty_desc with
Pmty_ident lid ->
- Tmty_ident (transl_modtype_longident smty.pmty_loc env lid)
+ let path = transl_modtype_longident loc env lid.txt in
+ mkmty (Tmty_ident (path, lid)) (Mty_ident path) env loc
| Pmty_signature ssg ->
- Tmty_signature(transl_signature env ssg)
+ let sg = transl_signature env ssg in
+ mkmty (Tmty_signature sg) (Mty_signature sg.sig_type) env loc
| Pmty_functor(param, sarg, sres) ->
let arg = transl_modtype env sarg in
- let (id, newenv) = Env.enter_module param arg env in
+ let (id, newenv) = Env.enter_module param.txt arg.mty_type env in
let res = transl_modtype newenv sres in
- Tmty_functor(id, arg, res)
+ mkmty (Tmty_functor (id, param, arg, res))
+ (Mty_functor(id, arg.mty_type, res.mty_type)) env loc
| Pmty_with(sbody, constraints) ->
let body = transl_modtype env sbody in
- let init_sg = extract_sig env sbody.pmty_loc body in
- let final_sg =
+ let init_sg = extract_sig env sbody.pmty_loc body.mty_type in
+ let (tcstrs, final_sg) =
List.fold_left
- (fun sg (lid, sdecl) ->
- merge_constraint env smty.pmty_loc sg lid sdecl)
- init_sg constraints in
- Mtype.freshen (Tmty_signature final_sg)
+ (fun (tcstrs,sg) (lid, sdecl) ->
+ let (tcstr, sg) = merge_constraint env smty.pmty_loc sg lid sdecl
+ in
+ (tcstr :: tcstrs, sg)
+ )
+ ([],init_sg) constraints in
+ mkmty (Tmty_with ( body, tcstrs))
+ (Mtype.freshen (Mty_signature final_sg)) env loc
| Pmty_typeof smod ->
- !type_module_type_of_fwd env smod
+ let tmty, mty = !type_module_type_of_fwd env smod in
+ mkmty (Tmty_typeof tmty) mty env loc
+
and transl_signature env sg =
let type_names = ref StringSet.empty
@@ -377,52 +442,71 @@ and transl_signature env sg =
let rec transl_sig env sg =
Ctype.init_def(Ident.current_time());
match sg with
- [] -> []
+ [] -> [], [], env
| item :: srem ->
+ let loc = item.psig_loc in
match item.psig_desc with
| Psig_value(name, sdesc) ->
- let desc = Typedecl.transl_value_decl env item.psig_loc sdesc in
- let (id, newenv) = Env.enter_value ~check:(fun s -> Warnings.Unused_value_declaration s) name desc env in
- let rem = transl_sig newenv srem in
- if List.exists (Ident.equal id) (get_values rem) then rem
- else Tsig_value(id, desc) :: rem
+ let tdesc = Typedecl.transl_value_decl env item.psig_loc sdesc in
+ let desc = tdesc.val_val in
+ let (id, newenv) = Env.enter_value ~check:(fun s -> Warnings.Unused_value_declaration s) name.txt desc env in
+ let (trem,rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_value (id, name, tdesc)) env loc :: trem,
+ (if List.exists (Ident.equal id) (get_values rem) then rem
+ else Sig_value(id, desc) :: rem),
+ final_env
| Psig_type sdecls ->
List.iter
- (fun (name, decl) -> check "type" item.psig_loc type_names name)
+ (fun (name, decl) -> check "type" item.psig_loc type_names name.txt)
sdecls;
let (decls, newenv) = Typedecl.transl_type_decl env sdecls in
- let rem = transl_sig newenv srem in
- map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls rem
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_type decls) env loc :: trem,
+ map_rec'' (fun rs (id, _, info) ->
+ Sig_type(id, info.typ_type, rs)) decls rem,
+ final_env
| Psig_exception(name, sarg) ->
let arg = Typedecl.transl_exception env item.psig_loc sarg in
- let (id, newenv) = Env.enter_exception name arg env in
- let rem = transl_sig newenv srem in
- Tsig_exception(id, arg) :: rem
+ let (id, newenv) = Env.enter_exception name.txt arg.exn_exn env in
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_exception (id, name, arg)) env loc :: trem,
+ Sig_exception(id, arg.exn_exn) :: rem,
+ final_env
| Psig_module(name, smty) ->
- check "module" item.psig_loc module_names name;
- let mty = transl_modtype env smty in
- let (id, newenv) = Env.enter_module name mty env in
- let rem = transl_sig newenv srem in
- Tsig_module(id, mty, Trec_not) :: rem
+ check "module" item.psig_loc module_names name.txt;
+ let tmty = transl_modtype env smty in
+ let mty = tmty.mty_type in
+ let (id, newenv) = Env.enter_module name.txt mty env in
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_module (id, name, tmty)) env loc :: trem,
+ Sig_module(id, mty, Trec_not) :: rem,
+ final_env
| Psig_recmodule sdecls ->
List.iter
(fun (name, smty) ->
- check "module" item.psig_loc module_names name)
+ check "module" item.psig_loc module_names name.txt)
sdecls;
let (decls, newenv) =
transl_recmodule_modtypes item.psig_loc env sdecls in
- let rem = transl_sig newenv srem in
- map_rec (fun rs (id, mty) -> Tsig_module(id, mty, rs)) decls rem
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_recmodule decls) env loc :: trem,
+ map_rec (fun rs (id, _, tmty) -> Sig_module(id, tmty.mty_type, rs)) decls rem,
+ final_env
| Psig_modtype(name, sinfo) ->
- check "module type" item.psig_loc modtype_names name;
- let info = transl_modtype_info env sinfo in
- let (id, newenv) = Env.enter_modtype name info env in
- let rem = transl_sig newenv srem in
- Tsig_modtype(id, info) :: rem
+ check "module type" item.psig_loc modtype_names name.txt;
+ let (tinfo, info) = transl_modtype_info env sinfo in
+ let (id, newenv) = Env.enter_modtype name.txt info env in
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_modtype (id, name, tinfo)) env loc :: trem,
+ Sig_modtype(id, info) :: rem,
+ final_env
| Psig_open lid ->
- transl_sig (type_open env item.psig_loc lid) srem
+ let (path, newenv) = type_open env item.psig_loc lid in
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_open (path,lid)) env loc :: trem, rem, final_env
| Psig_include smty ->
- let mty = transl_modtype env smty in
+ let tmty = transl_modtype env smty in
+ let mty = tmty.mty_type in
let sg = Subst.signature Subst.identity
(extract_sig env smty.pmty_loc mty) in
List.iter
@@ -430,63 +514,84 @@ and transl_signature env sg =
item.psig_loc)
sg;
let newenv = Env.add_signature sg env in
- let rem = transl_sig newenv srem in
- remove_values (get_values rem) sg @ rem
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_include (tmty, sg)) env loc :: trem,
+ remove_values (get_values rem) sg @ rem, final_env
| Psig_class cl ->
List.iter
(fun {pci_name = name} ->
- check "type" item.psig_loc type_names name)
+ check "type" item.psig_loc type_names name.txt )
cl;
let (classes, newenv) = Typeclass.class_descriptions env cl in
- let rem = transl_sig newenv srem in
- List.flatten
- (map_rec
- (fun rs (i, d, i', d', i'', d'', i''', d''', _, _, _) ->
- [Tsig_class(i, d, rs);
- Tsig_cltype(i', d', rs);
- Tsig_type(i'', d'', rs);
- Tsig_type(i''', d''', rs)])
- classes [rem])
+ let (trem, rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_class (List.map2 (fun pcl tcl ->
+ let (_, _, _, _, _, _, _, _, _, _, _, tcl) = tcl in
+ tcl
+ ) cl classes)) env loc :: trem,
+ List.flatten
+ (map_rec
+ (fun rs (i, _, d, i', d', i'', d'', i''', d''', _, _, _) ->
+ [Sig_class(i, d, rs);
+ Sig_class_type(i', d', rs);
+ Sig_type(i'', d'', rs);
+ Sig_type(i''', d''', rs)])
+ classes [rem]),
+ final_env
| Psig_class_type cl ->
List.iter
(fun {pci_name = name} ->
- check "type" item.psig_loc type_names name)
+ check "type" item.psig_loc type_names name.txt)
cl;
let (classes, newenv) = Typeclass.class_type_declarations env cl in
- let rem = transl_sig newenv srem in
+ let (trem,rem, final_env) = transl_sig newenv srem in
+ mksig (Tsig_class_type (List.map2 (fun pcl tcl ->
+ let (_, _, _, _, _, _, _, tcl) = tcl in
+ tcl
+ ) cl classes)) env loc :: trem,
List.flatten
(map_rec
- (fun rs (i, d, i', d', i'', d'') ->
- [Tsig_cltype(i, d, rs);
- Tsig_type(i', d', rs);
- Tsig_type(i'', d'', rs)])
- classes [rem])
- in transl_sig (Env.in_signature env) sg
+ (fun rs (i, _, d, i', d', i'', d'', _) ->
+ [Sig_class_type(i, d, rs);
+ Sig_type(i', d', rs);
+ Sig_type(i'', d'', rs)])
+ classes [rem]),
+ final_env
+ in
+ let previous_saved_types = Cmt_format.get_saved_types () in
+ let (trem, rem, final_env) = transl_sig (Env.in_signature env) sg in
+ let sg = { sig_items = trem; sig_type = rem; sig_final_env = final_env } in
+ Cmt_format.set_saved_types ( (Cmt_format.Partial_signature sg) :: previous_saved_types );
+ sg
and transl_modtype_info env sinfo =
match sinfo with
Pmodtype_abstract ->
- Tmodtype_abstract
+ Tmodtype_abstract, Modtype_abstract
| Pmodtype_manifest smty ->
- Tmodtype_manifest(transl_modtype env smty)
+ let tmty = transl_modtype env smty in
+ Tmodtype_manifest tmty, Modtype_manifest tmty.mty_type
and transl_recmodule_modtypes loc env sdecls =
let make_env curr =
List.fold_left
- (fun env (id, mty) -> Env.add_module id mty env)
+ (fun env (id, _, mty) -> Env.add_module id mty env)
+ env curr in
+ let make_env2 curr =
+ List.fold_left
+ (fun env (id, _, mty) -> Env.add_module id mty.mty_type env)
env curr in
let transition env_c curr =
List.map2
- (fun (_, smty) (id, mty) -> (id, transl_modtype env_c smty))
+ (fun (_, smty) (id, id_loc, mty) -> (id, id_loc, transl_modtype env_c smty))
sdecls curr in
let init =
List.map
(fun (name, smty) ->
- (Ident.create name, approx_modtype env smty))
+ (Ident.create name.txt, name, approx_modtype env smty))
sdecls in
let env0 = make_env init in
let dcl1 = transition env0 init in
- let env1 = make_env dcl1 in
+ let env1 = make_env2 dcl1 in
check_recmod_typedecls env1 sdecls dcl1;
let dcl2 = transition env1 dcl1 in
(*
@@ -495,7 +600,7 @@ and transl_recmodule_modtypes loc env sdecls =
Format.printf "%a: %a@." Printtyp.ident id Printtyp.modtype mty)
dcl2;
*)
- let env2 = make_env dcl2 in
+ let env2 = make_env2 dcl2 in
check_recmod_typedecls env2 sdecls dcl2;
(dcl2, env2)
@@ -505,7 +610,7 @@ exception Not_a_path
let rec path_of_module mexp =
match mexp.mod_desc with
- Tmod_ident p -> p
+ Tmod_ident (p,_) -> p
| Tmod_apply(funct, arg, coercion) when !Clflags.applicative_functors ->
Papply(path_of_module funct, path_of_module arg)
| _ -> raise Not_a_path
@@ -513,23 +618,24 @@ let rec path_of_module mexp =
(* Check that all core type schemes in a structure are closed *)
let rec closed_modtype = function
- Tmty_ident p -> true
- | Tmty_signature sg -> List.for_all closed_signature_item sg
- | Tmty_functor(id, param, body) -> closed_modtype body
+ Mty_ident p -> true
+ | Mty_signature sg -> List.for_all closed_signature_item sg
+ | Mty_functor(id, param, body) -> closed_modtype body
and closed_signature_item = function
- Tsig_value(id, desc) -> Ctype.closed_schema desc.val_type
- | Tsig_module(id, mty, _) -> closed_modtype mty
+ Sig_value(id, desc) -> Ctype.closed_schema desc.val_type
+ | Sig_module(id, mty, _) -> closed_modtype mty
| _ -> true
-let check_nongen_scheme env = function
+let check_nongen_scheme env str =
+ match str.str_desc with
Tstr_value(rec_flag, pat_exp_list) ->
List.iter
(fun (pat, exp) ->
if not (Ctype.closed_schema exp.exp_type) then
raise(Error(exp.exp_loc, Non_generalizable exp.exp_type)))
pat_exp_list
- | Tstr_module(id, md) ->
+ | Tstr_module(id, _, md) ->
if not (closed_modtype md.mod_type) then
raise(Error(md.mod_loc, Non_generalizable_module md.mod_type))
| _ -> ()
@@ -544,11 +650,11 @@ let check_nongen_schemes env str =
let rec bound_value_identifiers = function
[] -> []
- | Tsig_value(id, {val_kind = Val_reg}) :: rem ->
+ | Sig_value(id, {val_kind = Val_reg}) :: rem ->
id :: bound_value_identifiers rem
- | Tsig_exception(id, decl) :: rem -> id :: bound_value_identifiers rem
- | Tsig_module(id, mty, _) :: rem -> id :: bound_value_identifiers rem
- | Tsig_class(id, decl, _) :: rem -> id :: bound_value_identifiers rem
+ | Sig_exception(id, decl) :: rem -> id :: bound_value_identifiers rem
+ | Sig_module(id, mty, _) :: rem -> id :: bound_value_identifiers rem
+ | Sig_class(id, decl, _) :: rem -> id :: bound_value_identifiers rem
| _ :: rem -> bound_value_identifiers rem
(* Helpers for typing recursive modules *)
@@ -563,9 +669,9 @@ let enrich_type_decls anchor decls oldenv newenv =
None -> newenv
| Some p ->
List.fold_left
- (fun e (id, info) ->
+ (fun e (id, _, info) ->
let info' =
- Mtype.enrich_typedecl oldenv (Pdot(p, Ident.name id, nopos)) info
+ Mtype.enrich_typedecl oldenv (Pdot(p, Ident.name id, nopos)) info.typ_type
in
Env.add_type id info' e)
oldenv decls
@@ -605,7 +711,7 @@ let check_recmodule_inclusion env bindings =
(* Generate fresh names Y_i for the rec. bound module idents X_i *)
let bindings1 =
List.map
- (fun (id, mty_decl, modl, mty_actual) ->
+ (fun (id, _, mty_decl, modl, mty_actual) ->
(id, Ident.rename id, mty_actual))
bindings in
(* Enter the Y_i in the environment with their actual types substituted
@@ -630,8 +736,8 @@ let check_recmodule_inclusion env bindings =
end else begin
(* Base case: check inclusion of s(mty_actual) in s(mty_decl)
and insert coercion if needed *)
- let check_inclusion (id, mty_decl, modl, mty_actual) =
- let mty_decl' = Subst.modtype s mty_decl
+ let check_inclusion (id, id_loc, mty_decl, modl, mty_actual) =
+ let mty_decl' = Subst.modtype s mty_decl.mty_type
and mty_actual' = subst_and_strengthen env s id mty_actual in
let coercion =
try
@@ -639,11 +745,12 @@ let check_recmodule_inclusion env bindings =
with Includemod.Error msg ->
raise(Error(modl.mod_loc, Not_included msg)) in
let modl' =
- { mod_desc = Tmod_constraint(modl, mty_decl, coercion);
- mod_type = mty_decl;
+ { mod_desc = Tmod_constraint(modl, mty_decl.mty_type,
+ Tmodtype_explicit mty_decl, coercion);
+ mod_type = mty_decl.mty_type;
mod_env = env;
mod_loc = modl.mod_loc } in
- (id, modl') in
+ (id, id_loc, mty_decl, modl') in
List.map check_inclusion bindings
end
in check_incl true (List.length bindings) env Subst.identity
@@ -656,50 +763,55 @@ let rec package_constraints env loc mty constrs =
let sg' =
List.map
(function
- | Tsig_type (id, ({type_params=[]} as td), rs) when List.mem_assoc [Ident.name id] constrs ->
+ | Sig_type (id, ({type_params=[]} as td), rs) when List.mem_assoc [Ident.name id] constrs ->
let ty = List.assoc [Ident.name id] constrs in
- Tsig_type (id, {td with type_manifest = Some ty}, rs)
- | Tsig_module (id, mty, rs) ->
+ Sig_type (id, {td with type_manifest = Some ty}, rs)
+ | Sig_module (id, mty, rs) ->
let rec aux = function
| (m :: ((_ :: _) as l), t) :: rest when m = Ident.name id -> (l, t) :: aux rest
| _ :: rest -> aux rest
| [] -> []
in
- Tsig_module (id, package_constraints env loc mty (aux constrs), rs)
+ Sig_module (id, package_constraints env loc mty (aux constrs), rs)
| item -> item
)
sg
in
- Tmty_signature sg'
+ Mty_signature sg'
let modtype_of_package env loc p nl tl =
try match Env.find_modtype p env with
- | Tmodtype_manifest mty when nl <> [] ->
+ | Modtype_manifest mty when nl <> [] ->
package_constraints env loc mty (List.combine (List.map Longident.flatten nl) tl)
| _ ->
- if nl = [] then Tmty_ident p
+ if nl = [] then Mty_ident p
else raise(Error(loc, Signature_expected))
with Not_found ->
raise(Typetexp.Error(loc, Typetexp.Unbound_modtype (Ctype.lid_of_path p)))
-let wrap_constraint env arg mty =
+let wrap_constraint env arg mty explicit =
let coercion =
try
Includemod.modtypes env arg.mod_type mty
with Includemod.Error msg ->
raise(Error(arg.mod_loc, Not_included msg)) in
- { mod_desc = Tmod_constraint(arg, mty, coercion);
+ { mod_desc = Tmod_constraint(arg, mty, explicit, coercion);
mod_type = mty;
mod_env = env;
mod_loc = arg.mod_loc }
(* Type a module value expression *)
+let mkstr desc loc env =
+ let str = { str_desc = desc; str_loc = loc; str_env = env } in
+ Cmt_format.add_saved_type (Cmt_format.Partial_structure_item str);
+ str
+
let rec type_module sttn funct_body anchor env smod =
match smod.pmod_desc with
Pmod_ident lid ->
- let (path, mty) = Typetexp.find_module env smod.pmod_loc lid in
- rm { mod_desc = Tmod_ident path;
+ let (path, mty) = Typetexp.find_module env smod.pmod_loc lid.txt in
+ rm { mod_desc = Tmod_ident (path, lid);
mod_type = if sttn then Mtype.strengthen env mty path else mty;
mod_env = env;
mod_loc = smod.pmod_loc }
@@ -707,15 +819,15 @@ let rec type_module sttn funct_body anchor env smod =
let (str, sg, finalenv) =
type_structure funct_body anchor env sstr smod.pmod_loc in
rm { mod_desc = Tmod_structure str;
- mod_type = Tmty_signature sg;
+ mod_type = Mty_signature sg;
mod_env = env;
mod_loc = smod.pmod_loc }
| Pmod_functor(name, smty, sbody) ->
let mty = transl_modtype env smty in
- let (id, newenv) = Env.enter_module name mty env in
+ let (id, newenv) = Env.enter_module name.txt mty.mty_type env in
let body = type_module sttn true None newenv sbody in
- rm { mod_desc = Tmod_functor(id, mty, body);
- mod_type = Tmty_functor(id, mty, body.mod_type);
+ rm { mod_desc = Tmod_functor(id, name, mty, body);
+ mod_type = Mty_functor(id, mty.mty_type, body.mod_type);
mod_env = env;
mod_loc = smod.pmod_loc }
| Pmod_apply(sfunct, sarg) ->
@@ -724,7 +836,7 @@ let rec type_module sttn funct_body anchor env smod =
let funct =
type_module (sttn && path <> None) funct_body None env sfunct in
begin match Mtype.scrape env funct.mod_type with
- Tmty_functor(param, mty_param, mty_res) as mty_functor ->
+ Mty_functor(param, mty_param, mty_res) as mty_functor ->
let coercion =
try
Includemod.modtypes env arg.mod_type mty_param
@@ -753,7 +865,7 @@ let rec type_module sttn funct_body anchor env smod =
| Pmod_constraint(sarg, smty) ->
let arg = type_module true funct_body anchor env sarg in
let mty = transl_modtype env smty in
- rm {(wrap_constraint env arg mty) with mod_loc = smod.pmod_loc}
+ rm {(wrap_constraint env arg mty.mty_type (Tmodtype_explicit mty)) with mod_loc = smod.pmod_loc}
| Pmod_unpack sexp ->
if funct_body then
@@ -792,15 +904,19 @@ and type_structure funct_body anchor env sstr scope =
and module_names = ref StringSet.empty
and modtype_names = ref StringSet.empty in
let rec type_struct env sstr =
+ let mkstr desc loc = mkstr desc loc env in
Ctype.init_def(Ident.current_time());
match sstr with
[] ->
([], [], env)
- | {pstr_desc = Pstr_eval sexpr} :: srem ->
- let expr = Typecore.type_expression env sexpr in
- let (str_rem, sig_rem, final_env) = type_struct env srem in
- (Tstr_eval expr :: str_rem, sig_rem, final_env)
- | {pstr_desc = Pstr_value(rec_flag, sdefs); pstr_loc = loc} :: srem ->
+ | pstr :: srem ->
+ let loc = pstr.pstr_loc in
+ match pstr.pstr_desc with
+ | Pstr_eval sexpr ->
+ let expr = Typecore.type_expression env sexpr in
+ let (str_rem, sig_rem, final_env) = type_struct env srem in
+ (mkstr (Tstr_eval expr) loc :: str_rem, sig_rem, final_env)
+ | Pstr_value(rec_flag, sdefs) ->
let scope =
match rec_flag with
| Recursive -> Some (Annot.Idef {scope with
@@ -819,136 +935,141 @@ and type_structure funct_body anchor env sstr scope =
(* Note: Env.find_value does not trigger the value_used event. Values
will be marked as being used during the signature inclusion test. *)
let make_sig_value id =
- Tsig_value(id, Env.find_value (Pident id) newenv) in
- (Tstr_value(rec_flag, defs) :: str_rem,
+ Sig_value(id, Env.find_value (Pident id) newenv) in
+ (mkstr (Tstr_value(rec_flag, defs)) loc :: str_rem,
map_end make_sig_value bound_idents sig_rem,
final_env)
- | {pstr_desc = Pstr_primitive(name, sdesc); pstr_loc = loc} :: srem ->
+ | Pstr_primitive(name, sdesc) ->
let desc = Typedecl.transl_value_decl env loc sdesc in
- let (id, newenv) = Env.enter_value ~check:(fun s -> Warnings.Unused_value_declaration s) name desc env in
+ let (id, newenv) = Env.enter_value ~check:(fun s -> Warnings.Unused_value_declaration s) name.txt desc.val_val env in
let (str_rem, sig_rem, final_env) = type_struct newenv srem in
- (Tstr_primitive(id, desc) :: str_rem,
- Tsig_value(id, desc) :: sig_rem,
+ (mkstr (Tstr_primitive(id, name, desc)) loc :: str_rem,
+ Sig_value(id, desc.val_val) :: sig_rem,
final_env)
- | {pstr_desc = Pstr_type sdecls; pstr_loc = loc} :: srem ->
+ | Pstr_type sdecls ->
List.iter
- (fun (name, decl) -> check "type" loc type_names name)
+ (fun (name, decl) -> check "type" loc type_names name.txt)
sdecls;
let (decls, newenv) = Typedecl.transl_type_decl env sdecls in
let newenv' =
enrich_type_decls anchor decls env newenv in
let (str_rem, sig_rem, final_env) = type_struct newenv' srem in
- (Tstr_type decls :: str_rem,
- map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls sig_rem,
+ (mkstr (Tstr_type decls) loc :: str_rem,
+ map_rec'' (fun rs (id, _, info) -> Sig_type(id, info.typ_type, rs)) decls sig_rem,
final_env)
- | {pstr_desc = Pstr_exception(name, sarg); pstr_loc = loc} :: srem ->
+ | Pstr_exception(name, sarg) ->
let arg = Typedecl.transl_exception env loc sarg in
- let (id, newenv) = Env.enter_exception name arg env in
+ let (id, newenv) = Env.enter_exception name.txt arg.exn_exn env in
let (str_rem, sig_rem, final_env) = type_struct newenv srem in
- (Tstr_exception(id, arg) :: str_rem,
- Tsig_exception(id, arg) :: sig_rem,
+ (mkstr (Tstr_exception(id, name, arg)) loc :: str_rem,
+ Sig_exception(id, arg.exn_exn) :: sig_rem,
final_env)
- | {pstr_desc = Pstr_exn_rebind(name, longid); pstr_loc = loc} :: srem ->
- let (path, arg) = Typedecl.transl_exn_rebind env loc longid in
- let (id, newenv) = Env.enter_exception name arg env in
+ | Pstr_exn_rebind(name, longid) ->
+ let (path, arg) = Typedecl.transl_exn_rebind env loc longid.txt in
+ let (id, newenv) = Env.enter_exception name.txt arg env in
let (str_rem, sig_rem, final_env) = type_struct newenv srem in
- (Tstr_exn_rebind(id, path) :: str_rem,
- Tsig_exception(id, arg) :: sig_rem,
+ (mkstr (Tstr_exn_rebind(id, name, path, longid)) loc :: str_rem,
+ Sig_exception(id, arg) :: sig_rem,
final_env)
- | {pstr_desc = Pstr_module(name, smodl); pstr_loc = loc} :: srem ->
- check "module" loc module_names name;
+ | Pstr_module(name, smodl) ->
+ check "module" loc module_names name.txt;
let modl =
- type_module true funct_body (anchor_submodule name anchor) env
+ type_module true funct_body (anchor_submodule name.txt anchor) env
smodl in
- let mty = enrich_module_type anchor name modl.mod_type env in
- let (id, newenv) = Env.enter_module name mty env in
+ let mty = enrich_module_type anchor name.txt modl.mod_type env in
+ let (id, newenv) = Env.enter_module name.txt mty env in
let (str_rem, sig_rem, final_env) = type_struct newenv srem in
- (Tstr_module(id, modl) :: str_rem,
- Tsig_module(id, modl.mod_type, Trec_not) :: sig_rem,
+ (mkstr (Tstr_module(id, name, modl)) loc :: str_rem,
+ Sig_module(id, modl.mod_type, Trec_not) :: sig_rem,
final_env)
- | {pstr_desc = Pstr_recmodule sbind; pstr_loc = loc} :: srem ->
+ | Pstr_recmodule sbind ->
List.iter
- (fun (name, _, _) -> check "module" loc module_names name)
+ (fun (name, _, _) -> check "module" loc module_names name.txt)
sbind;
let (decls, newenv) =
transl_recmodule_modtypes loc env
(List.map (fun (name, smty, smodl) -> (name, smty)) sbind) in
let bindings1 =
List.map2
- (fun (id, mty) (name, smty, smodl) ->
+ (fun (id, _, mty) (name, _, smodl) ->
let modl =
type_module true funct_body (anchor_recmodule id anchor) newenv
smodl in
let mty' =
enrich_module_type anchor (Ident.name id) modl.mod_type newenv
in
- (id, mty, modl, mty'))
+ (id, name, mty, modl, mty'))
decls sbind in
let bindings2 =
check_recmodule_inclusion newenv bindings1 in
let (str_rem, sig_rem, final_env) = type_struct newenv srem in
- (Tstr_recmodule bindings2 :: str_rem,
- map_rec (fun rs (id, modl) -> Tsig_module(id, modl.mod_type, rs))
+ (mkstr (Tstr_recmodule bindings2) loc :: str_rem,
+ map_rec (fun rs (id, _, _, modl) -> Sig_module(id, modl.mod_type, rs))
bindings2 sig_rem,
final_env)
- | {pstr_desc = Pstr_modtype(name, smty); pstr_loc = loc} :: srem ->
- check "module type" loc modtype_names name;
+ | Pstr_modtype(name, smty) ->
+ check "module type" loc modtype_names name.txt;
let mty = transl_modtype env smty in
- let (id, newenv) = Env.enter_modtype name (Tmodtype_manifest mty) env in
+ let (id, newenv) = Env.enter_modtype name.txt (Modtype_manifest mty.mty_type) env in
let (str_rem, sig_rem, final_env) = type_struct newenv srem in
- (Tstr_modtype(id, mty) :: str_rem,
- Tsig_modtype(id, Tmodtype_manifest mty) :: sig_rem,
+ (mkstr (Tstr_modtype(id, name, mty)) loc :: str_rem,
+ Sig_modtype(id, Modtype_manifest mty.mty_type) :: sig_rem,
final_env)
- | {pstr_desc = Pstr_open lid; pstr_loc = loc} :: srem ->
- type_struct (type_open env loc lid) srem
- | {pstr_desc = Pstr_class cl; pstr_loc = loc} :: srem ->
+ | Pstr_open (lid) ->
+ let (path, newenv) = type_open env loc lid in
+ let (str_rem, sig_rem, final_env) = type_struct newenv srem in
+ (mkstr (Tstr_open (path, lid)) loc :: str_rem, sig_rem, final_env)
+ | Pstr_class cl ->
List.iter
- (fun {pci_name = name} -> check "type" loc type_names name)
+ (fun {pci_name = name} -> check "type" loc type_names name.txt)
cl;
let (classes, new_env) = Typeclass.class_declarations env cl in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
- (Tstr_class
- (List.map (fun (i, d, _,_,_,_,_,_, s, m, c) ->
+ (mkstr (Tstr_class
+ (List.map (fun (i, _, d, _,_,_,_,_,_, s, m, c) ->
let vf = if d.cty_new = None then Virtual else Concrete in
- (i, s, m, c, vf)) classes) ::
- Tstr_cltype
- (List.map (fun (_,_, i, d, _,_,_,_,_,_,_) -> (i, d)) classes) ::
+ (* (i, s, m, c, vf) *) (c, m, vf)) classes)) loc ::
+(* TODO: check with Jacques why this is here
+ Tstr_class_type
+ (List.map (fun (_,_, i, d, _,_,_,_,_,_,c) -> (i, c)) classes) ::
Tstr_type
(List.map (fun (_,_,_,_, i, d, _,_,_,_,_) -> (i, d)) classes) ::
Tstr_type
(List.map (fun (_,_,_,_,_,_, i, d, _,_,_) -> (i, d)) classes) ::
+*)
str_rem,
List.flatten
(map_rec
- (fun rs (i, d, i', d', i'', d'', i''', d''', _, _, _) ->
- [Tsig_class(i, d, rs);
- Tsig_cltype(i', d', rs);
- Tsig_type(i'', d'', rs);
- Tsig_type(i''', d''', rs)])
+ (fun rs (i, _, d, i', d', i'', d'', i''', d''', _, _, _) ->
+ [Sig_class(i, d, rs);
+ Sig_class_type(i', d', rs);
+ Sig_type(i'', d'', rs);
+ Sig_type(i''', d''', rs)])
classes [sig_rem]),
final_env)
- | {pstr_desc = Pstr_class_type cl; pstr_loc = loc} :: srem ->
+ | Pstr_class_type cl ->
List.iter
- (fun {pci_name = name} -> check "type" loc type_names name)
+ (fun {pci_name = name} -> check "type" loc type_names name.txt)
cl;
let (classes, new_env) = Typeclass.class_type_declarations env cl in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
- (Tstr_cltype
- (List.map (fun (i, d, _, _, _, _) -> (i, d)) classes) ::
- Tstr_type
+ (mkstr (Tstr_class_type
+ (List.map (fun (i, i_loc, d, _, _, _, _, c) -> (i, i_loc, c)) classes)) loc ::
+(* TODO: check with Jacques why this is here
+ Tstr_type
(List.map (fun (_, _, i, d, _, _) -> (i, d)) classes) ::
Tstr_type
- (List.map (fun (_, _, _, _, i, d) -> (i, d)) classes) ::
+ (List.map (fun (_, _, _, _, i, d) -> (i, d)) classes) :: *)
str_rem,
List.flatten
(map_rec
- (fun rs (i, d, i', d', i'', d'') ->
- [Tsig_cltype(i, d, rs);
- Tsig_type(i', d', rs);
- Tsig_type(i'', d'', rs)])
+ (fun rs (i, _, d, i', d', i'', d'', _) ->
+ [Sig_class_type(i, d, rs);
+ Sig_type(i', d', rs);
+ Sig_type(i'', d'', rs)])
classes [sig_rem]),
final_env)
- | {pstr_desc = Pstr_include smodl; pstr_loc = loc} :: srem ->
+ | Pstr_include smodl ->
let modl = type_module true funct_body None env smodl in
(* Rename all identifiers bound by this signature to avoid clashes *)
let sg = Subst.signature Subst.identity
@@ -957,13 +1078,17 @@ and type_structure funct_body anchor env sstr scope =
(check_sig_item type_names module_names modtype_names loc) sg;
let new_env = Env.add_signature sg env in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
- (Tstr_include (modl, bound_value_identifiers sg) :: str_rem,
+ (mkstr (Tstr_include (modl, bound_value_identifiers sg)) loc :: str_rem,
sg @ sig_rem,
final_env)
in
if !Clflags.annotations
- then List.iter (function {pstr_loc = l} -> Stypes.record_phrase l) sstr;
- type_struct env sstr
+ then List.iter (function {pstr_loc = l} -> Stypes.record_phrase l) sstr; (* moved to genannot *)
+ let previous_saved_types = Cmt_format.get_saved_types () in
+ let (items, sg, final_env) = type_struct env sstr in
+ let str = { str_items = items; str_type = sg; str_final_env = final_env } in
+ Cmt_format.set_saved_types (( Cmt_format.Partial_structure str) :: previous_saved_types);
+ str, sg, final_env
let type_module = type_module true false None
let type_structure = type_structure false None
@@ -971,15 +1096,15 @@ let type_structure = type_structure false None
(* Normalize types in a signature *)
let rec normalize_modtype env = function
- Tmty_ident p -> ()
- | Tmty_signature sg -> normalize_signature env sg
- | Tmty_functor(id, param, body) -> normalize_modtype env body
+ Mty_ident p -> ()
+ | Mty_signature sg -> normalize_signature env sg
+ | Mty_functor(id, param, body) -> normalize_modtype env body
and normalize_signature env = List.iter (normalize_signature_item env)
and normalize_signature_item env = function
- Tsig_value(id, desc) -> Ctype.normalize_type env desc.val_type
- | Tsig_module(id, mty, _) -> normalize_modtype env mty
+ Sig_value(id, desc) -> Ctype.normalize_type env desc.val_type
+ | Sig_module(id, mty, _) -> normalize_modtype env mty
| _ -> ()
(* Simplify multiple specifications of a value or an exception in a signature.
@@ -989,26 +1114,26 @@ and normalize_signature_item env = function
let rec simplify_modtype mty =
match mty with
- Tmty_ident path -> mty
- | Tmty_functor(id, arg, res) -> Tmty_functor(id, arg, simplify_modtype res)
- | Tmty_signature sg -> Tmty_signature(simplify_signature sg)
+ Mty_ident path -> mty
+ | Mty_functor(id, arg, res) -> Mty_functor(id, arg, simplify_modtype res)
+ | Mty_signature sg -> Mty_signature(simplify_signature sg)
and simplify_signature sg =
let rec simplif val_names exn_names res = function
[] -> res
- | (Tsig_value(id, descr) as component) :: sg ->
+ | (Sig_value(id, descr) as component) :: sg ->
let name = Ident.name id in
simplif (StringSet.add name val_names) exn_names
(if StringSet.mem name val_names then res else component :: res)
sg
- | (Tsig_exception(id, decl) as component) :: sg ->
+ | (Sig_exception(id, decl) as component) :: sg ->
let name = Ident.name id in
simplif val_names (StringSet.add name exn_names)
(if StringSet.mem name exn_names then res else component :: res)
sg
- | Tsig_module(id, mty, rs) :: sg ->
+ | Sig_module(id, mty, rs) :: sg ->
simplif val_names exn_names
- (Tsig_module(id, simplify_modtype mty, rs) :: res) sg
+ (Sig_module(id, simplify_modtype mty, rs) :: res) sg
| component :: sg ->
simplif val_names exn_names (component :: res) sg
in
@@ -1017,23 +1142,28 @@ and simplify_signature sg =
(* Extract the module type of a module expression *)
let type_module_type_of env smod =
- let mty =
+ let tmty =
match smod.pmod_desc with
| Pmod_ident lid -> (* turn off strengthening in this case *)
- let (path, mty) = Typetexp.find_module env smod.pmod_loc lid in mty
- | _ -> (type_module env smod).mod_type in
+ let (path, mty) = Typetexp.find_module env smod.pmod_loc lid.txt in
+ rm { mod_desc = Tmod_ident (path, lid);
+ mod_type = mty;
+ mod_env = env;
+ mod_loc = smod.pmod_loc }
+ | _ -> type_module env smod in
+ let mty = tmty.mod_type in
(* PR#5037: clean up inferred signature to remove duplicate specs *)
let mty = simplify_modtype mty in
(* PR#5036: must not contain non-generalized type variables *)
if not (closed_modtype mty) then
raise(Error(smod.pmod_loc, Non_generalizable_module mty));
- mty
+ tmty, mty
(* For Typecore *)
let rec get_manifest_types = function
[] -> []
- | Tsig_type (id, {type_params=[]; type_manifest=Some ty}, _) :: rem ->
+ | Sig_type (id, {type_params=[]; type_manifest=Some ty}, _) :: rem ->
(Ident.name id, ty) :: get_manifest_types rem
| _ :: rem -> get_manifest_types rem
@@ -1049,7 +1179,7 @@ let type_package env m p nl tl =
Typetexp.widen context;
let (mp, env) =
match modl.mod_desc with
- Tmod_ident mp -> (mp, env)
+ Tmod_ident (mp,_) -> (mp, env)
| _ ->
let (id, new_env) = Env.enter_module "%M" modl.mod_type env in
(Pident id, new_env)
@@ -1063,14 +1193,14 @@ let type_package env m p nl tl =
List.map (fun name -> Ctype.newconstr (mkpath mp name) []) nl in
(* go back to original level *)
Ctype.end_def ();
- if nl = [] then (wrap_constraint env modl (Tmty_ident p), []) else
+ if nl = [] then (wrap_constraint env modl (Mty_ident p) Tmodtype_implicit, []) else
let mty = modtype_of_package env modl.mod_loc p nl tl' in
List.iter2
(fun n ty ->
try Ctype.unify env ty (Ctype.newvar ())
with Ctype.Unify _ -> raise (Error(m.pmod_loc, Scoping_pack (n,ty))))
nl tl';
- (wrap_constraint env modl mty, tl')
+ (wrap_constraint env modl mty Tmodtype_implicit, tl')
(* Fill in the forward declarations *)
let () =
@@ -1084,6 +1214,8 @@ let () =
(* Typecheck an implementation file *)
let type_implementation sourcefile outputprefix modulename initial_env ast =
+ Cmt_format.set_saved_types [];
+ try
Typecore.reset_delayed_checks ();
let (str, sg, finalenv) = type_structure initial_env ast Location.none in
let simple_sg = simplify_signature sg in
@@ -1105,9 +1237,10 @@ let type_implementation sourcefile outputprefix modulename initial_env ast =
(* It is important to run these checks after the inclusion test above,
so that value declarations which are not used internally but exported
are not reported as being unused. *)
+ Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename (Cmt_format.Implementation str) (Some sourcefile) initial_env None;
(str, coercion)
end else begin
- check_nongen_schemes finalenv str;
+ check_nongen_schemes finalenv str.str_items;
normalize_signature finalenv simple_sg;
let coercion =
Includemod.compunit sourcefile sg
@@ -1117,11 +1250,24 @@ let type_implementation sourcefile outputprefix modulename initial_env ast =
the value being exported. We can still capture unused
declarations like "let x = true;; let x = 1;;", because in this
case, the inferred signature contains only the last declaration. *)
- if not !Clflags.dont_write_files then
- Env.save_signature simple_sg modulename (outputprefix ^ ".cmi");
+ if not !Clflags.dont_write_files then begin
+ let sg = Env.save_signature simple_sg modulename (outputprefix ^ ".cmi") in
+ Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename (Cmt_format.Implementation str)
+ (Some sourcefile) initial_env (Some sg);
+ end;
(str, coercion)
end
- end
+ end
+ with e ->
+ Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename
+ (Cmt_format.Partial_implementation (Array.of_list (Cmt_format.get_saved_types ())))
+ (Some sourcefile) initial_env None;
+ raise e
+
+
+let save_signature modname tsg outputprefix source_file initial_env cmi =
+ Cmt_format.save_cmt (outputprefix ^ ".cmti") modname
+ (Cmt_format.Interface tsg) (Some source_file) initial_env (Some cmi)
(* "Packaging" of several compilation units into one unit
having them as sub-modules. *)
@@ -1132,7 +1278,7 @@ let rec package_signatures subst = function
let sg' = Subst.signature subst sg in
let oldid = Ident.create_persistent name
and newid = Ident.create name in
- Tsig_module(newid, Tmty_signature sg', Trec_not) ::
+ Sig_module(newid, Mty_signature sg', Trec_not) ::
package_signatures (Subst.add_module oldid (Pident newid) subst) rem
let package_units objfiles cmifile modulename =
@@ -1152,13 +1298,15 @@ let package_units objfiles cmifile modulename =
Ident.reinit();
let sg = package_signatures Subst.identity units in
(* See if explicit interface is provided *)
- let mlifile =
- chop_extension_if_any cmifile ^ !Config.interface_suffix in
+ let prefix = chop_extension_if_any cmifile in
+ let mlifile = prefix ^ !Config.interface_suffix in
if Sys.file_exists mlifile then begin
if not (Sys.file_exists cmifile) then begin
raise(Error(Location.in_file mlifile, Interface_not_compiled mlifile))
end;
let dclsig = Env.read_signature modulename cmifile in
+ Cmt_format.save_cmt (prefix ^ ".cmt") modulename
+ (Cmt_format.Packed (sg, objfiles)) None Env.initial None ;
Includemod.compunit "(obtained by packing)" sg mlifile dclsig
end else begin
(* Determine imports *)
@@ -1168,7 +1316,11 @@ let package_units objfiles cmifile modulename =
(fun (name, crc) -> not (List.mem name unit_names))
(Env.imported_units()) in
(* Write packaged signature *)
- Env.save_signature_with_imports sg modulename cmifile imports;
+ if not !Clflags.dont_write_files then begin
+ let sg = Env.save_signature_with_imports sg modulename (prefix ^ ".cmi") imports in
+ Cmt_format.save_cmt (prefix ^ ".cmt") modulename
+ (Cmt_format.Packed (sg, objfiles)) None Env.initial (Some sg)
+ end;
Tcoerce_none
end
diff --git a/typing/typemod.mli b/typing/typemod.mli
index a2c03aaa8..1d3b92ee3 100644
--- a/typing/typemod.mli
+++ b/typing/typemod.mli
@@ -21,20 +21,25 @@ val type_module:
Env.t -> Parsetree.module_expr -> Typedtree.module_expr
val type_structure:
Env.t -> Parsetree.structure -> Location.t ->
- Typedtree.structure * signature * Env.t
+ Typedtree.structure * Types.signature * Env.t
val type_implementation:
- string -> string -> string -> Env.t -> Parsetree.structure ->
- Typedtree.structure * Typedtree.module_coercion
+ string -> string -> string -> Env.t -> Parsetree.structure ->
+ Typedtree.structure * Typedtree.module_coercion
val transl_signature:
- Env.t -> Parsetree.signature -> signature
+ Env.t -> Parsetree.signature -> Typedtree.signature
val check_nongen_schemes:
- Env.t -> Typedtree.structure -> unit
+ Env.t -> Typedtree.structure_item list -> unit
val simplify_signature: signature -> signature
+val save_signature : string -> Typedtree.signature -> string -> string ->
+ Env.t -> Types.signature_item list -> unit
+
val package_units:
string list -> string -> string -> Typedtree.module_coercion
+val bound_value_identifiers : Types.signature_item list -> Ident.t list
+
type error =
Cannot_apply of module_type
| Not_included of Includemod.error list
diff --git a/typing/types.ml b/typing/types.ml
index a13611a81..0ac4a9dab 100644
--- a/typing/types.ml
+++ b/typing/types.ml
@@ -154,8 +154,8 @@ type type_declaration =
and type_kind =
Type_abstract
| Type_record of
- (string * mutable_flag * type_expr) list * record_representation
- | Type_variant of (string * type_expr list * type_expr option) list
+ (Ident.t * mutable_flag * type_expr) list * record_representation
+ | Type_variant of (Ident.t * type_expr list * type_expr option) list
type exception_declaration =
{ exn_args: type_expr list;
@@ -166,9 +166,9 @@ type exception_declaration =
module Concr = Set.Make(OrderedString)
type class_type =
- Tcty_constr of Path.t * type_expr list * class_type
- | Tcty_signature of class_signature
- | Tcty_fun of label * type_expr * class_type
+ Cty_constr of Path.t * type_expr list * class_type
+ | Cty_signature of class_signature
+ | Cty_fun of label * type_expr * class_type
and class_signature =
{ cty_self: type_expr;
@@ -184,7 +184,7 @@ type class_declaration =
cty_new: type_expr option;
cty_variance: (bool * bool) list }
-type cltype_declaration =
+type class_type_declaration =
{ clty_params: type_expr list;
clty_type: class_type;
clty_path: Path.t;
@@ -193,24 +193,24 @@ type cltype_declaration =
(* Type expressions for the module language *)
type module_type =
- Tmty_ident of Path.t
- | Tmty_signature of signature
- | Tmty_functor of Ident.t * module_type * module_type
+ Mty_ident of Path.t
+ | Mty_signature of signature
+ | Mty_functor of Ident.t * module_type * module_type
and signature = signature_item list
and signature_item =
- Tsig_value of Ident.t * value_description
- | Tsig_type of Ident.t * type_declaration * rec_status
- | Tsig_exception of Ident.t * exception_declaration
- | Tsig_module of Ident.t * module_type * rec_status
- | Tsig_modtype of Ident.t * modtype_declaration
- | Tsig_class of Ident.t * class_declaration * rec_status
- | Tsig_cltype of Ident.t * cltype_declaration * rec_status
+ Sig_value of Ident.t * value_description
+ | Sig_type of Ident.t * type_declaration * rec_status
+ | Sig_exception of Ident.t * exception_declaration
+ | Sig_module of Ident.t * module_type * rec_status
+ | Sig_modtype of Ident.t * modtype_declaration
+ | Sig_class of Ident.t * class_declaration * rec_status
+ | Sig_class_type of Ident.t * class_type_declaration * rec_status
and modtype_declaration =
- Tmodtype_abstract
- | Tmodtype_manifest of module_type
+ Modtype_abstract
+ | Modtype_manifest of module_type
and rec_status =
Trec_not (* not recursive *)
diff --git a/typing/types.mli b/typing/types.mli
index cf897bd7a..731cff214 100644
--- a/typing/types.mli
+++ b/typing/types.mli
@@ -153,8 +153,8 @@ type type_declaration =
and type_kind =
Type_abstract
| Type_record of
- (string * mutable_flag * type_expr) list * record_representation
- | Type_variant of (string * type_expr list * type_expr option) list
+ (Ident.t * mutable_flag * type_expr) list * record_representation
+ | Type_variant of (Ident.t * type_expr list * type_expr option) list
type exception_declaration =
{ exn_args: type_expr list;
@@ -165,9 +165,9 @@ type exception_declaration =
module Concr : Set.S with type elt = string
type class_type =
- Tcty_constr of Path.t * type_expr list * class_type
- | Tcty_signature of class_signature
- | Tcty_fun of label * type_expr * class_type
+ Cty_constr of Path.t * type_expr list * class_type
+ | Cty_signature of class_signature
+ | Cty_fun of label * type_expr * class_type
and class_signature =
{ cty_self: type_expr;
@@ -182,7 +182,7 @@ type class_declaration =
cty_new: type_expr option;
cty_variance: (bool * bool) list }
-type cltype_declaration =
+type class_type_declaration =
{ clty_params: type_expr list;
clty_type: class_type;
clty_path: Path.t;
@@ -191,24 +191,24 @@ type cltype_declaration =
(* Type expressions for the module language *)
type module_type =
- Tmty_ident of Path.t
- | Tmty_signature of signature
- | Tmty_functor of Ident.t * module_type * module_type
+ Mty_ident of Path.t
+ | Mty_signature of signature
+ | Mty_functor of Ident.t * module_type * module_type
and signature = signature_item list
and signature_item =
- Tsig_value of Ident.t * value_description
- | Tsig_type of Ident.t * type_declaration * rec_status
- | Tsig_exception of Ident.t * exception_declaration
- | Tsig_module of Ident.t * module_type * rec_status
- | Tsig_modtype of Ident.t * modtype_declaration
- | Tsig_class of Ident.t * class_declaration * rec_status
- | Tsig_cltype of Ident.t * cltype_declaration * rec_status
+ Sig_value of Ident.t * value_description
+ | Sig_type of Ident.t * type_declaration * rec_status
+ | Sig_exception of Ident.t * exception_declaration
+ | Sig_module of Ident.t * module_type * rec_status
+ | Sig_modtype of Ident.t * modtype_declaration
+ | Sig_class of Ident.t * class_declaration * rec_status
+ | Sig_class_type of Ident.t * class_type_declaration * rec_status
and modtype_declaration =
- Tmodtype_abstract
- | Tmodtype_manifest of module_type
+ Modtype_abstract
+ | Modtype_manifest of module_type
and rec_status =
Trec_not (* not recursive *)
diff --git a/typing/typetexp.ml b/typing/typetexp.ml
index 2fe653044..7a680d364 100644
--- a/typing/typetexp.ml
+++ b/typing/typetexp.ml
@@ -14,8 +14,10 @@
(* Typechecking of type expressions for the core language *)
+open Asttypes
open Misc
open Parsetree
+open Typedtree
open Types
open Ctype
@@ -101,7 +103,7 @@ let find_module =
find_component Env.lookup_module (fun lid -> Unbound_module lid)
let find_modtype =
find_component Env.lookup_modtype (fun lid -> Unbound_modtype lid)
-let find_cltype =
+let find_class_type =
find_component Env.lookup_cltype (fun lid -> Unbound_cltype lid)
(* Support for first-class modules. *)
@@ -113,7 +115,7 @@ let create_package_mty fake loc env (p, l) =
let l =
List.sort
(fun (s1, t1) (s2, t2) ->
- if s1 = s2 then raise (Error (loc, Multiple_constraints_on_type s1));
+ if s1.txt = s2.txt then raise (Error (loc, Multiple_constraints_on_type s1.txt));
compare s1 s2)
l
in
@@ -127,7 +129,7 @@ let create_package_mty fake loc env (p, l) =
ptype_manifest = if fake then None else Some t;
ptype_variance = [];
ptype_loc = loc} in
- {pmty_desc=Pmty_with (mty, [ s, Pwith_type d ]);
+ {pmty_desc=Pmty_with (mty, [ { txt = s.txt; loc }, Pwith_type d ]);
pmty_loc=loc}
)
{pmty_desc=Pmty_ident p; pmty_loc=loc}
@@ -195,37 +197,48 @@ let rec swap_list = function
type policy = Fixed | Extensible | Univars
+let ctyp desc typ env loc = { ctyp_desc = desc; ctyp_type = typ; ctyp_loc = loc; ctyp_env = env }
+
let rec transl_type env policy styp =
+ let loc = styp.ptyp_loc in
match styp.ptyp_desc with
Ptyp_any ->
- if policy = Univars then new_pre_univar () else
- if policy = Fixed then
- raise (Error (styp.ptyp_loc, Unbound_type_variable "_"))
- else newvar ()
+ let ty =
+ if policy = Univars then new_pre_univar () else
+ if policy = Fixed then
+ raise (Error (styp.ptyp_loc, Unbound_type_variable "_"))
+ else newvar ()
+ in
+ ctyp Ttyp_any ty env loc
| Ptyp_var name ->
+ let ty =
if name <> "" && name.[0] = '_' then
raise (Error (styp.ptyp_loc, Invalid_variable_name ("'" ^ name)));
begin try
- instance env (List.assoc name !univars)
- with Not_found -> try
- instance env (fst(Tbl.find name !used_variables))
- with Not_found ->
- let v =
- if policy = Univars then new_pre_univar ~name () else newvar ~name ()
- in
- used_variables := Tbl.add name (v, styp.ptyp_loc) !used_variables;
- v
+ instance env (List.assoc name !univars)
+ with Not_found -> try
+ instance env (fst(Tbl.find name !used_variables))
+ with Not_found ->
+ let v =
+ if policy = Univars then new_pre_univar ~name () else newvar ~name () in
+ used_variables := Tbl.add name (v, styp.ptyp_loc) !used_variables;
+ v
end
+ in
+ ctyp (Ttyp_var name) ty env loc
| Ptyp_arrow(l, st1, st2) ->
- let ty1 = transl_type env policy st1 in
- let ty2 = transl_type env policy st2 in
- newty (Tarrow(l, ty1, ty2, Cok))
+ let cty1 = transl_type env policy st1 in
+ let cty2 = transl_type env policy st2 in
+ let ty = newty (Tarrow(l, cty1.ctyp_type, cty2.ctyp_type, Cok)) in
+ ctyp (Ttyp_arrow (l, cty1, cty2)) ty env loc
| Ptyp_tuple stl ->
- newty (Ttuple(List.map (transl_type env policy) stl))
+ let ctys = List.map (transl_type env policy) stl in
+ let ty = newty (Ttuple (List.map (fun ctyp -> ctyp.ctyp_type) ctys)) in
+ ctyp (Ttyp_tuple ctys) ty env loc
| Ptyp_constr(lid, stl) ->
- let (path, decl) = find_type env styp.ptyp_loc lid in
+ let (path, decl) = find_type env styp.ptyp_loc lid.txt in
if List.length stl <> decl.type_arity then
- raise(Error(styp.ptyp_loc, Type_arity_mismatch(lid, decl.type_arity,
+ raise(Error(styp.ptyp_loc, Type_arity_mismatch(lid.txt, decl.type_arity,
List.length stl)));
let args = List.map (transl_type env policy) stl in
let params = instance_list decl.type_params in
@@ -236,23 +249,34 @@ let rec transl_type env policy styp =
if (repr ty).level = Btype.generic_level then unify_var else unify
in
List.iter2
- (fun (sty, ty) ty' ->
- try unify_param env ty' ty with Unify trace ->
+ (fun (sty, cty) ty' ->
+ try unify_param env ty' cty.ctyp_type with Unify trace ->
raise (Error(sty.ptyp_loc, Type_mismatch (swap_list trace))))
(List.combine stl args) params;
- let constr = newconstr path args in
+ let constr = newconstr path (List.map (fun ctyp -> ctyp.ctyp_type) args) in
begin try
Ctype.enforce_constraints env constr
with Unify trace ->
raise (Error(styp.ptyp_loc, Type_mismatch trace))
end;
- constr
+ ctyp (Ttyp_constr (path, lid, args)) constr env loc
| Ptyp_object fields ->
- newobj (transl_fields env policy [] fields)
+ let fields = List.map (fun pf ->
+ let desc =
+ match pf.pfield_desc with
+ | Pfield_var -> Tcfield_var
+ | Pfield (s,e) ->
+ let ty1 = transl_type env policy e in
+ Tcfield (s, ty1)
+ in
+ { field_desc = desc; field_loc = pf.pfield_loc })
+ fields in
+ let ty = newobj (transl_fields env policy [] fields) in
+ ctyp (Ttyp_object fields) ty env loc
| Ptyp_class(lid, stl, present) ->
let (path, decl, is_variant) =
try
- let (path, decl) = Env.lookup_type lid env in
+ let (path, decl) = Env.lookup_type lid.txt env in
let rec check decl =
match decl.type_manifest with
None -> raise Not_found
@@ -268,7 +292,7 @@ let rec transl_type env policy styp =
with Not_found -> try
if present <> [] then raise Not_found;
let lid2 =
- match lid with
+ match lid.txt with
Longident.Lident s -> Longident.Lident ("#" ^ s)
| Longident.Ldot(r, s) -> Longident.Ldot (r, "#" ^ s)
| Longident.Lapply(_, _) -> fatal_error "Typetexp.transl_type"
@@ -276,24 +300,25 @@ let rec transl_type env policy styp =
let (path, decl) = Env.lookup_type lid2 env in
(path, decl, false)
with Not_found ->
- raise(Error(styp.ptyp_loc, Unbound_class lid))
+ raise(Error(styp.ptyp_loc, Unbound_class lid.txt))
in
if List.length stl <> decl.type_arity then
- raise(Error(styp.ptyp_loc, Type_arity_mismatch(lid, decl.type_arity,
+ raise(Error(styp.ptyp_loc, Type_arity_mismatch(lid.txt, decl.type_arity,
List.length stl)));
let args = List.map (transl_type env policy) stl in
let params = instance_list decl.type_params in
List.iter2
- (fun (sty, ty) ty' ->
- try unify_var env ty' ty with Unify trace ->
+ (fun (sty, cty) ty' ->
+ try unify_var env ty' cty.ctyp_type with Unify trace ->
raise (Error(sty.ptyp_loc, Type_mismatch (swap_list trace))))
(List.combine stl args) params;
+ let ty_args = List.map (fun ctyp -> ctyp.ctyp_type) args in
let ty =
- try Ctype.expand_head env (newconstr path args)
+ try Ctype.expand_head env (newconstr path ty_args)
with Unify trace ->
raise (Error(styp.ptyp_loc, Type_mismatch trace))
in
- begin match ty.desc with
+ let ty = match ty.desc with
Tvariant row ->
let row = Btype.row_repr row in
List.iter
@@ -313,7 +338,7 @@ let rec transl_type env policy styp =
row.row_fields
in
let row = { row_closed = true; row_fields = fields;
- row_bound = (); row_name = Some (path, args);
+ row_bound = (); row_name = Some (path, ty_args);
row_fixed = false; row_more = newvar () } in
let static = Btype.static_row row in
let row =
@@ -328,9 +353,10 @@ let rec transl_type env policy styp =
ty
| _ ->
assert false
- end
+ in
+ ctyp (Ttyp_class (path, lid, args, present)) ty env loc
| Ptyp_alias(st, alias) ->
- begin
+ let cty =
try
let t =
try List.assoc alias !univars
@@ -338,7 +364,7 @@ let rec transl_type env policy styp =
instance env (fst(Tbl.find alias !used_variables))
in
let ty = transl_type env policy st in
- begin try unify_var env t ty with Unify trace ->
+ begin try unify_var env t ty.ctyp_type with Unify trace ->
let trace = swap_list trace in
raise(Error(styp.ptyp_loc, Alias_type_mismatch trace))
end;
@@ -348,7 +374,7 @@ let rec transl_type env policy styp =
let t = newvar () in
used_variables := Tbl.add alias (t, styp.ptyp_loc) !used_variables;
let ty = transl_type env policy st in
- begin try unify_var env t ty with Unify trace ->
+ begin try unify_var env t ty.ctyp_type with Unify trace ->
let trace = swap_list trace in
raise(Error(styp.ptyp_loc, Alias_type_mismatch trace))
end;
@@ -363,8 +389,9 @@ let rec transl_type env policy styp =
| Tunivar None -> Btype.log_type px; px.desc <- Tunivar (Some alias)
| _ -> ()
end;
- t
- end
+ { ty with ctyp_type = t }
+ in
+ ctyp (Ttyp_alias (cty, alias)) cty.ctyp_type env loc
| Ptyp_variant(fields, closed, present) ->
let name = ref None in
let mkfield l f =
@@ -388,21 +415,25 @@ let rec transl_type env policy styp =
let add_field = function
Rtag (l, c, stl) ->
name := None;
+ let tl = List.map (transl_type env policy) stl in
let f = match present with
Some present when not (List.mem l present) ->
- let tl = List.map (transl_type env policy) stl in
- Reither(c, tl, false, ref None)
+ let ty_tl = List.map (fun cty -> cty.ctyp_type) tl in
+ Reither(c, ty_tl, false, ref None)
| _ ->
if List.length stl > 1 || c && stl <> [] then
raise(Error(styp.ptyp_loc, Present_has_conjunction l));
- match stl with [] -> Rpresent None
- | st :: _ -> Rpresent (Some(transl_type env policy st))
+ match tl with [] -> Rpresent None
+ | st :: _ ->
+ Rpresent (Some st.ctyp_type)
in
- add_typed_field styp.ptyp_loc l f
+ add_typed_field styp.ptyp_loc l f;
+ Ttag (l,c,tl)
| Rinherit sty ->
- let ty = transl_type env policy sty in
+ let cty = transl_type env policy sty in
+ let ty = cty.ctyp_type in
let nm =
- match repr ty with
+ match repr cty.ctyp_type with
{desc=Tconstr(p, tl, _)} -> Some(p, tl)
| _ -> None
in
@@ -414,7 +445,7 @@ let rec transl_type env policy styp =
(* Unset it otherwise *)
name := None
end;
- let fl = match expand_head env ty, nm with
+ let fl = match expand_head env cty.ctyp_type, nm with
{desc=Tvariant row}, _ when Btype.static_row row ->
let row = Btype.row_repr row in
row.row_fields
@@ -438,9 +469,10 @@ let rec transl_type env policy styp =
| _ -> f
in
add_typed_field sty.ptyp_loc l f)
- fl
+ fl;
+ Tinherit cty
in
- List.iter add_field fields;
+ let tfields = List.map add_field fields in
let fields = Hashtbl.fold (fun _ p l -> p :: l) hfields [] in
begin match present with None -> ()
| Some present ->
@@ -459,13 +491,15 @@ let rec transl_type env policy styp =
else if policy <> Univars then row
else { row with row_more = new_pre_univar () }
in
- newty (Tvariant row)
- | Ptyp_poly(vars, st) ->
+ let ty = newty (Tvariant row) in
+ ctyp (Ttyp_variant (tfields, closed, present)) ty env loc
+ | Ptyp_poly(vars, st) ->
begin_def();
let new_univars = List.map (fun name -> name, newvar ~name ()) vars in
let old_univars = !univars in
univars := new_univars @ !univars;
- let ty = transl_type env policy st in
+ let cty = transl_type env policy st in
+ let ty = cty.ctyp_type in
univars := old_univars;
end_def();
generalize ty;
@@ -485,28 +519,37 @@ let rec transl_type env policy styp =
in
let ty' = Btype.newgenty (Tpoly(ty, List.rev ty_list)) in
unify_var env (newvar()) ty';
- ty'
+ ctyp (Ttyp_poly (vars, cty)) ty' env loc
| Ptyp_package (p, l) ->
let l, mty = create_package_mty true styp.ptyp_loc env (p, l) in
let z = narrow () in
- ignore (!transl_modtype env mty);
+ let mty = !transl_modtype env mty in
widen z;
- newty (Tpackage (!transl_modtype_longident styp.ptyp_loc env p,
- List.map fst l,
- List.map (transl_type env policy) (List.map snd l)))
+ let ptys = List.map (fun (s, pty) ->
+ s, transl_type env policy pty
+ ) l in
+ let path = !transl_modtype_longident styp.ptyp_loc env p.txt in
+ let ty = newty (Tpackage (path,
+ List.map (fun (s, pty) -> s.txt) l,
+ List.map (fun (_,cty) -> cty.ctyp_type) ptys))
+ in
+ ctyp (Ttyp_package {
+ pack_name = path;
+ pack_type = mty.mty_type;
+ pack_fields = ptys;
+ pack_txt = p;
+ }) ty env loc
and transl_fields env policy seen =
function
[] ->
newty Tnil
- | {pfield_desc = Pfield_var}::_ ->
+ | {field_desc = Tcfield_var}::_ ->
if policy = Univars then new_pre_univar () else newvar ()
- | {pfield_desc = Pfield(s, e); pfield_loc = loc}::l ->
+ | {field_desc = Tcfield(s, ty1); field_loc = loc}::l ->
if List.mem s seen then raise (Error (loc, Repeated_method_label s));
- let ty1 = transl_type env policy e in
let ty2 = transl_fields env policy (s::seen) l in
- newty (Tfield (s, Fpresent, ty1, ty2))
-
+ newty (Tfield (s, Fpresent, ty1.ctyp_type, ty2))
(* Make the rows "fixed" in this type, to make universal check easier *)
let rec make_fixed_univars ty =
@@ -563,7 +606,7 @@ let transl_simple_type env fixed styp =
univars := []; used_variables := Tbl.empty;
let typ = transl_type env (if fixed then Fixed else Extensible) styp in
globalize_used_variables env fixed ();
- make_fixed_univars typ;
+ make_fixed_univars typ.ctyp_type;
typ
let transl_simple_type_univars env styp =
@@ -580,7 +623,7 @@ let transl_simple_type_univars env styp =
new_variables;
globalize_used_variables env false ();
end_def ();
- generalize typ;
+ generalize typ.ctyp_type;
let univs =
List.fold_left
(fun acc v ->
@@ -591,13 +634,14 @@ let transl_simple_type_univars env styp =
| _ -> acc)
[] !pre_univars
in
- make_fixed_univars typ;
- instance env (Btype.newgenty (Tpoly (typ, univs)))
+ make_fixed_univars typ.ctyp_type;
+ { typ with ctyp_type =
+ instance env (Btype.newgenty (Tpoly (typ.ctyp_type, univs))) }
let transl_simple_type_delayed env styp =
univars := []; used_variables := Tbl.empty;
let typ = transl_type env Extensible styp in
- make_fixed_univars typ;
+ make_fixed_univars typ.ctyp_type;
(typ, globalize_used_variables env false)
let transl_type_scheme env styp =
@@ -605,7 +649,7 @@ let transl_type_scheme env styp =
begin_def();
let typ = transl_simple_type env false styp in
end_def();
- generalize typ;
+ generalize typ.ctyp_type;
typ
diff --git a/typing/typetexp.mli b/typing/typetexp.mli
index 79082d5f5..dfaec5cb3 100644
--- a/typing/typetexp.mli
+++ b/typing/typetexp.mli
@@ -17,15 +17,15 @@
open Format;;
val transl_simple_type:
- Env.t -> bool -> Parsetree.core_type -> Types.type_expr
+ Env.t -> bool -> Parsetree.core_type -> Typedtree.core_type
val transl_simple_type_univars:
- Env.t -> Parsetree.core_type -> Types.type_expr
+ Env.t -> Parsetree.core_type -> Typedtree.core_type
val transl_simple_type_delayed:
- Env.t -> Parsetree.core_type -> Types.type_expr * (unit -> unit)
+ Env.t -> Parsetree.core_type -> Typedtree.core_type * (unit -> unit)
(* Translate a type, but leave type variables unbound. Returns
the type and a function that binds the type variable. *)
val transl_type_scheme:
- Env.t -> Parsetree.core_type -> Types.type_expr
+ Env.t -> Parsetree.core_type -> Typedtree.core_type
val reset_type_variables: unit -> unit
val enter_type_variable: bool -> Location.t -> string -> Types.type_expr
val type_variable: Location.t -> string -> Types.type_expr
@@ -70,14 +70,14 @@ val report_error: formatter -> error -> unit
(* Support for first-class modules. *)
val transl_modtype_longident: (Location.t -> Env.t -> Longident.t -> Path.t) ref (* from Typemod *)
-val transl_modtype: (Env.t -> Parsetree.module_type -> Types.module_type) ref (* from Typemod *)
-val create_package_mty: Location.t -> Env.t -> Parsetree.package_type -> (Longident.t * Parsetree.core_type) list * Parsetree.module_type
+val transl_modtype: (Env.t -> Parsetree.module_type -> Typedtree.module_type) ref (* from Typemod *)
+val create_package_mty: Location.t -> Env.t -> Parsetree.package_type -> (Longident.t Asttypes.loc * Parsetree.core_type) list * Parsetree.module_type
val find_type: Env.t -> Location.t -> Longident.t -> Path.t * Types.type_declaration
-val find_constructor: Env.t -> Location.t -> Longident.t -> Types.constructor_description
-val find_label: Env.t -> Location.t -> Longident.t -> Types.label_description
+val find_constructor : Env.t -> Location.t -> Longident.t -> Path.t * Types.constructor_description
+val find_label : Env.t -> Location.t -> Longident.t -> Path.t * Types.label_description
val find_value: Env.t -> Location.t -> Longident.t -> Path.t * Types.value_description
val find_class: Env.t -> Location.t -> Longident.t -> Path.t * Types.class_declaration
val find_module: Env.t -> Location.t -> Longident.t -> Path.t * Types.module_type
val find_modtype: Env.t -> Location.t -> Longident.t -> Path.t * Types.modtype_declaration
-val find_cltype: Env.t -> Location.t -> Longident.t -> Path.t * Types.cltype_declaration
+val find_class_type: Env.t -> Location.t -> Longident.t -> Path.t * Types.class_type_declaration
diff --git a/utils/clflags.ml b/utils/clflags.ml
index 51c80ed0e..0b3f6bebc 100644
--- a/utils/clflags.ml
+++ b/utils/clflags.ml
@@ -34,6 +34,7 @@ and classic = ref false (* -nolabels *)
and nopervasives = ref false (* -nopervasives *)
and preprocessor = ref(None : string option) (* -pp *)
let annotations = ref false (* -annot *)
+let binary_annotations = ref false (* -annot *)
and use_threads = ref false (* -thread *)
and use_vmthreads = ref false (* -vmthread *)
and noassert = ref false (* -noassert *)
diff --git a/utils/clflags.mli b/utils/clflags.mli
index 4cff375a4..4ec62cc8d 100644
--- a/utils/clflags.mli
+++ b/utils/clflags.mli
@@ -31,6 +31,7 @@ val classic : bool ref
val nopervasives : bool ref
val preprocessor : string option ref
val annotations : bool ref
+val binary_annotations : bool ref
val use_threads : bool ref
val use_vmthreads : bool ref
val noassert : bool ref
@@ -80,3 +81,4 @@ val std_include_dir : unit -> string list
val shared : bool ref
val dlcode : bool ref
val runtime_variant : string ref
+
diff --git a/utils/config.mlbuild b/utils/config.mlbuild
index ca6e6d476..06fc7da2b 100644
--- a/utils/config.mlbuild
+++ b/utils/config.mlbuild
@@ -62,14 +62,15 @@ let mkexe = C.mkexe
let mkmaindll = C.mkmaindll
let exec_magic_number = "Caml1999X008"
-and cmi_magic_number = "Caml1999I013"
+and cmi_magic_number = "Caml1999I014"
and cmo_magic_number = "Caml1999O007"
and cma_magic_number = "Caml1999A008"
and cmx_magic_number = "Caml1999Y011"
and cmxa_magic_number = "Caml1999Z010"
-and ast_impl_magic_number = "Caml1999M014"
-and ast_intf_magic_number = "Caml1999N013"
+and ast_impl_magic_number = "Caml1999M015"
+and ast_intf_magic_number = "Caml1999N014"
and cmxs_magic_number = "Caml2007D001"
+and cmt_magic_number = "Caml2012T001"
let load_path = ref ([] : string list)
diff --git a/utils/config.mli b/utils/config.mli
index 822df4b06..a201dd43d 100644
--- a/utils/config.mli
+++ b/utils/config.mli
@@ -75,6 +75,8 @@ val ast_impl_magic_number: string
(* Magic number for file holding an implementation syntax tree *)
val cmxs_magic_number: string
(* Magic number for dynamically-loadable plugins *)
+val cmt_magic_number: string
+ (* Magic number for compiled interface files *)
val max_tag: int
(* Biggest tag that can be stored in the header of a regular block. *)
diff --git a/utils/config.mlp b/utils/config.mlp
index 9b3edb989..f59243e95 100644
--- a/utils/config.mlp
+++ b/utils/config.mlp
@@ -51,14 +51,15 @@ let mkexe = "%%MKEXE%%"
let mkmaindll = "%%MKMAINDLL%%"
let exec_magic_number = "Caml1999X008"
-and cmi_magic_number = "Caml1999I013"
+and cmi_magic_number = "Caml1999I014"
and cmo_magic_number = "Caml1999O007"
and cma_magic_number = "Caml1999A008"
and cmx_magic_number = "Caml1999Y011"
and cmxa_magic_number = "Caml1999Z010"
-and ast_impl_magic_number = "Caml1999M014"
-and ast_intf_magic_number = "Caml1999N013"
+and ast_impl_magic_number = "Caml1999M015"
+and ast_intf_magic_number = "Caml1999N014"
and cmxs_magic_number = "Caml2007D001"
+and cmt_magic_number = "Caml2012T001"
let load_path = ref ([] : string list)
diff --git a/utils/misc.ml b/utils/misc.ml
index 1f5bb98b1..206c222da 100644
--- a/utils/misc.ml
+++ b/utils/misc.ml
@@ -141,6 +141,17 @@ let copy_file_chunk ic oc len =
end
in copy len
+let string_of_file ic =
+ let b = Buffer.create 0x10000 in
+ let buff = String.create 0x1000 in
+ let rec copy () =
+ let n = input ic buff 0 0x1000 in
+ if n = 0 then Buffer.contents b else
+ (Buffer.add_substring b buff 0 n; copy())
+ in copy()
+
+
+
(* Reading from a channel *)
let input_bytes ic n =
@@ -205,3 +216,12 @@ let rev_split_words s =
let get_ref r =
let v = !r in
r := []; v
+
+let fst3 (x, _, _) = x
+let snd3 (_,x,_) = x
+let thd3 (_,_,x) = x
+
+let fst4 (x, _, _, _) = x
+let snd4 (_,x,_, _) = x
+let thd4 (_,_,x,_) = x
+
diff --git a/utils/misc.mli b/utils/misc.mli
index 6ccb1b66b..b982a9444 100644
--- a/utils/misc.mli
+++ b/utils/misc.mli
@@ -65,7 +65,9 @@ val copy_file_chunk: in_channel -> out_channel -> int -> unit
(* [copy_file_chunk ic oc n] reads [n] bytes from [ic] and copies
them to [oc]. It raises [End_of_file] when encountering
EOF on [ic]. *)
-
+val string_of_file: in_channel -> string
+ (* [string_of_file ic] reads the contents of file [ic] and copies
+ them to a string. It stops when encountering EOF on [ic]. *)
val input_bytes : in_channel -> int -> string;;
(* [input_bytes ic n] reads [n] bytes from [ic] and returns them
in a new string. It raises [End_of_file] if EOF is encountered
@@ -111,3 +113,12 @@ val rev_split_words: string -> string list
val get_ref: 'a list ref -> 'a list
(* [get_ref lr] returns the content of the list reference [lr] and reset
its content to the empty list. *)
+
+
+val fst3: 'a * 'b * 'c -> 'a
+val snd3: 'a * 'b * 'c -> 'b
+val thd3: 'a * 'b * 'c -> 'c
+
+val fst4: 'a * 'b * 'c * 'd -> 'a
+val snd4: 'a * 'b * 'c * 'd -> 'b
+val thd4: 'a * 'b * 'c * 'd -> 'c