mlw_dexpr.mli 4.82 KB
Newer Older
1 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
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
(*  Copyright 2010-2013   --   INRIA - CNRS - Paris-Sud University  *)
(*                                                                  *)
(*  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.                           *)
(*                                                                  *)
(********************************************************************)

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 50
  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

51
(** Binders *)
52 53 54

type ghost = bool

55 56
type opaque = Stv.t

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

59 60
(** Specifications *)

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

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

75 76 77 78 79 80
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. *)

81 82 83 84 85 86 87 88
type dtype_v =
  | DSpecV of dity
  | DSpecA of dbinder list * dtype_c

and dtype_c = dtype_v * dspec later

(** Expressions *)

89 90
type dinvariant = term list

91 92 93 94 95 96 97 98 99 100 101 102 103 104
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
105
  | DEapply of dexpr * dexpr
106
  | DEconst of Number.constant
107 108
  | DElet of dlet_defn * dexpr
  | DEfun of dfun_defn * dexpr
109
  | DErec of drec_defn * dexpr
110
  | DEif of dexpr * dexpr * dexpr
Andrei Paskevich's avatar
Andrei Paskevich committed
111
  | DEcase of dexpr * (dpattern * dexpr) list
112 113 114 115 116 117 118
  | 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
119 120
  | DEfor of preid * dexpr * for_direction * dexpr * dinvariant later * dexpr
  | DEloop of (variant list * dinvariant) later * dexpr
121 122 123 124 125 126 127 128 129 130 131 132
  | DEabsurd
  | DEassert of assertion_kind * term later
  | DEabstract of dexpr * dspec later
  | DEmark of preid * dexpr
  | DEghost of dexpr
  | DEany of dtype_c
  | DEcast of dexpr * ity
  | DEuloc of dexpr * Loc.position
  | DElabel of dexpr * Slab.t

and dlet_defn = preid * ghost * dexpr

133
and dfun_defn = preid * ghost * dbinder list * dexpr * dspec later
134

135 136
and drec_defn = private { fds : dfun_defn list }

137 138
type dval_decl = preid * ghost * dtype_v

139 140 141 142 143 144
(** Environment *)

type denv

val denv_empty : denv

Andrei Paskevich's avatar
Andrei Paskevich committed
145 146
val denv_add_var : denv -> preid -> dity -> denv

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
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

165 166 167 168 169
type pre_fun_defn =
  preid * ghost * dbinder list * dity * (denv -> dexpr * dspec later)

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

170 171
(** Final stage *)

172 173 174 175 176 177 178 179 180 181
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 ->
182
  Decl.known_map -> Mlw_decl.known_map -> drec_defn -> fun_defn list
183 184 185

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