Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Context.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90(**************************************************************************) (* *) (* This file is part of WP plug-in of Frama-C. *) (* *) (* Copyright (C) 2007-2023 *) (* CEA (Commissariat a l'energie atomique et aux energies *) (* alternatives) *) (* *) (* you can redistribute it and/or modify it under the terms of the GNU *) (* Lesser General Public License as published by the Free Software *) (* Foundation, version 2.1. *) (* *) (* It is distributed in the hope that it will be useful, *) (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) (* GNU Lesser General Public License for more details. *) (* *) (* See the GNU Lesser General Public License version 2.1 *) (* for more details (enclosed in the file licenses/LGPLv2.1). *) (* *) (**************************************************************************) (* -------------------------------------------------------------------------- *) (* --- Location --- *) (* -------------------------------------------------------------------------- *) let with_current_loc loc phi x = let tmp = Cil_const.CurrentLoc.get () in try Cil_const.CurrentLoc.set loc ; let y = phi x in Cil_const.CurrentLoc.set tmp ; y with error -> Cil_const.CurrentLoc.set tmp ; raise error (* -------------------------------------------------------------------------- *) (* --- Local Context --- *) (* -------------------------------------------------------------------------- *) type 'a value = { name : string ; (* Descriptive *) mutable current : 'a option ; } let create ?default name = { name = name ; current = default } let name s = s.name let defined env = match env.current with None -> false | Some _ -> true let get env = match env.current with | Some e -> e | None -> Wp_parameters.fatal "Context '%s' non-initialized." env.name let get_opt env = env.current let set env s = env.current <- Some s let clear env = env.current <- None let update env f = match env.current with | Some e -> env.current <- Some (f e) | None -> Wp_parameters.fatal "Context '%s' non-initialized." env.name let bind_with env w f e = let tmp = env.current in env.current <- w ; try let e = f e in env.current <- tmp ; e with error -> env.current <- tmp ; raise error let bind env s f e = bind_with env (Some s) f e let free env f e = bind_with env None f e let push env x = let old = env.current in env.current <- Some x ; old let pop env old = env.current <- old let demon = ref [] let register f = demon := !demon @ [f] let configure = let closure,state = State_builder.apply_once "Wp.Context.configure" [ Ast.self ] (fun () -> List.iter (fun f -> f ()) !demon) in ignore state ; closure (* -------------------------------------------------------------------------- *)