123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
Denis Merigoux <denis.merigoux@inria.fr>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)openCatala_utilsincludeShared_asttypelit=lcalcglittype'mnaked_expr=(lcalc,'mmark)naked_gexprand'mexpr=(lcalc,'mmark)gexprtype'mprogram='mexprShared_ast.programletoption_enum:EnumName.t=EnumName.fresh("eoption",Pos.no_pos)letnone_constr:EnumConstructor.t=EnumConstructor.fresh("ENone",Pos.no_pos)letsome_constr:EnumConstructor.t=EnumConstructor.fresh("ESome",Pos.no_pos)letoption_enum_config:typEnumConstructor.Map.t=EnumConstructor.Map.empty|>EnumConstructor.Map.addnone_constr(TLitTUnit,Pos.no_pos)|>EnumConstructor.Map.addsome_constr(TAny,Pos.no_pos)(* FIXME: proper typing in all the constructors below *)letmake_nonem=lettunit=TLitTUnit,Expr.mark_posminExpr.einj(Expr.elitLUnit(Expr.with_tymtunit))none_constroption_enummletmake_somee=letm=Marked.get_markeinExpr.einjesome_constroption_enumm(** [make_matchopt_with_abs_arms arg e_none e_some] build an expression
[match arg with |None -> e_none | Some -> e_some] and requires e_some and
e_none to be in the form [EAbs ...].*)letmake_matchopt_with_abs_armsarge_nonee_some=letm=Marked.get_markarginletcases=EnumConstructor.Map.empty|>EnumConstructor.Map.addnone_constre_none|>EnumConstructor.Map.addsome_constre_someinExpr.ematchargoption_enumcasesm(** [make_matchopt pos v tau arg e_none e_some] builds an expression
[match arg with | None ()-> e_none | Somev -> e_some]. It binds v to
e_some, permitting it to be used inside the expression. There is no
requirements on the form of both e_some and e_none. *)letmake_matchopt posvtauarge_nonee_some=letx=Var.make"_"inmake_matchopt_with_abs_armsarg(Expr.make_abs[|x|]e_none[TLitTUnit,pos]pos)(Expr.make_abs[|v|]e_some[tau]pos)lethandle_default=Var.make"handle_default"lethandle_default_opt=Var.make"handle_default_opt"