diff options
author | Emilio Jesus Gallego Arias <e+git@x80.org> | 2016-07-07 04:56:24 +0200 |
---|---|---|
committer | Emilio Jesus Gallego Arias <e+git@x80.org> | 2016-08-19 01:48:30 +0200 |
commit | de038270f72214b169d056642eb7144a79e6f126 (patch) | |
tree | c1a5dc835f5042c79418fdbadc7b266a473b8c82 /lib | |
parent | 13fb26d615cdb03a4c4841c20b108deab2de60b3 (diff) |
Unify location handling of error functions.
In some cases prior to this patch, there were two cases for the same
error function, one taking a location, the other not.
We unify them by using an option parameter, in the line with recent
changes in warnings and feedback.
This implies a bit of clean up in some places, but more importantly, is
the preparation for subsequent patches making `Loc.location` opaque,
change that could be use to improve modularity and allow a more
functional implementation strategy --- for example --- of the
beautifier.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cErrors.ml | 9 | ||||
-rw-r--r-- | lib/cErrors.mli | 5 | ||||
-rw-r--r-- | lib/cWarnings.ml | 2 | ||||
-rw-r--r-- | lib/loc.ml | 9 | ||||
-rw-r--r-- | lib/loc.mli | 2 |
5 files changed, 15 insertions, 12 deletions
diff --git a/lib/cErrors.ml b/lib/cErrors.ml index 1459141d1..c5f262373 100644 --- a/lib/cErrors.ml +++ b/lib/cErrors.ml @@ -26,9 +26,8 @@ let _ = let make_anomaly ?label pp = Anomaly (label, pp) -let anomaly ?loc ?label pp = match loc with - | None -> raise (Anomaly (label, pp)) - | Some loc -> Loc.raise loc (Anomaly (label, pp)) +let anomaly ?loc ?label pp = + Loc.raise ?loc (Anomaly (label, pp)) let is_anomaly = function | Anomaly _ -> true @@ -43,8 +42,8 @@ let alreadydeclared pps = raise (AlreadyDeclared(pps)) let todo s = prerr_string ("TODO: "^s^"\n") -let user_err_loc (loc,s,strm) = Loc.raise loc (UserError (s,strm)) -let invalid_arg_loc (loc,s) = Loc.raise loc (Invalid_argument s) +let user_err ?loc s strm = Loc.raise ?loc (UserError (s,strm)) +let invalid_arg ?loc s = Loc.raise ?loc (Invalid_argument s) exception Timeout exception Drop diff --git a/lib/cErrors.mli b/lib/cErrors.mli index e5dad93fd..291c39b84 100644 --- a/lib/cErrors.mli +++ b/lib/cErrors.mli @@ -36,12 +36,13 @@ val is_anomaly : exn -> bool exception UserError of string * std_ppcmds val error : string -> 'a val errorlabstrm : string -> std_ppcmds -> 'a -val user_err_loc : Loc.t * string * std_ppcmds -> 'a + +val user_err : ?loc:Loc.t -> string -> std_ppcmds -> 'a exception AlreadyDeclared of std_ppcmds val alreadydeclared : std_ppcmds -> 'a -val invalid_arg_loc : Loc.t * string -> 'a +val invalid_arg : ?loc:Loc.t -> string -> 'a (** [todo] is for running of an incomplete code its implementation is "do nothing" (or print a message), but this function should not be diff --git a/lib/cWarnings.ml b/lib/cWarnings.ml index 78fa84f33..f36c7ad80 100644 --- a/lib/cWarnings.ml +++ b/lib/cWarnings.ml @@ -45,7 +45,7 @@ let create ~name ~category ?(default=Enabled) pp = | Disabled -> () | AsError -> let loc = Option.default !current_loc loc in - CErrors.user_err_loc (loc,"_",pp x) + CErrors.user_err ~loc "_" (pp x) | Enabled -> let msg = pp x ++ spc () ++ str "[" ++ str name ++ str "," ++ diff --git a/lib/loc.ml b/lib/loc.ml index 0f9864a9a..e373a760c 100644 --- a/lib/loc.ml +++ b/lib/loc.ml @@ -71,6 +71,9 @@ let add_loc e loc = Exninfo.add e location loc let get_loc e = Exninfo.get e location -let raise loc e = - let info = Exninfo.add Exninfo.null location loc in - Exninfo.iraise (e, info) +let raise ?loc e = + match loc with + | None -> raise e + | Some loc -> + let info = Exninfo.add Exninfo.null location loc in + Exninfo.iraise (e, info) diff --git a/lib/loc.mli b/lib/loc.mli index c08e097a8..bb88f8642 100644 --- a/lib/loc.mli +++ b/lib/loc.mli @@ -51,7 +51,7 @@ val add_loc : Exninfo.info -> t -> Exninfo.info val get_loc : Exninfo.info -> t option (** Retrieving the optional location of an exception *) -val raise : t -> exn -> 'a +val raise : ?loc:t -> exn -> 'a (** [raise loc e] is the same as [Pervasives.raise (add_loc e loc)]. *) (** {5 Location utilities} *) |