Skip to content
Snippets Groups Projects
Commit 935803fe authored by Basile Desloges's avatar Basile Desloges
Browse files

[eacsl] Add phase information to error messages

parent 73d390b7
No related branches found
No related tags found
No related merge requests found
...@@ -24,9 +24,13 @@ ...@@ -24,9 +24,13 @@
open Cil_types open Cil_types
module Options: sig
type category
end
module Error: sig module Error: sig
exception Typing_error of string exception Typing_error of Options.category option * string
exception Not_yet of string exception Not_yet of Options.category option * string
end end
module Translate_terms: sig module Translate_terms: sig
......
...@@ -22,14 +22,39 @@ ...@@ -22,14 +22,39 @@
open Error_types open Error_types
exception Typing_error of string module Exn_impl = struct
let untypable s = raise (Typing_error s) exception Typing_error of Options.category option * string
exception Not_yet of Options.category option * string
exception Not_memoized of Options.category option
end
exception Not_yet of string module type Exn = module type of Exn_impl
let not_yet s = raise (Not_yet s)
exception Not_memoized module type S = sig
let not_memoized () = raise Not_memoized include Exn
val make_untypable: string -> exn
val make_not_yet: string -> exn
val make_not_memoized: unit -> exn
val untypable: string -> 'a
val not_yet: string -> 'a
val not_memoized: unit -> 'a
val print_not_yet: string -> unit
val handle: ('a -> 'a) -> 'a -> 'a
val generic_handle: ('a -> 'b) -> 'b -> 'a -> 'b
val nb_untypable: unit -> int
val nb_not_yet: unit -> int
val retrieve_preprocessing:
string ->
('a -> 'b or_error) ->
'a ->
(Format.formatter -> 'a -> unit) ->
'b
val pp_or_error:
(Format.formatter -> 'a -> unit) ->
Format.formatter ->
'a or_error ->
unit
end
module Nb_typing = module Nb_typing =
State_builder.Ref State_builder.Ref
...@@ -40,8 +65,6 @@ module Nb_typing = ...@@ -40,8 +65,6 @@ module Nb_typing =
let dependencies = [ Ast.self ] let dependencies = [ Ast.self ]
end) end)
let nb_untypable = Nb_typing.get
module Nb_not_yet = module Nb_not_yet =
State_builder.Ref State_builder.Ref
(Datatype.Int) (Datatype.Int)
...@@ -51,46 +74,85 @@ module Nb_not_yet = ...@@ -51,46 +74,85 @@ module Nb_not_yet =
let dependencies = [ Ast.self ] let dependencies = [ Ast.self ]
end) end)
let nb_not_yet = Nb_not_yet.get module Make_with_opt(P: sig val phase:Options.category option end): S = struct
include Exn_impl
let print_not_yet msg =
let msg = let make_untypable msg = Typing_error (P.phase, msg)
Format.sprintf "@[E-ACSL construct@ `%s'@ is not yet supported.@]" msg let make_not_yet msg = Not_yet (P.phase, msg)
in let make_not_memoized () = Not_memoized P.phase
Options.warning ~once:true ~current:true "@[%s@ Ignoring annotation.@]" msg;
Nb_not_yet.set (Nb_not_yet.get () + 1) let untypable msg = raise (make_untypable msg)
let not_yet msg = raise (make_not_yet msg)
let generic_handle f res x = let not_memoized () = raise (make_not_memoized ())
try
f x let nb_untypable = Nb_typing.get
with let nb_not_yet = Nb_not_yet.get
| Typing_error s ->
let msg = Format.sprintf "@[invalid E-ACSL construct@ `%s'.@]" s in let pp_phase fmt phase =
Options.warning ~once:true ~current:true "@[%s@ Ignoring annotation.@]" msg; match phase with
Nb_typing.set (Nb_typing.get () + 1); | Some phase ->
res if Options.verbose_atleast 2 then
| Not_yet s -> Format.fprintf fmt "@[@ in phase `%a'@]" Options.pp_category phase
print_not_yet s; | None -> ()
res
let do_print_not_yet phase msg =
let handle f x = generic_handle f x x let msg =
Format.asprintf
let retrieve_preprocessing analyse_name getter parameter pp = "@[E-ACSL construct@ `%s'@ is not yet supported%a.@]"
try msg
match getter parameter with pp_phase phase
| Res res -> res in
| Err exn -> raise exn Options.warning
with Not_memoized -> ~once:true ~current:true
Options.fatal "@[%s@ Ignoring annotation.@]" msg;
"%s was not performed on construct %a" Nb_not_yet.set (Nb_not_yet.get () + 1)
analyse_name
pp let print_not_yet msg =
parameter do_print_not_yet P.phase msg
let pp_or_error pp fmt a_or_error = let generic_handle f res x =
match a_or_error with try
| Res a -> Format.fprintf fmt "@[%a@]" pp a f x
| Err err -> Format.fprintf fmt "@[%s@]" (Printexc.to_string err) with
| Typing_error (phase, s) ->
let msg =
Format.asprintf "@[invalid E-ACSL construct@ `%s'%a.@]"
s
pp_phase phase
in
Options.warning
~once:true ~current:true
"@[%s@ Ignoring annotation.@]" msg;
Nb_typing.set (Nb_typing.get () + 1);
res
| Not_yet (phase, s) ->
do_print_not_yet phase s;
res
let handle f x = generic_handle f x x
let retrieve_preprocessing analyse_name getter parameter pp =
try
match getter parameter with
| Res res -> res
| Err exn -> raise exn
with Not_memoized phase ->
Options.fatal
"@[%s was not performed on construct %a%a@]"
analyse_name
pp parameter
pp_phase phase
let pp_or_error pp fmt a_or_error =
match a_or_error with
| Res a -> Format.fprintf fmt "@[%a@]" pp a
| Err err -> Format.fprintf fmt "@[%s@]" (Printexc.to_string err)
end
module Make(P: sig val phase:Options.category end): S =
Make_with_opt(struct let phase = Some P.phase end)
include Make_with_opt(struct let phase = None end)
(* (*
Local Variables: Local Variables:
......
...@@ -23,57 +23,89 @@ ...@@ -23,57 +23,89 @@
(** Handling errors. *) (** Handling errors. *)
open Error_types open Error_types
exception Typing_error of string (** Internal module holding the exception of [Error].
exception Not_yet of string
exception Not_memoized The module is included into [S] later and should not be used directly.
However we need to have a separate module for the exception so that every
val untypable: string -> 'a exception built by [Make] is the exact same type. *)
(** Type error built from the given argument. *) module type Exn = sig
exception Typing_error of Options.category option * string
val not_yet: string -> 'a (** Typing error where the first element is the phase where the error occured
(** Not_yet_implemented error built from the given argument. *) and the second element is the error message. *)
val not_memoized : unit -> 'a exception Not_yet of Options.category option * string
(** @raise Not_memoized when asking the preprocessed form of something that (** "Not yet supported" error where the first element is the phase where the
was not preprocessed *) error occured and the second element is the error message. *)
val handle: ('a -> 'a) -> 'a -> 'a exception Not_memoized of Options.category option
(** Run the closure with the given argument and handle potential errors. (** "Not memoized" error with the phase where the error occured. *)
Return the provide argument in case of errors. *) end
val generic_handle: ('a -> 'b) -> 'b -> 'a -> 'b module type S = sig
(** Run the closure with the given argument and handle potential errors. include Exn
Return the additional argument in case of errors. *)
val make_untypable: string -> exn
val nb_untypable: unit -> int (** Make a [Typing_error] exception with the given message. *)
(** Number of untypable annotations. *)
val make_not_yet: string -> exn
val nb_not_yet: unit -> int (** Make a [Not_yet] exception with the given message. *)
(** Number of not-yet-supported annotations. *)
val make_not_memoized: unit -> exn
val print_not_yet: string -> unit (** Make a [Not_memoized] exception with the given message. *)
(** Print the "not yet" message without raising an exception. *)
val untypable: string -> 'a
val retrieve_preprocessing: (** @raise Typing_error with the given message. *)
string ->
('a -> 'b or_error) -> val not_yet: string -> 'a
'a -> (** @raise Not_yet with the given message. *)
(Format.formatter -> 'a -> unit) ->
'b val not_memoized: unit -> 'a
(** Retrieve the result of a preprocessing phase, which possibly failed. (** @raise Not_memoized *)
The [string] argument and the formatter are used to display a message in
case the preprocessing phase did not compute the required result. *) val print_not_yet: string -> unit
(** Print the "not yet supported" message without raising an exception. *)
val pp_or_error:
(Format.formatter -> 'a -> unit) -> val handle: ('a -> 'a) -> 'a -> 'a
Format.formatter -> (** Run the closure with the given argument and handle potential errors.
'a or_error -> Return the provide argument in case of errors. *)
unit
(** [pp_or_error pp] where [pp] is a formatter for ['a] returns a formatter for val generic_handle: ('a -> 'b) -> 'b -> 'a -> 'b
['a or_error]. *) (** Run the closure with the given argument and handle potential errors.
Return the additional argument in case of errors. *)
val nb_untypable: unit -> int
(** Number of untypable annotations. *)
val nb_not_yet: unit -> int
(** Number of not-yet-supported annotations. *)
val retrieve_preprocessing:
string ->
('a -> 'b or_error) ->
'a ->
(Format.formatter -> 'a -> unit) ->
'b
(** Retrieve the result of a preprocessing phase, which possibly failed.
The [string] argument and the formatter are used to display a message in
case the preprocessing phase did not compute the required result. *)
val pp_or_error:
(Format.formatter -> 'a -> unit) ->
Format.formatter ->
'a or_error ->
unit
(** [pp_or_error pp] where [pp] is a formatter for ['a] returns a formatter for
['a or_error]. *)
end
(** Functor to build an [Error] module for a given [phase]. *)
module Make(P: sig val phase:Options.category end): S
(** The [Error] module implements [Error.S] with no phase. *)
include S
(* (*
Local Variables: Local Variables:
compile-command: "make" compile-command: "make -C ../../../../.."
End: End:
*) *)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment