mlw_dexpr.mli 5.02 KB
Newer Older
1 2 3
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
Andrei Paskevich's avatar
Andrei Paskevich committed
4
(*  Copyright 2010-2016   --   INRIA - CNRS - Paris-Sud University  *)
5 6 7 8
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
9
(*                                                                  *)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(********************************************************************)

open Stdlib
open Ident
open Ty
open Term
open Mlw_ty
open Mlw_ty.T
open Mlw_expr

(** Program types *)

type dity

val dity_fresh : unit -> dity

val dity_of_ity : ity -> dity

type dvty = dity list * dity (* A -> B -> C == ([A;B],C) *)

30 31 32 33
val dity_is_bool : dity -> bool

val dvty_is_chainable : dvty -> bool

34 35 36 37 38
(** Patterns *)

type dpattern = private {
  dp_pat  : pre_ppattern;
  dp_dity : dity;
39
  dp_vars : dity Mstr.t;
40 41 42 43 44 45 46 47 48 49
  dp_loc  : Loc.position option;
}

type dpattern_node =
  | DPwild
  | DPvar  of preid
  | DPlapp of lsymbol * dpattern list
  | DPpapp of plsymbol * dpattern list
  | DPor   of dpattern * dpattern
  | DPas   of dpattern * preid
50
  | DPcast of dpattern * ity
51

52
(** Binders *)
53 54 55

type ghost = bool

56 57
type opaque = Stv.t

58
type dbinder = preid option * ghost * opaque * dity
59

60 61
(** Specifications *)

62
type 'a later = vsymbol Mstr.t -> 'a
63
  (* Specification terms are parsed and typechecked after the program
64 65 66
     expressions, when the types of locally bound program variables are
     already established. *)

67 68 69 70
type dspec_final = {
  ds_pre     : term list;
  ds_post    : (vsymbol option * term) list;
  ds_xpost   : (vsymbol option * term) list Mexn.t;
71 72 73
  ds_reads   : vsymbol list;
  ds_writes  : term list;
  ds_variant : variant list;
74 75
  ds_checkrw : bool;
  ds_diverge : bool;
76 77
}

78 79 80 81 82 83
type dspec = ty -> dspec_final
  (* Computation specification is also parametrized by the result type.
     All vsymbols in the postcondition clauses in the [ds_post] field
     must have this type. All vsymbols in the exceptional postcondition
     clauses must have the type of the corresponding exception. *)

84 85 86 87 88 89 90 91
type dtype_v =
  | DSpecV of dity
  | DSpecA of dbinder list * dtype_c

and dtype_c = dtype_v * dspec later

(** Expressions *)

92 93
type dinvariant = term list

94 95 96 97 98 99 100 101 102 103 104 105 106 107
type dlazy_op = DEand | DEor

type dexpr = private {
  de_node : dexpr_node;
  de_dvty : dvty;
  de_loc  : Loc.position option;
}

and dexpr_node =
  | DEvar of string * dvty
  | DEgpvar of pvsymbol
  | DEgpsym of psymbol
  | DEplapp of plsymbol * dexpr list
  | DElsapp of lsymbol * dexpr list
108
  | DEapply of dexpr * dexpr
109
  | DEconst of Number.constant
110
  | DElam of dbinder list * dexpr * dspec later
111 112
  | DElet of dlet_defn * dexpr
  | DEfun of dfun_defn * dexpr
113
  | DErec of drec_defn * dexpr
114
  | DEif of dexpr * dexpr * dexpr
Andrei Paskevich's avatar
Andrei Paskevich committed
115
  | DEcase of dexpr * (dpattern * dexpr) list
116 117 118 119 120 121 122
  | DEassign of plsymbol * dexpr * dexpr
  | DElazy of dlazy_op * dexpr * dexpr
  | DEnot of dexpr
  | DEtrue
  | DEfalse
  | DEraise of xsymbol * dexpr
  | DEtry of dexpr * (xsymbol * dpattern * dexpr) list
123
  | DEfor of preid * dexpr * for_direction * dexpr * dinvariant later * dexpr
124
  | DEwhile of dexpr * (variant list * dinvariant) later * dexpr
125
  | DEloop of (variant list * dinvariant) later * dexpr
126 127 128 129 130
  | DEabsurd
  | DEassert of assertion_kind * term later
  | DEabstract of dexpr * dspec later
  | DEmark of preid * dexpr
  | DEghost of dexpr
131
  | DEany of dtype_v * dspec later option
132 133 134 135 136 137
  | DEcast of dexpr * ity
  | DEuloc of dexpr * Loc.position
  | DElabel of dexpr * Slab.t

and dlet_defn = preid * ghost * dexpr

138
and dfun_defn = preid * ghost * dbinder list * dexpr * dspec later
139

140 141
and drec_defn = private { fds : dfun_defn list }

142 143
type dval_decl = preid * ghost * dtype_v

144 145 146 147 148 149
(** Environment *)

type denv

val denv_empty : denv

Andrei Paskevich's avatar
Andrei Paskevich committed
150 151
val denv_add_var : denv -> preid -> dity -> denv

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
val denv_add_let : denv -> dlet_defn -> denv

val denv_add_fun : denv -> dfun_defn -> denv

val denv_add_args : denv -> dbinder list -> denv

val denv_add_pat : denv -> dpattern -> denv

val denv_get : denv -> string -> dexpr_node (** raises UnboundVar *)

val denv_get_opt : denv -> string -> dexpr_node option

(** Constructors *)

val dpattern : ?loc:Loc.position -> dpattern_node -> dpattern

val dexpr : ?loc:Loc.position -> dexpr_node -> dexpr

170 171 172 173 174
type pre_fun_defn =
  preid * ghost * dbinder list * dity * (denv -> dexpr * dspec later)

val drec_defn : denv -> pre_fun_defn list -> denv * drec_defn

175 176
(** Final stage *)

177 178 179 180 181 182 183 184 185 186
val expr : keep_loc:bool ->
  Decl.known_map -> Mlw_decl.known_map -> dexpr -> expr

val let_defn : keep_loc:bool ->
  Decl.known_map -> Mlw_decl.known_map -> dlet_defn -> let_defn

val fun_defn : keep_loc:bool ->
  Decl.known_map -> Mlw_decl.known_map -> dfun_defn -> fun_defn

val rec_defn : keep_loc:bool ->
187
  Decl.known_map -> Mlw_decl.known_map -> drec_defn -> fun_defn list
188 189 190

val val_decl : keep_loc:bool ->
  Decl.known_map -> Mlw_decl.known_map -> dval_decl -> let_sym