123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146(**************************************************************************)(* *)(* OCaml *)(* *)(* Jacques Garrigue, Graduate School of Mathematics, Nagoya University *)(* *)(* Copyright 2003 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Print a raw type expression, with sharing *)openFormatopenTypesletlongident=Pprintast.longidentletraw_listprppf=function[]->fprintfppf"[]"|a::l->fprintfppf"@[<1>[%a%t]@]"pra(funppf->List.iter(funx->fprintfppf";@,%a"prx)l)letkind_vars=ref[]letkind_count=ref0letstring_of_field_kindv=matchfield_kind_reprvwith|Fpublic->"Fpublic"|Fabsent->"Fabsent"|Fprivate->"Fprivate"letrecsafe_reprvt=matchTransient_expr.coercetwith{desc=Tlinkt}whennot(List.memqtv)->safe_repr(t::v)t|t'->t'letreclist_of_memo=functionMnil->[]|Mcons(_priv,p,_t1,_t2,rem)->p::list_of_memorem|Mlinkrem->list_of_memo!remletprint_nameppf=functionNone->fprintfppf"None"|Somename->fprintfppf"\"%s\""nameletpath=Format_doc.compatPath.printletvisited=ref[]letrecraw_typeppfty=letty=safe_repr[]tyinifList.memqty!visitedthenfprintfppf"{id=%d}"ty.idelsebeginvisited:=ty::!visited;fprintfppf"@[<1>{id=%d;level=%d;scope=%d;marks=%x;desc=@,%a}@]"ty.idty.level(Transient_expr.get_scopety)(Transient_expr.get_marksty)raw_type_descty.descendandraw_type_listtl=raw_listraw_typetlandraw_lid_type_listtl=raw_list(funppf(lid,typ)->fprintfppf"(@,%a,@,%a)"longidentlidraw_typetyp)tlandraw_type_descppf=functionTvarname->fprintfppf"Tvar %a"print_namename|Tarrow(l,t1,t2,c)->fprintfppf"@[<hov1>Tarrow(\"%s\",@,%a,@,%a,@,%s)@]"(Asttypes.string_of_labell)raw_typet1raw_typet2(ifis_commu_okcthen"Cok"else"Cunknown")|Ttupletl->fprintfppf"@[<1>Ttuple@,%a@]"raw_type_listtl|Tconstr(p,tl,abbrev)->fprintfppf"@[<hov1>Tconstr(@,%a,@,%a,@,%a)@]"pathpraw_type_listtl(raw_listpath)(list_of_memo!abbrev)|Tobject(t,nm)->fprintfppf"@[<hov1>Tobject(@,%a,@,@[<1>ref%t@])@]"raw_typet(funppf->match!nmwithNone->fprintfppf" None"|Some(p,tl)->fprintfppf"(Some(@,%a,@,%a))"pathpraw_type_listtl)|Tfield(f,k,t1,t2)->fprintfppf"@[<hov1>Tfield(@,%s,@,%s,@,%a,@;<0 -1>%a)@]"f(string_of_field_kindk)raw_typet1raw_typet2|Tnil->fprintfppf"Tnil"|Tlinkt->fprintfppf"@[<1>Tlink@,%a@]"raw_typet|Tsubst(t,None)->fprintfppf"@[<1>Tsubst@,(%a,None)@]"raw_typet|Tsubst(t,Somet')->fprintfppf"@[<1>Tsubst@,(%a,@ Some%a)@]"raw_typetraw_typet'|Tunivarname->fprintfppf"Tunivar %a"print_namename|Tpoly(t,tl)->fprintfppf"@[<hov1>Tpoly(@,%a,@,%a)@]"raw_typetraw_type_listtl|Tvariantrow->letRow{fields;more;name;fixed;closed}=row_reprrowinfprintfppf"@[<hov1>{@[%s@,%a;@]@ @[%s@,%a;@]@ %s%B;@ %s%a;@ @[<1>%s%t@]}@]""row_fields="(raw_list(funppf(l,f)->fprintfppf"@[%s,@ %a@]"lraw_fieldf))fields"row_more="raw_typemore"row_closed="closed"row_fixed="raw_row_fixedfixed"row_name="(funppf->matchnamewithNone->fprintfppf"None"|Some(p,tl)->fprintfppf"Some(@,%a,@,%a)"pathpraw_type_listtl)|Tpackage(p,fl)->fprintfppf"@[<hov1>Tpackage(@,%a,@,%a)@]"pathpraw_lid_type_listflandraw_row_fixedppf=function|None->fprintfppf"None"|SomeTypes.Fixed_private->fprintfppf"Some Fixed_private"|SomeTypes.Rigid->fprintfppf"Some Rigid"|SomeTypes.Univart->fprintfppf"Some(Univar(%a))"raw_typet|SomeTypes.Reifiedp->fprintfppf"Some(Reified(%a))"pathpandraw_fieldppfrf=match_row_field~absent:(fun_->fprintfppf"RFabsent")~present:(function|None->fprintfppf"RFpresent None"|Somet->fprintfppf"@[<1>RFpresent(Some@,%a)@]"raw_typet)~either:(functlm(_,e)->fprintfppf"@[<hov1>RFeither(%B,@,%a,@,%B,@,@[<1>ref%t@])@]"craw_type_listtlm(funppf->matchewithNone->fprintfppf" RFnone"|Somef->fprintfppf"@,@[<1>(%a)@]"raw_fieldf))rflettype_exprppft=visited:=[];kind_vars:=[];kind_count:=0;raw_typeppft;visited:=[];kind_vars:=[]