2010-06-15 14:05:26 +02:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Author : Marc Pouzet *)
|
|
|
|
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2010-07-05 12:13:57 +02:00
|
|
|
|
2010-06-15 14:05:26 +02:00
|
|
|
open Names
|
2010-07-08 17:41:00 +02:00
|
|
|
open Misc
|
2010-07-05 16:55:14 +02:00
|
|
|
open Location
|
2010-07-05 12:13:57 +02:00
|
|
|
|
2010-07-05 16:55:14 +02:00
|
|
|
type static_exp = { se_desc: static_exp_desc; se_ty: ty; se_loc: location }
|
|
|
|
|
|
|
|
and static_exp_desc =
|
2010-07-07 15:11:32 +02:00
|
|
|
| Svar of constant_name
|
2010-07-05 12:13:57 +02:00
|
|
|
| Sint of int
|
|
|
|
| Sfloat of float
|
|
|
|
| Sbool of bool
|
2010-07-07 15:11:32 +02:00
|
|
|
| Sconstructor of constructor_name
|
2010-07-05 12:13:57 +02:00
|
|
|
| Stuple of static_exp list
|
|
|
|
| Sarray_power of static_exp * static_exp (** power : 0^n : [0,0,0,0,0,..] *)
|
|
|
|
| Sarray of static_exp list (** [ e1, e2, e3 ] *)
|
2010-07-07 15:11:32 +02:00
|
|
|
| Srecord of (field_name * static_exp) list (** { f1 = e1; f2 = e2; ... } *)
|
|
|
|
| Sop of fun_name * static_exp list (** defined ops for now in pervasives *)
|
2010-06-15 14:05:26 +02:00
|
|
|
|
2010-07-07 15:11:32 +02:00
|
|
|
and ty = | Tprod of ty list | Tid of type_name | Tarray of ty * static_exp
|
2010-07-07 12:15:02 +02:00
|
|
|
|
2010-06-16 17:03:45 +02:00
|
|
|
let invalid_type = Tprod []
|
2010-06-15 14:05:26 +02:00
|
|
|
|
2010-07-21 17:19:51 +02:00
|
|
|
let prod = function
|
|
|
|
| [] -> assert false
|
|
|
|
| [ty] -> ty
|
|
|
|
| ty_list -> Tprod ty_list
|
|
|
|
|
2010-08-03 22:38:42 +02:00
|
|
|
(** DO NOT use this after the typing, since it gives invalid_type *)
|
2010-07-07 15:11:32 +02:00
|
|
|
let mk_static_exp ?(loc = no_location) ?(ty = invalid_type) desc =
|
2010-07-05 16:55:14 +02:00
|
|
|
{ se_desc = desc; se_ty = ty; se_loc = loc }
|
2010-06-16 19:31:51 +02:00
|
|
|
|
2010-07-08 17:41:00 +02:00
|
|
|
|
2010-06-16 19:31:51 +02:00
|
|
|
open Pp_tools
|
|
|
|
open Format
|
|
|
|
|
2010-07-07 15:11:32 +02:00
|
|
|
let rec print_static_exp ff se = match se.se_desc with
|
|
|
|
| Sint i -> fprintf ff "%d" i
|
|
|
|
| Sbool b -> fprintf ff "%b" b
|
|
|
|
| Sfloat f -> fprintf ff "%f" f
|
|
|
|
| Sconstructor ln -> print_longname ff ln
|
|
|
|
| Svar id -> fprintf ff "%a" print_longname id
|
|
|
|
| Sop (op, se_list) ->
|
|
|
|
fprintf ff "@[<2>%a@,%a@]"
|
|
|
|
print_longname op print_static_exp_tuple se_list
|
|
|
|
| Sarray_power (se, n) ->
|
|
|
|
fprintf ff "%a^%a" print_static_exp se print_static_exp n
|
|
|
|
| Sarray se_list ->
|
|
|
|
fprintf ff "@[<2>%a@]" (print_list_r print_static_exp "["";""]") se_list
|
|
|
|
| Stuple se_list -> print_static_exp_tuple ff se_list
|
|
|
|
| Srecord f_se_list ->
|
|
|
|
print_record (print_couple print_longname
|
|
|
|
print_static_exp """ = """) ff f_se_list
|
|
|
|
|
|
|
|
and print_static_exp_tuple ff l =
|
|
|
|
fprintf ff "@[<2>%a@]" (print_list_r print_static_exp "("","")") l
|
|
|
|
|
|
|
|
and print_type ff = function
|
2010-06-16 19:31:51 +02:00
|
|
|
| Tprod ty_list ->
|
|
|
|
fprintf ff "@[<hov2>%a@]" (print_list_r print_type "(" " *" ")") ty_list
|
|
|
|
| Tid id -> print_longname ff id
|
|
|
|
| Tarray (ty, n) ->
|
2010-06-30 17:20:56 +02:00
|
|
|
fprintf ff "@[<hov2>%a^%a@]" print_type ty print_static_exp n
|