123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115(* SPDX-License-Identifier: MIT *)(* Copyright (C) 2023-2024 formalsec *)(* Written by the Smtml programmers *)typename=|Simpleofstring|Indexedof{basename:string;indices:stringlist}typenamespace=|Attr|Sort|Term|Vartypet={ty:Ty.t;name:name;namespace:namespace}letattr=Attrletsort=Sortletterm=Termletvar=VarmoduleName=structletsimplename=Simplenameletindexedbasenameindices=Indexed{basename;indices}endlet(@:)(name:string)(ty:Ty.t):t={name=Name.simplename;namespace=term;ty}letname{name;_}=nameletnamespace{namespace;_}=namespaceletdiscr_namespace=functionAttr->0|Sort->1|Term->2|Var->3letcompare_namespaceab=compare(discr_namespacea)(discr_namespaceb)letcompare_nameab=match(a,b)with|Simplea,Simpleb->String.compareab|(Indexed{basename=base1;indices=indices1},Indexed{basename=base2;indices=indices2})->letcompare_base=String.comparebase1base2inifcompare_base=0thenList.compareString.compareindices1indices2elsecompare_base|Simple_,_->-1|Indexed_,_->1letcompareab=letcompare_name=compare_namea.nameb.nameinifcompare_name=0thenletcompare_ty=Ty.comparea.tyb.tyinifcompare_ty=0thencompare_namespacea.namespaceb.namespaceelsecompare_tyelsecompare_nameletequalab=phys_equalab||compareab=0letmaketyname=name@:tyletmake3tynamenamespace={ty;name;namespace}letmknamespacename={ty=Ty_none;name=Name.simplename;namespace}letindexednamespacebasenameindices={ty=Ty_none;name=Name.indexedbasenameindices;namespace}letpp_namespacefmt=function|Attr->Fmt.stringfmt"attr"|Sort->Fmt.stringfmt"sort"|Term->Fmt.stringfmt"term"|Var->Fmt.stringfmt"var"letpp_namefmt=function|Simplename->Fmt.stringfmtname|Indexed{basename;indices}->Fmt.pffmt"(%s %a)"basename(Fmt.list~sep:Fmt.spFmt.string)indicesletppfmt{name;_}=pp_namefmtnameletto_string{name;_}=Fmt.str"%a"pp_namenameletto_json{name;ty;_}=`Assoc[(Fmt.str"%a"pp_namename,`Assoc[("ty",`String(Fmt.str"%a"Ty.ppty))])]lettype_of{ty;_}=tymoduleMap=Map.Make(structtypenonrect=tletcompare=compareend)moduleSmtlib=structletppfmt{ty;name;namespace}=matchnamespacewith|Term->pp_namefmtname|Sort->Ty.Smtlib.ppfmtty|Var->assertfalse|Attr->assertfalseend