theory.mli 6.07 KB
Newer Older
1 2
(**************************************************************************)
(*                                                                        *)
3
(*  Copyright (C) 2010-2011                                               *)
4 5 6
(*    François Bobot                                                      *)
(*    Jean-Christophe Filliâtre                                           *)
(*    Claude Marché                                                       *)
7 8 9 10 11 12 13 14 15 16 17 18 19
(*    Andrei Paskevich                                                    *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2.1, with the special exception on linking            *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software 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.                  *)
(*                                                                        *)
(**************************************************************************)

20
open Stdlib
21
open Util
22

MARCHE Claude's avatar
MARCHE Claude committed
23 24
(** Theories and Namespaces *)

25 26 27
open Ident
open Ty
open Term
28
open Decl
29

30
type namespace = private {
31 32 33 34
  ns_ts : tysymbol Mstr.t;   (* type symbols *)
  ns_ls : lsymbol Mstr.t;    (* logic symbols *)
  ns_pr : prsymbol Mstr.t;   (* propositions *)
  ns_ns : namespace Mstr.t;  (* inner namespaces *)
35 36
}

37 38 39
val ns_find_ts : namespace -> string list -> tysymbol
val ns_find_ls : namespace -> string list -> lsymbol
val ns_find_pr : namespace -> string list -> prsymbol
40
val ns_find_ns : namespace -> string list -> namespace
41

42 43 44
(** Meta properties *)

type meta_arg_type =
45
  | MTty
46 47 48 49 50 51 52
  | MTtysymbol
  | MTlsymbol
  | MTprsymbol
  | MTstring
  | MTint

type meta_arg =
53
  | MAty  of ty
54 55 56 57 58 59
  | MAts  of tysymbol
  | MAls  of lsymbol
  | MApr  of prsymbol
  | MAstr of string
  | MAint of int

60 61 62 63 64 65
type meta = private {
  meta_name : string;
  meta_type : meta_arg_type list;
  meta_excl : bool;
  meta_tag  : int;
}
66

67
module Mmeta : Map.S with type key = meta
68
module Smeta : Mmeta.Set
69
module Hmeta : Hashtbl.S with type key = meta
70

71
val meta_equal : meta -> meta -> bool
Andrei Paskevich's avatar
Andrei Paskevich committed
72
val meta_hash : meta -> int
73 74 75

val register_meta      : string -> meta_arg_type list -> meta
val register_meta_excl : string -> meta_arg_type list -> meta
François Bobot's avatar
François Bobot committed
76 77
(** Register exclusive meta, each new setting remove the previous one.
Useful for transformation or printer parameters *)
78

79 80
val lookup_meta : string -> meta
val list_metas  : unit -> meta list
81

82
(** Theory *)
83

84
type theory = private {
85
  th_name   : ident;      (* theory name *)
86
  th_path   : string list;(* environment qualifiers *)
87 88 89 90 91 92 93 94 95 96
  th_decls  : tdecl list; (* theory declarations *)
  th_export : namespace;  (* exported namespace *)
  th_known  : known_map;  (* known identifiers *)
  th_local  : Sid.t;      (* locally declared idents *)
  th_used   : Sid.t;      (* used theories *)
}

and tdecl = private {
  td_node : tdecl_node;
  td_tag  : int;
97
}
98

99
and tdecl_node = private
100 101
  | Decl  of decl
  | Use   of theory
102
  | Clone of theory * symbol_map
103
  | Meta  of meta * meta_arg list
104

105 106 107 108 109 110
and symbol_map = {
  sm_ts : tysymbol Mts.t;
  sm_ls : lsymbol Mls.t;
  sm_pr : prsymbol Mpr.t;
}

111
module Mtdecl : Map.S with type key = tdecl
112
module Stdecl : Mtdecl.Set
113
module Htdecl : Hashtbl.S with type key = tdecl
114

115
val td_equal : tdecl -> tdecl -> bool
Andrei Paskevich's avatar
Andrei Paskevich committed
116
val td_hash : tdecl -> int
117

118
(** Constructors and utilities *)
119

120
type theory_uc  (* a theory under construction *)
121

122
val create_theory : ?path:string list -> preid -> theory_uc
123
val close_theory  : theory_uc -> theory
124

125 126
val open_namespace  : theory_uc -> theory_uc
val close_namespace : theory_uc -> bool -> string option -> theory_uc
127
  (* the Boolean indicates [import]; the string option indicates [as T] *)
128

129
val get_namespace : theory_uc -> namespace
130 131 132
val get_known : theory_uc -> known_map

(** Declaration constructors *)
133

134 135 136
val create_decl : decl -> tdecl

val add_decl : theory_uc -> decl -> theory_uc
137 138 139 140

val add_ty_decl : theory_uc -> ty_decl list -> theory_uc
val add_logic_decl : theory_uc -> logic_decl list -> theory_uc
val add_ind_decl : theory_uc -> ind_decl list -> theory_uc
141
val add_prop_decl : theory_uc -> prop_kind -> prsymbol -> term -> theory_uc
142

143 144 145 146 147
(** Use *)

val create_use : theory -> tdecl
val use_export : theory_uc -> theory -> theory_uc

Andrei Paskevich's avatar
Andrei Paskevich committed
148
(** Clone *)
149 150

type th_inst = {
Francois Bobot's avatar
 
Francois Bobot committed
151
  inst_ts    : tysymbol Mts.t; (* old to new *)
152 153 154 155 156 157 158
  inst_ls    : lsymbol  Mls.t;
  inst_lemma : Spr.t;
  inst_goal  : Spr.t;
}

val empty_inst : th_inst

Andrei Paskevich's avatar
Andrei Paskevich committed
159 160 161 162 163 164
val create_inst :
  ts    : (tysymbol * tysymbol) list ->
  ls    : (lsymbol  * lsymbol)  list ->
  lemma : prsymbol list ->
  goal  : prsymbol list -> th_inst

165
val clone_theory : ('a -> tdecl -> 'a) -> 'a -> theory -> th_inst -> 'a
166 167 168

val create_clone : tdecl list -> theory -> th_inst -> tdecl list

169
val clone_export : theory_uc -> theory -> th_inst -> theory_uc
170 171 172

val create_null_clone : theory -> tdecl

173 174
val is_empty_sm : symbol_map -> bool

175 176
(** Meta *)

177
val create_meta : meta -> meta_arg list -> tdecl
178

179
val add_meta : theory_uc -> meta -> meta_arg list -> theory_uc
180

181 182 183
val clone_meta : tdecl -> symbol_map -> tdecl
(* [clone_meta td_meta sm] produces from [td_meta]
 * a new Meta tdecl instantiated with respect to [sm]]. *)
184

185
(*
186
val on_meta: meta-> ('a -> meta_arg list -> 'a) -> 'a -> theory -> 'a
187
*)
188

189 190 191 192
(** Base theories *)

val builtin_theory : theory

193 194
val bool_theory : theory

195 196
val highord_theory : theory

197
val tuple_theory : int -> theory
198

199 200
val tuple_theory_name : string -> int option

201 202
val add_decl_with_tuples : theory_uc -> decl -> theory_uc

203
(* exceptions *)
204

205 206 207
exception NonLocal of ident
exception CannotInstantiate of ident
exception BadInstance of ident * ident
208

209 210 211
exception CloseTheory
exception NoOpenedNamespace
exception ClashSymbol of string
212

213
exception KnownMeta of meta
214
exception UnknownMeta of string
215 216
exception BadMetaArity of meta * int * int
exception MetaTypeMismatch of meta * meta_arg_type * meta_arg_type
217