123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140(*-----------------------------------------------------------------------
** Copyright (C) - Verimag.
** This file may only be copied under the terms of the CeCill
** Public License
**-----------------------------------------------------------------------
**
** File: type.ml
** Author: erwan.jahier@univ-grenoble-alpes.fr
*)typeenum_value=stringtypefield=stringtypet=|BoolT|IntT|FloatT|UTofstructuredandstructured=|ArrayTofint*t|StructTof(field*t)list|EnumTofenum_valuelistletrec(typ_to_string_param:string->t->string)=funfloatvt->matchvtwithBoolT->"bool"|IntT->"int"|FloatT->float|UT(ut)->structured_to_string_paramfloatutand(structured_to_string_param:string->structured->string)=funfloatut->matchutwith|ArrayT(i,t)->((typ_to_string_paramfloatt)^"^"^(string_of_inti))|StructT(fl)->((List.fold_left(funacc(fn,ft)->(acc^fn^":"^(typ_to_string_paramfloatft)^"; "))"{"fl)^"}")|EnumT(el)->(let_=assert(el<>[])in(List.fold_left(funacce->(acc^", "^e))("("^(List.hdel))(List.tlel))^")")letto_string=typ_to_string_param"float"letto_string2=typ_to_string_param"real"letto_string3=typ_to_string_param"double"letstructured_to_string=structured_to_string_param"real"(****************************************************************************)(* exported *)letrec(to_cstring:t->string)=funvt->matchvtwithBoolT->"_bool"|IntT->"_int"|FloatT->"_real"|UT(ut)->structured_to_cstringutand(structured_to_cstring:structured->string)=funut->matchutwith|ArrayT(i,t)->((to_cstringt)^"^"^(string_of_inti))|StructT(fl)->((List.fold_left(funacc(fn,ft)->(acc^fn^":"^(to_cstringft)^"; "))"{"fl)^"}")|EnumT(el)->(let_=assert(el<>[])in(List.fold_left(funacce->(acc^", "^e))("("^(List.hdel))(List.tlel))^")")(* exported *)letrec(to_cstring_bis:t->string)=funvt->matchvtwithBoolT->"bool"|IntT->"int"|FloatT->"real"|UT(ut)->structured_to_cstring_bisutand(structured_to_cstring_bis:structured->string)=funut->matchutwith|ArrayT(i,t)->((to_cstring_bist)^"^"^(string_of_inti))|StructT(fl)->((List.fold_left(funacc(fn,ft)->(acc^fn^":"^(to_cstring_bisft)^"; "))"{"fl)^"}")|EnumT(el)->(let_=assert(el<>[])in(List.fold_left(funacce->(acc^", "^e))("("^(List.hdel))(List.tlel))^")")letrec(to_data_t:t->Data.t)=function|BoolT->Data.Bool|IntT->Data.Int|FloatT->Data.Real|UT(ArrayT(n,a))->Data.Array(to_data_ta,n)|UT(StructTfl)->Data.Struct("struct",(List.map(fun(id,t)->id,to_data_tt)fl))|UT(EnumTel)->Data.Enum("enum",el)