From a321788c2f9dee8be008cdcfaa848e887f7a8ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Sat, 5 Dec 2020 15:37:30 +0100 Subject: [PATCH] [eva/server] computed hook --- src/plugins/value/api/values_request.ml | 2 ++ src/plugins/value/engine/analysis.ml | 10 +++++++++- src/plugins/value/engine/analysis.mli | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins/value/api/values_request.ml b/src/plugins/value/api/values_request.ml index ed98a6bb1b4..986e4339faf 100644 --- a/src/plugins/value/api/values_request.ml +++ b/src/plugins/value/api/values_request.ml @@ -54,6 +54,8 @@ type domain = { let signal = Request.signal ~package ~name:"changed" ~descr:(Md.plain "Emitted when EVA results has changed") +let () = Analysis.register_computed_hook (fun () -> Request.emit signal) + (* -------------------------------------------------------------------------- *) (* --- Marker Utilities --- *) (* -------------------------------------------------------------------------- *) diff --git a/src/plugins/value/engine/analysis.ml b/src/plugins/value/engine/analysis.ml index 256e3db49ab..d1d807098e3 100644 --- a/src/plugins/value/engine/analysis.ml +++ b/src/plugins/value/engine/analysis.ml @@ -127,9 +127,16 @@ let current_analyzer () = (module (val (snd !ref_analyzer)): S) Useful for the GUI parts that depend on it. *) module Analyzer_Hook = Hook.Build (struct type t = (module S) end) +(* Set of hooks called whenever the current Analyzer is computed. + Useful for the GUI parts that depend on it. *) +module Computed_Hook = Hook.Build (struct type t = unit end) + (* Register a new hook. *) let register_hook = Analyzer_Hook.extend +(* Register a new computed hook. *) +let register_computed_hook = Computed_Hook.extend + (* Sets the current Analyzer module for a given configuration. Calls the hooks above. *) let set_current_analyzer config (analyzer: (module Analyzer)) = @@ -169,7 +176,8 @@ let force_compute () = let kf, lib_entry = Globals.entry_point () in reset_analyzer (); let module Analyzer = (val snd !ref_analyzer) in - Analyzer.compute_from_entry_point ~lib_entry kf + Analyzer.compute_from_entry_point ~lib_entry kf ; + Computed_Hook.apply () (* Resets the Analyzer when the current project is changed. *) let () = diff --git a/src/plugins/value/engine/analysis.mli b/src/plugins/value/engine/analysis.mli index 6f85061797c..50b943ccad7 100644 --- a/src/plugins/value/engine/analysis.mli +++ b/src/plugins/value/engine/analysis.mli @@ -70,6 +70,10 @@ val register_hook: ((module S) -> unit) -> unit is changed. This happens when a new analysis is run with different abstractions than before, or when the current project is changed. *) +val register_computed_hook: (unit -> unit) -> unit +(** Registers a hook that will be called each time the [current] analyzer + has been computed. *) + val force_compute : unit -> unit (** Perform a full analysis, starting from the [main] function. *) -- GitLab