Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file pp.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161(*****************************************************************************)(* Open Source License *)(* Copyright (c) 2021 Valentin Chaboche *)(* Copyright (c) 2021 Nomadic Labs, <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openPpxlib(* ------------------------------------------------ *)(* ------------ Print type_declaration ------------ *)(* ------------------------------------------------ *)letlist_to_str?(sep=" ; ")?(left="[")?(right="]")fl=letrecaux=function|[]->""|[x]->fx|x::xs->fx^sep^auxxsinPrintf.sprintf"%s %s %s"left(auxl)rightletrectype_decl_to_strtd=Printf.sprintf{|
{
ptype_name : %s;
ptype_params : %s;
ptype_cstrs : %s;
ptype_kind : %s;
ptype_private : %s;
ptype_manifest : %s;
ptype_attributes : %s;
ptype_loc : %s
}
|}td.ptype_name.txt(type_params_to_strtd.ptype_params)(type_cstrs_to_strtd.ptype_cstrs)(type_kind_to_strtd.ptype_kind)(private_to_strtd.ptype_private)(manifest_to_strtd.ptype_manifest)(attributes_to_strtd.ptype_attributes)"loc not printed"andtype_cstr_to_str(x,y,_)=Printf.sprintf"(%s, %s, _)"(core_type_to_strx)(core_type_to_stry)andtype_cstrs_to_strcstrs=list_to_strtype_cstr_to_strcstrsandtype_param_to_str(ct,(variance,injectivity))=Printf.sprintf"(%s, (%s, %s))"(core_type_to_strct)(variance_to_strvariance)(injectivity_to_strinjectivity)andvariance_to_str=function|Covariant->"covariant"|Contravariant->"contravariant"|NoVariance->"noVariance"andinjectivity_to_str=function|Injective->"injective"|NoInjectivity->"noInjectivity"andtype_params_to_strparams=list_to_strtype_param_to_strparamsandcore_type_to_strct=matchct.ptyp_descwith|Ptyp_constr(id,cts)->Printf.sprintf"K (%s, %s)"(longident_to_strid.txt)(core_types_to_strcts)|Ptyp_poly(strs,ct)->Printf.sprintf"%s (%s)"(list_to_str(funs->s.txt)strs)(core_type_to_strct)|Ptyp_any->"any"|Ptyp_vars->s|Ptyp_tuplects->list_to_str~left:"("~sep:" , "~right:")"core_type_to_strcts|Ptyp_arrow(x,left,right)->letx'=arg_label_to_strxinletleft'=core_type_to_strleftinletright'=core_type_to_strrightinPrintf.sprintf"%s (%s -> %s)"x'left'right'|_->"TODO else core_type"andcore_types_to_strcts=list_to_strcore_type_to_strctsandarg_label_to_str=function|Nolabel->"_"|Labelleds->"~"^s|Optionals->"?"^sandtype_kind_to_str=function|Ptype_abstract->"abstract"(* TODO useful to print here *)|Ptype_variantconstrs->constr_declarations_to_strconstrs|Ptype_recordlabels->list_to_str~left:"{"~right:"}"label_declaration_to_strlabels|Ptype_open->"open"andlabel_declaration_to_strld=letname=ld.pld_name.txtinletmut=matchld.pld_mutablewithMutable->"mutable"|Immutable->"immutable"inletty=core_type_to_strld.pld_typeinPrintf.sprintf"(%s %s : %s)"mutnametyandconstr_declarations_to_strcstrs=list_to_str~sep:"\n"constr_declaration_to_strcstrsandconstr_declaration_to_strcd=Printf.sprintf"{ pcd_name:%s; pcd_args:%s; pcd_res:%s; _ }"cd.pcd_name.txt(constr_args_to_strcd.pcd_args)(Option.fold~none:"None"~some:core_type_to_strcd.pcd_res)andconstr_args_to_str=function(* TODO really print if necessary *)|Pcstr_tuplects->core_types_to_strcts|Pcstr_record_->"Pcstr_record"andattribute_to_strattr=Printf.sprintf"{attr_name : %s; _; _}"attr.attr_name.txtandattributes_to_strattrs=list_to_strattribute_to_strattrsandmanifest_to_strct=Option.fold~none:"None"~some:core_type_to_strctandlongident_to_str=function|Lidents->s|Ldot(lg,s)->Printf.sprintf"%s.%s"(longident_to_strlg)s|Lapply(lg1,lg2)->Printf.sprintf"%s %s"(longident_to_strlg1)(longident_to_strlg2)andprivate_to_str=functionPrivate->"private"|Public->"public"letprint_type_decltd=Printf.printf"%s\n"(type_decl_to_strtd)