Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ast_uncurry_gen.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132(* Copyright (C) 2020- Hongbo Zhang, Authors of ReScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)openImportopenAst_helperletprocess_args~locselfargs~init=List.fold_left~initargs~f:(funaccparam->matchparamwith|{pparam_desc=Pparam_newtype_;_}->acc|{pparam_desc=Pparam_val(arg_label,_,arg);_}->Error.optional_err~locarg_label;(arg_label,self#patternarg)::acc)letrecaux~locselfacc(body:expression)=matchAst_attributes.process_attributes_revbody.pexp_attributeswith|Nothing,_->(matchbody.pexp_descwith|Pexp_function(args,_,Pfunction_bodybody)->aux~locself(process_args~locselfargs~init:acc)body|_->(self#expressionbody,acc))|_,_->(self#expressionbody,acc)(* Handling `fun [@this]` used in `object [@u] end` *)letto_method_callback=letfirst_argargs=matchList.find~f:(function|{pparam_desc=Pparam_val_;_}->true|{pparam_desc=Pparam_newtype_;_}->false)argswith|{pparam_desc=Pparam_val(_,_,pat);_}->pat|{pparam_desc=Pparam_newtype_;_}|(exceptionNot_found)->assertfalseinletrecis_single_variable_pattern_conservativep=matchp.ppat_descwith|Ppat_any|Ppat_var_->true|Ppat_alias(p,_)|Ppat_constraint(p,_)->is_single_variable_pattern_conservativep|_->falseinfun~loc(self:Ast_traverse.map)argsbody->letfirst_arg=self#pattern(first_argargs)inifnot(is_single_variable_pattern_conservativefirst_arg)thenError.err~loc:first_arg.ppat_locMel_this_simple_pattern;letbody,rev_extra_args=letresult,rev_extra_args=letrev_args=process_args~locselfargs~init:[]inaux~locselfrev_argsbodyinletbody=Ast_builder.Default.pexp_function~loc(List.rev_map~f:(fun(label,p)->{pparam_desc=Pparam_val(label,None,p);pparam_loc=loc})rev_extra_args)None(Pfunction_bodyresult)in(body,rev_extra_args)inletarity_s=string_of_int(List.lengthrev_extra_args)inPexp_apply(Exp.ident~loc{loc;txt=Ast_literal.unsafe_to_method},[(Nolabel,Exp.constraint_~loc(Exp.record~loc[({loc;txt=Ast_literal.hidden_fieldarity_s},body)]None)(Typ.constr~loc{loc;txt=Ldot(Ast_literal.js_meth_callback,Format.sprintf"arity%s"arity_s);}[Typ.any~loc()]));])letto_uncurry_fn~loc(self:Ast_traverse.map)argsbody:expression_desc=letresult,rev_extra_args=letrev_args=process_args~locselfargs~init:[]inaux~locselfrev_argsbodyinletarity=matchrev_extra_argswith|[(_,{ppat_desc=Ppat_construct({txt=Lident"()";_},None);_});]->0|_->List.lengthrev_extra_argsinError.err_large_arity~locarity;letbody=Ast_builder.Default.pexp_function~loc(List.rev_map~f:(fun(label,p)->{pparam_desc=Pparam_val(label,None,p);pparam_loc=loc})rev_extra_args)None(Pfunction_bodyresult)inPexp_record([({txt=Ldot(Ast_literal.js_fn,"I"^string_of_intarity);loc},body);],None)