123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146# 1 "VisitorsCompatibility.cppo.ml"letmknoloc=Location.mknolocopenAsttypesopenParsetreeopenAst_helper(* OCaml's abstract syntax tree evolves with time. We depend on this tree
because we analyze it (that is, we analyze type definitions) and because we
construct it (that is, we generate code). This module gathers the ugly bits
whose definition varies depending on the version of OCaml that we are
working with. *)# 16 "VisitorsCompatibility.cppo.ml"(* Constructing an arrow type. *)letty_arrow(a:core_type)(b:core_type):core_type=Typ.arrowNolabelab(* Constructing a function. *)letplambda(p:pattern)(e:expression):expression=Exp.fun_NolabelNonepe(* Constructing a string literal. *)letconst_string(w:string)=# 32 "VisitorsCompatibility.cppo.ml"Const.stringw# 35 "VisitorsCompatibility.cppo.ml"(* [ld_label] and [ld_ty] extract a label and type out of an OCaml record label
declaration. *)letld_label(ld:label_declaration):label=ld.pld_name.txtletld_labels=List.mapld_labelletld_ty(ld:label_declaration):core_type=ld.pld_typeletld_tys=List.mapld_ty(* Analyzing the definition of a data constructor. *)(* A data constructor is either a traditional data constructor, whose
components are anonymous, or a data constructor whose components
form an ``inline record''. This is a new feature of OCaml 4.03. *)typedata_constructor_variety=|DataTraditionalofcore_typelist|DataInlineRecordoflabellist*core_typelistletdata_constructor_variety(cd:constructor_declaration)=# 64 "VisitorsCompatibility.cppo.ml"matchcd.pcd_argswith(* A traditional data constructor. *)|Pcstr_tupletys->DataTraditionaltys(* An ``inline record'' data constructor. *)|Pcstr_recordlds->DataInlineRecord(ld_labelslds,ld_tyslds)# 73 "VisitorsCompatibility.cppo.ml"(* Between OCaml 4.04 and OCaml 4.05, the types of several functions in [Ast_helper]
have changed. They used to take arguments of type [string], and now take arguments
of type [str], thus requiring a conversion. These functions include [Typ.object_],
[Typ.poly], [Exp.send], [Exp.newtype], [Ctf.val_], [Ctf.method_], [Cf.inherit_]. *)typestr=# 82 "VisitorsCompatibility.cppo.ml"stringLocation.loc# 85 "VisitorsCompatibility.cppo.ml"letstring2str(s:string):str=# 89 "VisitorsCompatibility.cppo.ml"mknolocs# 92 "VisitorsCompatibility.cppo.ml"letstr2string(s:str):string=# 96 "VisitorsCompatibility.cppo.ml"s.txt# 99 "VisitorsCompatibility.cppo.ml"lettyp_poly(tyvars:stringlist)(cty:core_type):core_type=Typ.poly(List.mapstring2strtyvars)ctyletexp_send(e:expression)(m:string):expression=Exp.sende(string2strm)(* In the data constructor [Ptyp_poly (qs, ty)], the type of [qs] has changed from
[string list] to [string loc list] between OCaml 4.04 and 4.05.
See commit b0e880c448c78ed0cedff28356fcaf88f1436eef.
The function [quantifiers] compensates for this. *)letquantifiersqs:stringlist=List.mapstr2stringqs(* In the data constructor [Ptyp_object (methods, _)], the type of [methods] has
changed from [(string loc * attributes * core_type) list] in OCaml 4.05 to
[object_field list] in OCaml 4.06. *)# 123 "VisitorsCompatibility.cppo.ml"letobject_field_to_core_type(field:object_field):core_type=# 135 "VisitorsCompatibility.cppo.ml"matchfield.pof_descwith|Otag(_,ty)->ty|Oinheritty->ty# 140 "VisitorsCompatibility.cppo.ml"letrow_field_to_core_types(field:row_field):core_typelist=# 148 "VisitorsCompatibility.cppo.ml"matchfield.prf_descwith|Rtag(_,_,tys)->tys|Rinheritty->[ty]# 155 "VisitorsCompatibility.cppo.ml"(* -------------------------------------------------------------------------- *)(* [floating s items] produces a floating attribute whose name is [s] and
whose payload is the list of structure items [items]. *)(* The type [attribute] is defined in 4.07 as [string loc * payload], but in
4.08 its definition changes to a record type and the function [Attr.mk]
appears. *)letfloating(s:string)(items:structure):structure_item=letname=mknolocsandpayload=PStritemsin# 170 "VisitorsCompatibility.cppo.ml"Str.attribute(Attr.mknamepayload)