Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file migrate_parsetree_ast_io.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(**************************************************************************)(* *)(* OCaml Migrate Parsetree *)(* *)(* Frédéric Bour *)(* *)(* Copyright 2017 Institut National de Recherche en Informatique et *)(* en Automatique (INRIA). *)(* *)(* 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. *)(* *)(**************************************************************************)openResulttypeast=|Impl:(moduleMigrate_parsetree_versions.OCaml_versionwithtypeAst.Parsetree.structure='concrete)*'concrete->ast|Intf:(moduleMigrate_parsetree_versions.OCaml_versionwithtypeAst.Parsetree.signature='concrete)*'concrete->asttypefilename=stringletmagic_length=String.lengthAst_402.Config.ast_impl_magic_numberletread_magicic=letbuf=Bytes.createmagic_lengthinletlen=inputicbuf0magic_lengthinlets=Bytes.sub_stringbuf0leniniflen=magic_lengththenOkselseErrorstyperead_error=|Not_a_binary_astofstring|Unknown_versionofstringletfind_magicmagic=letrecloop=function|[]->letprefix=String.submagic09inifprefix=String.subAst_402.Config.ast_impl_magic_number09||prefix=String.subAst_402.Config.ast_intf_magic_number09thenError(Unknown_versionmagic)elseError(Not_a_binary_astmagic)|(moduleFrontend:Migrate_parsetree_versions.OCaml_version)::tail->ifFrontend.Ast.Config.ast_impl_magic_number=magicthenOk(funx->Impl((moduleFrontend),Obj.objx))elseifFrontend.Ast.Config.ast_intf_magic_number=magicthenOk(funx->Intf((moduleFrontend),Obj.objx))elselooptailinloopMigrate_parsetree_versions.all_versionsletfrom_channelic=matchread_magicicwith|Errors->Error(Not_a_binary_asts)|Oks->matchfind_magicswith|Okinj->letfilename:filename=input_valueicinletpayload=inj(input_valueic)inOk(filename,payload)|Error_ase->eletfrom_bytesbytespos=ifBytes.lengthbytes-pos<magic_lengththenError(Not_a_binary_ast"")elseletmagic=Bytes.to_string(Bytes.subbytesposmagic_length)inmatchfind_magicmagicwith|Okinj->letfilename_pos=pos+magic_lengthinletfilename:filename=Marshal.from_bytesbytesfilename_posinletpayload_pos=filename_pos+Marshal.total_sizebytesfilename_posinletpayload=inj(Marshal.from_bytesbytespayload_pos)inOk(filename,payload)|Error_ase->eletdecompose_ast=function|Impl((moduleFrontend),tree)->(Frontend.Ast.Config.ast_impl_magic_number,Obj.reprtree)|Intf((moduleFrontend),tree)->(Frontend.Ast.Config.ast_intf_magic_number,Obj.reprtree)letto_channeloc(filename:filename)x=letmagic_number,payload=decompose_astxinoutput_stringocmagic_number;output_valueocfilename;output_valueocpayloadletto_bytes(filename:filename)x=letmagic_number,payload=decompose_astxinBytes.cat(Bytes.cat(Bytes.of_stringmagic_number)(Marshal.to_bytesfilename[]))(Marshal.to_bytespayload[])