Skip to content
Snippets Groups Projects
Commit 426c502a authored by Allan Blanchard's avatar Allan Blanchard
Browse files

[wp] builtin types are now registered in LogicBuiltins

parent 5deae9f7
No related branches found
No related tags found
No related merge requests found
...@@ -197,17 +197,18 @@ let rec varpoly k x = function ...@@ -197,17 +197,18 @@ let rec varpoly k x = function
| y::ys -> if x = y then k else varpoly (succ k) x ys | y::ys -> if x = y then k else varpoly (succ k) x ys
type t_builtin = E_mdt of mdt | E_poly of (tau list -> tau) type t_builtin = E_mdt of mdt | E_poly of (tau list -> tau)
let builtin_types = Context.create "Wp.Lang.builtin_types"
let builtins = Hashtbl.create 131 let find_builtin name = Context.get builtin_types name
let adt lt = let adt lt =
try match Hashtbl.find builtins lt.lt_name with try match find_builtin lt.lt_name with
| E_mdt m -> Mtype m | E_mdt m -> Mtype m
| E_poly _ -> assert false | E_poly _ -> assert false
with Not_found -> Atype lt with Not_found -> Atype lt
let atype lt ts = let atype lt ts =
try match Hashtbl.find builtins lt.lt_name with try match find_builtin lt.lt_name with
| E_mdt m -> Logic.Data(Mtype m,ts) | E_mdt m -> Logic.Data(Mtype m,ts)
| E_poly ftau -> ftau ts | E_poly ftau -> ftau ts
with Not_found -> Logic.Data(Atype lt,ts) with Not_found -> Logic.Data(Atype lt,ts)
...@@ -279,30 +280,21 @@ end ...@@ -279,30 +280,21 @@ end
(* --- Datatypes --- *) (* --- Datatypes --- *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
let get_builtin_type ~name ~link ~library = let get_builtin_type ~name =
try match Hashtbl.find builtins name with match find_builtin name with
| E_mdt m -> Mtype m | E_mdt m -> Mtype m
| E_poly _ -> assert false | E_poly _ -> assert false
with Not_found ->
let m = new_extern ~link ~library ~debug:name in
Hashtbl.add builtins name (E_mdt m) ; Mtype m
let set_builtin_type ~name ~link ~library =
let m = new_extern ~link ~library ~debug:name in
Hashtbl.add builtins name (E_mdt m)
let set_builtin_poly ~name f =
Hashtbl.add builtins name (E_poly f)
let mem_builtin_type ~name = let mem_builtin_type ~name =
Hashtbl.mem builtins name try ignore (find_builtin name) ; true
with Not_found -> false
let is_builtin lt = Hashtbl.mem builtins lt.lt_name let is_builtin lt = mem_builtin_type lt.lt_name
let is_builtin_type ~name = function let is_builtin_type ~name = function
| Data(Mtype m,_) -> | Data(Mtype m,_) ->
begin begin
try match Hashtbl.find builtins name with try match find_builtin name with
| E_mdt m0 -> m == m0 | E_mdt m0 -> m == m0
| _ -> false | _ -> false
with Not_found -> false with Not_found -> false
...@@ -527,6 +519,9 @@ let generated_p ?context name = ...@@ -527,6 +519,9 @@ let generated_p ?context name =
m_source = generated ?context name m_source = generated ?context name
} }
let extern_t name ~link ~library =
new_extern ~link ~library ~debug:name
module Fun = module Fun =
struct struct
......
...@@ -73,6 +73,7 @@ and field = ...@@ -73,6 +73,7 @@ and field =
| Cfield of fieldinfo | Cfield of fieldinfo
and tau = (field,adt) Logic.datatype and tau = (field,adt) Logic.datatype
type t_builtin = E_mdt of mdt | E_poly of (tau list -> tau)
type lfun = type lfun =
| ACSL of Cil_types.logic_info (** Registered in Definition.t, | ACSL of Cil_types.logic_info (** Registered in Definition.t,
...@@ -94,11 +95,9 @@ and source = ...@@ -94,11 +95,9 @@ and source =
| Extern of Engine.link extern | Extern of Engine.link extern
val mem_builtin_type : name:string -> bool val mem_builtin_type : name:string -> bool
val set_builtin_poly : name:string -> (tau list -> tau) -> unit
val set_builtin_type : name:string -> link:string infoprover -> library:string -> unit
val get_builtin_type : name:string -> link:string infoprover -> library:string -> adt
val is_builtin : logic_type_info -> bool val is_builtin : logic_type_info -> bool
val is_builtin_type : name:string -> tau -> bool val is_builtin_type : name:string -> tau -> bool
val get_builtin_type : name:string -> adt
val datatype : library:string -> string -> adt val datatype : library:string -> string -> adt
val record : val record :
link:string infoprover -> library:string -> (string * tau) list -> adt link:string infoprover -> library:string -> (string * tau) list -> adt
...@@ -151,6 +150,9 @@ val generated_f : ?context:bool -> ?category:lfun category -> ...@@ -151,6 +150,9 @@ val generated_f : ?context:bool -> ?category:lfun category ->
val generated_p : ?context:bool -> string -> lfun val generated_p : ?context:bool -> string -> lfun
val extern_t:
string -> link:string infoprover -> library:library -> mdt
(** {2 Sorting and Typing} *) (** {2 Sorting and Typing} *)
val tau_of_comp : compinfo -> tau val tau_of_comp : compinfo -> tau
...@@ -174,6 +176,7 @@ val t_datatype : adt -> tau list -> tau ...@@ -174,6 +176,7 @@ val t_datatype : adt -> tau list -> tau
val pointer : (typ -> tau) Context.value (** type of pointers *) val pointer : (typ -> tau) Context.value (** type of pointers *)
val floats : (c_float -> tau) Context.value (** type of floats *) val floats : (c_float -> tau) Context.value (** type of floats *)
val poly : string list Context.value (** polymorphism *) val poly : string list Context.value (** polymorphism *)
val builtin_types: (string -> t_builtin) Context.value (* builtin types *)
val parameters : (lfun -> sort list) -> unit (** definitions *) val parameters : (lfun -> sort list) -> unit (** definitions *)
val name_of_lfun : lfun -> string val name_of_lfun : lfun -> string
......
...@@ -106,6 +106,7 @@ type driver = { ...@@ -106,6 +106,7 @@ type driver = {
description : string; description : string;
includes : string list; includes : string list;
hlogic : (string , sigfun list) Hashtbl.t; hlogic : (string , sigfun list) Hashtbl.t;
htypes : (string , t_builtin) Hashtbl.t;
hdeps : (string, string list) Hashtbl.t; hdeps : (string, string list) Hashtbl.t;
hoptions : hoptions :
(string (* library *) * string (* group *) * string (* name *), string list) (string (* library *) * string (* group *) * string (* name *), string list)
...@@ -168,6 +169,12 @@ let register ?source name kinds link = ...@@ -168,6 +169,12 @@ let register ?source name kinds link =
let entry = (kinds,link) in let entry = (kinds,link) in
Hashtbl.add driver.hlogic name (entry::sigs) Hashtbl.add driver.hlogic name (entry::sigs)
let register_type ?source name builtin =
let driver = cdriver_rw () in
if Hashtbl.mem driver.htypes name then
Wp_parameters.warning ?source "Redifinition of type %s" name ;
Hashtbl.add driver.htypes name builtin
let iter_table f = let iter_table f =
let items = ref [] in let items = ref [] in
Hashtbl.iter Hashtbl.iter
...@@ -239,12 +246,12 @@ let add_ctor ~source name kinds ~library ~link () = ...@@ -239,12 +246,12 @@ let add_ctor ~source name kinds ~library ~link () =
let lfun = Lang.extern_s ~library ~category ~params ~link name in let lfun = Lang.extern_s ~library ~category ~params ~link name in
register ~source name kinds (LFUN lfun) register ~source name kinds (LFUN lfun)
let add_type ~source name ~library ?(link=Lang.infoprover name) () = let add_type ?source name ~library ?(link=Lang.infoprover name) () =
if Lang.mem_builtin_type ~name then let mdt = Lang.extern_t name ~link ~library in
Wp_parameters.warning ~source "Redefinition of type '%s'" name ; register_type ?source name (E_mdt mdt)
Lang.set_builtin_type ~name ~library ~link
let hack_type name poly = Lang.set_builtin_poly ~name poly let hack_type name poly =
register_type name (E_poly poly)
type sanitizer = driver_dir:string -> string -> string type sanitizer = driver_dir:string -> string -> string
let sanitizers : ( string * string , sanitizer ) Hashtbl.t = Hashtbl.create 10 let sanitizers : ( string * string , sanitizer ) Hashtbl.t = Hashtbl.create 10
...@@ -298,6 +305,7 @@ let builtin_driver = { ...@@ -298,6 +305,7 @@ let builtin_driver = {
description = "builtin driver"; description = "builtin driver";
includes = []; includes = [];
hlogic = Hashtbl.create 131; hlogic = Hashtbl.create 131;
htypes = Hashtbl.create 131;
hdeps = Hashtbl.create 31; hdeps = Hashtbl.create 31;
hoptions = Hashtbl.create 131; hoptions = Hashtbl.create 131;
locked = false locked = false
...@@ -310,6 +318,25 @@ let add_builtin name kinds lfun = ...@@ -310,6 +318,25 @@ let add_builtin name kinds lfun =
else else
Context.bind driver builtin_driver (register name kinds) phi Context.bind driver builtin_driver (register name kinds) phi
let add_type ?source name ~library ?link () =
if Context.defined driver then
add_type ?source name ~library ?link ()
else
Context.bind driver builtin_driver
(add_type ?source name ~library ?link) ()
let hack_type name poly =
if Context.defined driver then hack_type name poly
else Context.bind driver builtin_driver hack_type name poly
let find_type name =
Hashtbl.find (cdriver_ro ()).htypes name
let find_type name =
if Context.defined driver then find_type name
else Context.bind driver builtin_driver find_type name
let () = Context.set Lang.builtin_types find_type
let new_driver ~id ?(base=builtin_driver) let new_driver ~id ?(base=builtin_driver)
?(descr=id) ?(includes=[]) ?(configure=fun () -> ()) () = ?(descr=id) ?(includes=[]) ?(configure=fun () -> ()) () =
lock base ; lock base ;
...@@ -318,6 +345,7 @@ let new_driver ~id ?(base=builtin_driver) ...@@ -318,6 +345,7 @@ let new_driver ~id ?(base=builtin_driver)
description = descr ; description = descr ;
includes = includes @ base.includes ; includes = includes @ base.includes ;
hlogic = Hashtbl.copy base.hlogic ; hlogic = Hashtbl.copy base.hlogic ;
htypes = Hashtbl.copy base.htypes ;
hdeps = Hashtbl.copy base.hdeps ; hdeps = Hashtbl.copy base.hdeps ;
hoptions = Hashtbl.copy base.hoptions ; hoptions = Hashtbl.copy base.hoptions ;
locked = false locked = false
......
...@@ -77,7 +77,7 @@ val add_library : string -> string list -> unit ...@@ -77,7 +77,7 @@ val add_library : string -> string list -> unit
val add_alias : source:Filepath.position -> string -> kind list -> alias:string -> unit -> unit val add_alias : source:Filepath.position -> string -> kind list -> alias:string -> unit -> unit
val add_type : source:Filepath.position -> string -> library:string -> val add_type : ?source:Filepath.position -> string -> library:string ->
?link:string infoprover -> unit -> unit ?link:string infoprover -> unit -> unit
val add_ctor : source:Filepath.position -> string -> kind list -> val add_ctor : source:Filepath.position -> string -> kind list ->
......
...@@ -53,7 +53,8 @@ let l_repeat = Lang.(E.({ ...@@ -53,7 +53,8 @@ let l_repeat = Lang.(E.({
(*--- Typechecking ---*) (*--- Typechecking ---*)
let a_list = Lang.get_builtin_type ~library ~name:t_list ~link:l_list let () = LogicBuiltins.add_type t_list ~library ~link:l_list ()
let a_list = Lang.get_builtin_type t_list
let vlist_get_tau = function let vlist_get_tau = function
| None -> invalid_arg "a list operator without result type" | None -> invalid_arg "a list operator without result type"
......
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