summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2014-05-11 00:17:05 +0000
committerJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2014-05-11 00:17:05 +0000
commitccce2729666c4df6a1a7e5b92addb7b81d67dd23 (patch)
tree0cb546d5713db6e1fad031c12d084dfa05c9fc1e /driver
parentfc8c7778250119e7be7df329929861ef6b77b55f (diff)
downloadocaml-ccce2729666c4df6a1a7e5b92addb7b81d67dd23.tar.gz
commit o_and_opens.diff
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14787 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'driver')
-rw-r--r--driver/compenv.ml19
-rw-r--r--driver/compenv.mli3
-rw-r--r--driver/compile.ml8
-rw-r--r--driver/compmisc.ml2
-rw-r--r--driver/main.ml1
-rw-r--r--driver/main_args.ml4
-rw-r--r--driver/main_args.mli1
-rw-r--r--driver/optcompile.ml8
-rw-r--r--driver/optmain.ml1
9 files changed, 28 insertions, 19 deletions
diff --git a/driver/compenv.ml b/driver/compenv.ml
index e2a90d29a6..32ecb937e9 100644
--- a/driver/compenv.ml
+++ b/driver/compenv.ml
@@ -55,7 +55,7 @@ let last_ppx = ref []
let first_objfiles = ref []
let last_objfiles = ref []
-(* Note: this function is duplicated in optcompile.ml *)
+(* Check validity of module name *)
let check_unit_name ppf filename name =
try
begin match name.[0] with
@@ -76,10 +76,19 @@ let check_unit_name ppf filename name =
with Exit -> ()
;;
-
-
-
-
+(* Compute name of module from output file name *)
+let module_of_filename ppf inputfile outputprefix =
+ let basename = Filename.basename outputprefix in
+ let name =
+ try
+ let pos = String.index basename '.' in
+ String.sub basename 0 pos
+ with Not_found -> basename
+ in
+ let name = String.capitalize name in
+ check_unit_name ppf inputfile name;
+ name
+;;
type readenv_position =
diff --git a/driver/compenv.mli b/driver/compenv.mli
index d1d64393ac..85d588ef6e 100644
--- a/driver/compenv.mli
+++ b/driver/compenv.mli
@@ -10,7 +10,8 @@
(* *)
(***********************************************************************)
-val check_unit_name : Format.formatter -> string -> string -> unit
+(* val check_unit_name : Format.formatter -> string -> string -> unit *)
+val module_of_filename : Format.formatter -> string -> string -> string
val output_prefix : string -> string
val extract_output : string option -> string
diff --git a/driver/compile.ml b/driver/compile.ml
index a200b53635..6ffa9ed9a8 100644
--- a/driver/compile.ml
+++ b/driver/compile.ml
@@ -23,9 +23,7 @@ open Compenv
let interface ppf sourcefile outputprefix =
Compmisc.init_path false;
- let modulename =
- String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in
- check_unit_name ppf sourcefile modulename;
+ let modulename = module_of_filename ppf sourcefile outputprefix in
Env.set_unit_name modulename;
let initial_env = Compmisc.initial_env () in
let ast = Pparse.parse_interface ppf sourcefile in
@@ -57,9 +55,7 @@ let (++) x f = f x
let implementation ppf sourcefile outputprefix =
Compmisc.init_path false;
- let modulename =
- String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in
- check_unit_name ppf sourcefile modulename;
+ let modulename = module_of_filename ppf sourcefile outputprefix in
Env.set_unit_name modulename;
let env = Compmisc.initial_env() in
if !Clflags.print_types then begin
diff --git a/driver/compmisc.ml b/driver/compmisc.ml
index b97ba6c74e..b3283fa86f 100644
--- a/driver/compmisc.ml
+++ b/driver/compmisc.ml
@@ -57,4 +57,4 @@ let initial_env () =
in
List.fold_left (fun env m ->
open_implicit_module m env
- ) env !implicit_modules
+ ) env (!implicit_modules @ List.rev !Clflags.open_module)
diff --git a/driver/main.ml b/driver/main.ml
index 9a40e95a62..7d182ea40b 100644
--- a/driver/main.ml
+++ b/driver/main.ml
@@ -103,6 +103,7 @@ module Options = Main_args.Make_bytecomp_options (struct
let _noautolink = set no_auto_link
let _nostdlib = set no_std_include
let _o s = output_name := Some s
+ let _open s = open_module := s :: !open_module
let _output_obj () = output_c_object := true; custom_runtime := true
let _pack = set make_package
let _pp s = preprocessor := Some s
diff --git a/driver/main_args.ml b/driver/main_args.ml
index 6ebbdb0c1e..0324a75c01 100644
--- a/driver/main_args.ml
+++ b/driver/main_args.ml
@@ -208,6 +208,9 @@ let mk_o f =
"-o", Arg.String f, "<file> Set output file name to <file>"
;;
+let mk_open f =
+ "-open", Arg.String f, "<module> Opens the module <module> before typing"
+
let mk_output_obj f =
"-output-obj", Arg.Unit f, " Output a C object file instead of an executable"
;;
@@ -456,6 +459,7 @@ module type Common_options = sig
val _noassert : unit -> unit
val _nolabels : unit -> unit
val _nostdlib : unit -> unit
+ val _open : string -> unit
val _ppx : string -> unit
val _principal : unit -> unit
val _rectypes : unit -> unit
diff --git a/driver/main_args.mli b/driver/main_args.mli
index d66f551ca0..04c291bb65 100644
--- a/driver/main_args.mli
+++ b/driver/main_args.mli
@@ -19,6 +19,7 @@ module type Common_options = sig
val _noassert : unit -> unit
val _nolabels : unit -> unit
val _nostdlib : unit -> unit
+ val _open : string -> unit
val _ppx : string -> unit
val _principal : unit -> unit
val _rectypes : unit -> unit
diff --git a/driver/optcompile.ml b/driver/optcompile.ml
index 9b70cee04d..083ff7775d 100644
--- a/driver/optcompile.ml
+++ b/driver/optcompile.ml
@@ -24,9 +24,7 @@ open Compenv
let interface ppf sourcefile outputprefix =
Compmisc.init_path false;
- let modulename =
- String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in
- check_unit_name ppf sourcefile modulename;
+ let modulename = module_of_filename ppf sourcefile outputprefix in
Env.set_unit_name modulename;
let initial_env = Compmisc.initial_env () in
let ast = Pparse.parse_interface ppf sourcefile in
@@ -59,9 +57,7 @@ let (+++) (x, y) f = (x, f y)
let implementation ppf sourcefile outputprefix =
Compmisc.init_path true;
- let modulename =
- String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in
- check_unit_name ppf sourcefile modulename;
+ let modulename = module_of_filename ppf sourcefile outputprefix in
Env.set_unit_name modulename;
let env = Compmisc.initial_env() in
Compilenv.reset ?packname:!Clflags.for_package modulename;
diff --git a/driver/optmain.ml b/driver/optmain.ml
index 21c1f8e124..91e17bbfea 100644
--- a/driver/optmain.ml
+++ b/driver/optmain.ml
@@ -102,6 +102,7 @@ module Options = Main_args.Make_optcomp_options (struct
let _nolabels = set classic
let _nostdlib = set no_std_include
let _o s = output_name := Some s
+ let _open s = open_module := s :: !open_module
let _output_obj = set output_c_object
let _p = set gprofile
let _pack = set make_package