Skip to content
Snippets Groups Projects
Commit a9b91bf2 authored by Basile Desloges's avatar Basile Desloges Committed by Julien Signoles
Browse files

fixup! [eacsl] Create an analysis to compute translation location of labeled pred and terms

parent b8535d31
No related branches found
No related tags found
No related merge requests found
...@@ -44,12 +44,12 @@ module Annotation_kind = ...@@ -44,12 +44,12 @@ module Annotation_kind =
| RTE -> Format.fprintf fmt "RTE" | RTE -> Format.fprintf fmt "RTE"
end) end)
module PredOrTerm = module Pred_or_term =
Datatype.Make_with_collections Datatype.Make_with_collections
(struct (struct
type t = pred_or_term type t = pred_or_term
let name = "E_ACSL.PredOrTerm" let name = "E_ACSL.Pred_or_term"
let reprs = let reprs =
let reprs = let reprs =
...@@ -85,13 +85,12 @@ module PredOrTerm = ...@@ -85,13 +85,12 @@ module PredOrTerm =
let varname _ = "pred_or_term" let varname _ = "pred_or_term"
end) end)
(** Extended logic label module to associate a statement to a label when (** [Ext_logic_label] associates a statement to a label when necessary. For
necessary. For instance, the label `Old` is associated with its contract instance, the label `Old` is associated with its contract statement to
statement to be able to distinguish two `Old` annotations in the same distinguish two `Old` annotations in the same function. On the contrary, the
function. On the contrary the `Pre` label does not have an associated `Pre` label does not have an associated statement because this label
statement because this label designate the same location for all contracts represents the same location for all contracts in the same function. *)
in the same function. *) module Ext_logic_label: sig
module ExtLogicLabel: sig
include Datatype.S_with_collections with type t = logic_label * stmt option include Datatype.S_with_collections with type t = logic_label * stmt option
val from: kinstr -> logic_label -> logic_label * stmt option val from: kinstr -> logic_label -> logic_label * stmt option
...@@ -102,11 +101,11 @@ end = struct ...@@ -102,11 +101,11 @@ end = struct
(Datatype.Option_with_collections (Datatype.Option_with_collections
(Stmt) (Stmt)
(struct (struct
let module_name = "E_ACSL.Labels.ExtLogicLabel.StmtOption" let module_name = "E_ACSL.Labels.Ext_logic_label.StmtOption"
end)) end))
(struct let module_name = "E_ACSL.Labels.ExtLogicLabel" end) (struct let module_name = "E_ACSL.Labels.Ext_logic_label" end)
(* Override [pretty] to print a more compact representation of [ExtLogicLabel] (* Override [pretty] to print a more compact representation of [Ext_logic_label]
for debugging purposes. *) for debugging purposes. *)
let pretty fmt (label, from_stmt_opt) = let pretty fmt (label, from_stmt_opt) =
match from_stmt_opt with match from_stmt_opt with
...@@ -163,14 +162,14 @@ let basic_kinstr_hash kinstr = ...@@ -163,14 +162,14 @@ let basic_kinstr_hash kinstr =
| Kglobal -> 1 lsl 29 | Kglobal -> 1 lsl 29
| Kstmt _ -> 1 lsl 31 | Kstmt _ -> 1 lsl 31
module AtData = struct module At_data = struct
let create ?error kf kinstr lscope pot label = let create ?error kf kinstr lscope pot label =
{ kf; kinstr; lscope; pot; label; error } { kf; kinstr; lscope; pot; label; error }
include Datatype.Make_with_collections include Datatype.Make_with_collections
(struct (struct
type t = at_data type t = at_data
let name = "E_ACSL.AtData" let name = "E_ACSL.At_data"
let reprs = let reprs =
List.fold_left List.fold_left
...@@ -185,7 +184,7 @@ module AtData = struct ...@@ -185,7 +184,7 @@ module AtData = struct
acc acc
Logic_label.reprs) Logic_label.reprs)
acc acc
PredOrTerm.reprs) Pred_or_term.reprs)
acc acc
Kinstr.reprs) Kinstr.reprs)
[] []
...@@ -216,33 +215,33 @@ module AtData = struct ...@@ -216,33 +215,33 @@ module AtData = struct
else cmp else cmp
in in
let cmp = let cmp =
if cmp = 0 then PredOrTerm.compare pot1 pot2 if cmp = 0 then Pred_or_term.compare pot1 pot2
else cmp else cmp
in in
if cmp = 0 then if cmp = 0 then
let extlabel1 = ExtLogicLabel.from kinstr1 label1 in let extlabel1 = Ext_logic_label.from kinstr1 label1 in
let extlabel2 = ExtLogicLabel.from kinstr2 label2 in let extlabel2 = Ext_logic_label.from kinstr2 label2 in
ExtLogicLabel.compare extlabel1 extlabel2 Ext_logic_label.compare extlabel1 extlabel2
else cmp else cmp
let equal = Datatype.from_compare let equal = Datatype.from_compare
let hash { kf; kinstr; lscope; pot; label } = let hash { kf; kinstr; lscope; pot; label } =
let extlabel = ExtLogicLabel.from kinstr label in let extlabel = Ext_logic_label.from kinstr label in
Hashtbl.hash Hashtbl.hash
(Kf.hash kf, (Kf.hash kf,
basic_kinstr_hash kinstr, basic_kinstr_hash kinstr,
Lscope.D.hash lscope, Lscope.D.hash lscope,
PredOrTerm.hash pot, Pred_or_term.hash pot,
ExtLogicLabel.hash extlabel) Ext_logic_label.hash extlabel)
let pretty fmt { kf; kinstr; lscope; pot; label } = let pretty fmt { kf; kinstr; lscope; pot; label } =
let extlabel = ExtLogicLabel.from kinstr label in let extlabel = Ext_logic_label.from kinstr label in
Format.fprintf fmt "@[(%a, %a, %a, %a, %a)@]" Format.fprintf fmt "@[(%a, %a, %a, %a, %a)@]"
Kf.pretty kf Kf.pretty kf
basic_pp_kinstr kinstr basic_pp_kinstr kinstr
Lscope.D.pretty lscope Lscope.D.pretty lscope
PredOrTerm.pretty pot Pred_or_term.pretty pot
ExtLogicLabel.pretty extlabel Ext_logic_label.pretty extlabel
end) end)
end end
...@@ -27,9 +27,9 @@ open Analyses_types ...@@ -27,9 +27,9 @@ open Analyses_types
module Annotation_kind: Datatype.S with type t = annotation_kind module Annotation_kind: Datatype.S with type t = annotation_kind
module PredOrTerm: Datatype.S_with_collections with type t = pred_or_term module Pred_or_term: Datatype.S_with_collections with type t = pred_or_term
module AtData: sig module At_data: sig
include Datatype.S_with_collections with type t = at_data include Datatype.S_with_collections with type t = at_data
val create: val create:
......
...@@ -37,7 +37,7 @@ type pred_or_term = ...@@ -37,7 +37,7 @@ type pred_or_term =
| PoT_term of term | PoT_term of term
(** Type uniquely representing a [predicate] or [term] with an associated (** Type uniquely representing a [predicate] or [term] with an associated
[label], and all the information necessary for its translation. *) [label], and the necessary information for its translation. *)
type at_data = { type at_data = {
(** [kernel_function] englobing the [pred_or_term]. *) (** [kernel_function] englobing the [pred_or_term]. *)
kf: kernel_function; kf: kernel_function;
......
...@@ -58,7 +58,7 @@ let preprocess_done = ref false ...@@ -58,7 +58,7 @@ let preprocess_done = ref false
(** Associate a statement with the [at_data] that need to be translated on (** Associate a statement with the [at_data] that need to be translated on
this statement. *) this statement. *)
let at_data_for_stmts: AtData.Set.t ref Stmt.Hashtbl.t = let at_data_for_stmts: At_data.Set.t ref Stmt.Hashtbl.t =
Stmt.Hashtbl.create 17 Stmt.Hashtbl.create 17
(** Add [data] to the list of [at_data] that must be translated on the (** Add [data] to the list of [at_data] that must be translated on the
...@@ -69,23 +69,23 @@ let add_at_for_stmt data stmt = ...@@ -69,23 +69,23 @@ let add_at_for_stmt data stmt =
try try
Stmt.Hashtbl.find at_data_for_stmts stmt Stmt.Hashtbl.find at_data_for_stmts stmt
with Not_found -> with Not_found ->
let ats_ref = ref AtData.Set.empty in let ats_ref = ref At_data.Set.empty in
Stmt.Hashtbl.add at_data_for_stmts stmt ats_ref; Stmt.Hashtbl.add at_data_for_stmts stmt ats_ref;
ats_ref ats_ref
in in
let old_data = let old_data =
try try
AtData.Set.find data !ats_ref At_data.Set.find data !ats_ref
with Not_found -> with Not_found ->
ats_ref := AtData.Set.add data !ats_ref; ats_ref := At_data.Set.add data !ats_ref;
data data
in in
match old_data.error, data.error with match old_data.error, data.error with
| Some _, None -> | Some _, None ->
(* Replace the old data that has an error with the new data that do not (* Replace the old data that has an error with the new data that do not
have one. *) have one. *)
ats_ref := AtData.Set.remove old_data !ats_ref; ats_ref := At_data.Set.remove old_data !ats_ref;
ats_ref := AtData.Set.add data !ats_ref ats_ref := At_data.Set.add data !ats_ref
| Some _, Some _ | Some _, Some _
| None, Some _ | None, Some _
| None, None -> | None, None ->
...@@ -97,7 +97,7 @@ let add_at_for_stmt data stmt = ...@@ -97,7 +97,7 @@ let add_at_for_stmt data stmt =
let at_for_stmt stmt = let at_for_stmt stmt =
if !preprocess_done then if !preprocess_done then
let ats_ref = let ats_ref =
Stmt.Hashtbl.find_def at_data_for_stmts stmt (ref AtData.Set.empty) Stmt.Hashtbl.find_def at_data_for_stmts stmt (ref At_data.Set.empty)
in in
Result.Ok !ats_ref Result.Ok !ats_ref
else else
...@@ -126,10 +126,10 @@ module Process: sig ...@@ -126,10 +126,10 @@ module Process: sig
end end
val term: ?error:exn -> Env.t -> term -> unit val term: ?error:exn -> Env.t -> term -> unit
(** Traverse the given term to analyse labeled predicates and terms. *) (** Traverse the given term to analyze its labeled predicates and terms. *)
val predicate: ?error:exn -> Env.t -> predicate -> unit val predicate: ?error:exn -> Env.t -> predicate -> unit
(** Traverse the given predicate to analyse the labeled predicates and (** Traverse the given predicate to analyze its labeled predicates and
terms. *) terms. *)
end = struct end = struct
...@@ -177,7 +177,7 @@ end = struct ...@@ -177,7 +177,7 @@ end = struct
(** Analyse the predicate or term [pot] and the label [label] to decide where (** Analyse the predicate or term [pot] and the label [label] to decide where
the predicate or term must be translated. *) the predicate or term must be translated. *)
let process ?error env pot label = let process ?error env pot label =
Env.( (* locally open Env to be able to access the fields of Env.t *) Env.( (* locally open Env to access to the fields of Env.t *)
let msg s = let msg s =
Format.asprintf Format.asprintf
"%s '%a' within %s annotation '%a' in '%a'" "%s '%a' within %s annotation '%a' in '%a'"
...@@ -187,7 +187,7 @@ end = struct ...@@ -187,7 +187,7 @@ end = struct
| Kglobal -> "function" | Kglobal -> "function"
| Kstmt _ -> "statement") | Kstmt _ -> "statement")
Annotation_kind.pretty env.akind Annotation_kind.pretty env.akind
PredOrTerm.pretty pot Pred_or_term.pretty pot
in in
let error, dest_stmt_opt = let error, dest_stmt_opt =
match env.kinstr, env.akind, label with match env.kinstr, env.akind, label with
...@@ -199,7 +199,7 @@ end = struct ...@@ -199,7 +199,7 @@ end = struct
Options.fatal "%s" (msg "invalid use of C label") Options.fatal "%s" (msg "invalid use of C label")
(* Assertions *) (* Assertions *)
(* - Pre label corresponds to the first statement of the function *) (* - Pre label corresponding to the first statement of the function *)
| Kstmt _, Assertion, BuiltinLabel Pre -> | Kstmt _, Assertion, BuiltinLabel Pre ->
error, Some (Kernel_function.find_first_stmt env.kf) error, Some (Kernel_function.find_first_stmt env.kf)
(* - In-place translation for label Here *) (* - In-place translation for label Here *)
...@@ -296,7 +296,7 @@ end = struct ...@@ -296,7 +296,7 @@ end = struct
(* Register the current labeled pred_or_term to the destination (* Register the current labeled pred_or_term to the destination
statement for a later translation *) statement for a later translation *)
let at = let at =
AtData.create ?error env.kf env.kinstr env.lscope pot label At_data.create ?error env.kf env.kinstr env.lscope pot label
in in
add_at_for_stmt at dest_stmt; add_at_for_stmt at dest_stmt;
| None -> | None ->
...@@ -439,7 +439,7 @@ end = struct ...@@ -439,7 +439,7 @@ end = struct
else begin else begin
(* We want to process the bounds and the predicate with the same (* We want to process the bounds and the predicate with the same
environment as the translation (done in [Quantif.convert]). As a environment as the translation (done in [Quantif.convert]). As a
result the [lscope] is first built with a [fold_right] on the result, the [lscope] is first built with a [fold_right] on the
[bound_vars], then once the [lscope] is entirely built, the terms [bound_vars], then once the [lscope] is entirely built, the terms
of the bounds and the predicate of the goal are analyzed. *) of the bounds and the predicate of the goal are analyzed. *)
let env = let env =
...@@ -493,8 +493,8 @@ end = struct ...@@ -493,8 +493,8 @@ end = struct
arguments *) arguments *)
let error = do_term ?error env t in let error = do_term ?error env t in
(* Since we do not know how the labels are used with the arguments, (* Since we do not know how the labels are used with the arguments,
for each argument, register a not_yet error with each label of the for each argument, register a [Not_yet] error with each label of the
function so that each possible combination gracefully raise an error function so that each possible combination gracefully raises an error
to the user. *) to the user. *)
List.fold_left List.fold_left
(fun error label -> process ?error env (PoT_term t) label) (fun error label -> process ?error env (PoT_term t) label)
...@@ -555,10 +555,10 @@ let _debug () = ...@@ -555,10 +555,10 @@ let _debug () =
Options.feedback ~level:2 "| - stmt %d at %a" Options.feedback ~level:2 "| - stmt %d at %a"
stmt.sid stmt.sid
Printer.pp_location (Stmt.loc stmt); Printer.pp_location (Stmt.loc stmt);
AtData.Set.iter At_data.Set.iter
(fun at -> (fun at ->
Options.feedback ~level:2 "| - at %a" Options.feedback ~level:2 "| - at %a"
AtData.pretty at) At_data.pretty at)
!ats_ref !ats_ref
) )
at_data_for_stmts at_data_for_stmts
......
...@@ -35,7 +35,7 @@ val get_first_inner_stmt: stmt -> stmt ...@@ -35,7 +35,7 @@ val get_first_inner_stmt: stmt -> stmt
(** If the given statement has a label, return the first statement of the block. (** If the given statement has a label, return the first statement of the block.
Otherwise return the given statement. *) Otherwise return the given statement. *)
val at_for_stmt: stmt -> AtData.Set.t Error.result val at_for_stmt: stmt -> At_data.Set.t Error.result
(** @return the set of labeled predicates and terms to be translated on the (** @return the set of labeled predicates and terms to be translated on the
given statement. given statement.
@raise Not_memoized if the labels pre-analysis was not run. *) @raise Not_memoized if the labels pre-analysis was not run. *)
......
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