Skip to content

Commit 214f181

Browse files
committed
more changes to object_field
1 parent 87db5d2 commit 214f181

7 files changed

+216
-66
lines changed

jscomp/bin/all_ounit_tests.ml

+31
Original file line numberDiff line numberDiff line change
@@ -14472,6 +14472,18 @@ val rec_type_sig:
1447214472
type_declaration list ->
1447314473
signature_item
1447414474

14475+
val mk_fn_type:
14476+
(arg_label * core_type * attributes * loc) list ->
14477+
core_type ->
14478+
core_type
14479+
14480+
type object_field =
14481+
14482+
string * attributes * core_type
14483+
val object_field : string -> attributes -> core_type -> object_field
14484+
14485+
14486+
1447514487
end = struct
1447614488
#1 "ast_compatible.ml"
1447714489
(* Copyright (C) 2018 Authors of BuckleScript
@@ -14705,6 +14717,25 @@ let const_exp_string_list_as_array xs =
1470514717
Ast_helper.Exp.array
1470614718
(Ext_list.map (fun x -> const_exp_string x ) xs)
1470714719

14720+
14721+
let mk_fn_type
14722+
(new_arg_types_ty : (arg_label * core_type * attributes * loc) list)
14723+
(result : core_type) : core_type =
14724+
Ext_list.fold_right (fun (label, ty, attrs, loc) acc ->
14725+
{
14726+
ptyp_desc = Ptyp_arrow(label,ty,acc);
14727+
ptyp_loc = loc;
14728+
ptyp_attributes = attrs
14729+
}
14730+
) new_arg_types_ty result
14731+
14732+
type object_field =
14733+
14734+
string * attributes * core_type
14735+
14736+
14737+
let object_field l attrs ty =
14738+
(l,attrs,ty)
1470814739
end
1470914740
module Bs_loc : sig
1471014741
#1 "bs_loc.mli"

jscomp/syntax/ast_compatible.ml

+13-1
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,16 @@ let const_exp_string_list_as_array xs =
311311
ptyp_loc = loc;
312312
ptyp_attributes = attrs
313313
}
314-
) new_arg_types_ty result
314+
) new_arg_types_ty result
315+
316+
type object_field =
317+
#if OCAML_VERSION =~ ">4.03.0" then
318+
Parsetree.object_field
319+
#else
320+
string * attributes * core_type
321+
#end
322+
323+
let object_field l attrs ty =
324+
#if OCAML_VERSION =~ ">4.03.0" then
325+
Parsetree.Otag
326+
#end (l,attrs,ty)

jscomp/syntax/ast_compatible.mli

+12-1
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,15 @@ val rec_type_sig:
179179
val mk_fn_type:
180180
(arg_label * core_type * attributes * loc) list ->
181181
core_type ->
182-
core_type
182+
core_type
183+
184+
type object_field =
185+
#if OCAML_VERSION =~ ">4.03.0" then
186+
Parsetree.object_field
187+
val object_field : label Asttypes.loc -> attributes -> core_type -> object_field
188+
#else
189+
string * attributes * core_type
190+
val object_field : string -> attributes -> core_type -> object_field
191+
#end
192+
193+

jscomp/syntax/ast_core_type_class_type.ml

+16-7
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
open Ast_helper
25-
let process_getter_setter ~not_getter_setter ~get ~set
25+
26+
let process_getter_setter
27+
~not_getter_setter
28+
~(get : Parsetree.core_type -> _ -> Parsetree.attributes -> _) ~set
2629
loc name
2730
(attrs : Ast_attributes.t)
28-
(ty : Parsetree.core_type) acc =
31+
(ty : Parsetree.core_type) (acc : _ list) =
2932
match Ast_attributes.process_method_attributes_rev attrs with
3033
| {get = None; set = None}, _ -> not_getter_setter ty :: acc
3134
| st , pctf_attributes
@@ -163,7 +166,13 @@ let handle_core_type
163166
let (+>) attr (typ : Parsetree.core_type) =
164167
{typ with ptyp_attributes = attr :: typ.ptyp_attributes} in
165168
let new_methods =
166-
Ext_list.fold_right (fun (label, ptyp_attrs, core_type) acc ->
169+
Ext_list.fold_right (fun meth_ acc ->
170+
match meth_ with
171+
#if OCAML_VERSION =~ ">4.03.0" then
172+
| Parsetree.Oinherit _ -> meth_
173+
| Parsetree.Otag
174+
#end
175+
(label, ptyp_attrs, core_type) ->
167176
let get ty name attrs =
168177
let attrs, core_type =
169178
match Ast_attributes.process_attributes_rev attrs with
@@ -175,7 +184,7 @@ let handle_core_type
175184
| Meth_callback attr, attrs ->
176185
attrs, attr +> ty
177186
in
178-
name , attrs, self.typ self core_type in
187+
Ast_compatible.object_field name attrs (self.typ self core_type) in
179188
let set ty name attrs =
180189
let attrs, core_type =
181190
match Ast_attributes.process_attributes_rev attrs with
@@ -187,8 +196,8 @@ let handle_core_type
187196
| Meth_callback attr, attrs ->
188197
attrs, attr +> ty
189198
in
190-
name, attrs, Ast_util.to_method_type loc self Ast_compatible.no_label core_type
191-
(Ast_literal.type_unit ~loc ()) in
199+
Ast_compatible.object_field name attrs (Ast_util.to_method_type loc self Ast_compatible.no_label core_type
200+
(Ast_literal.type_unit ~loc ())) in
192201
let not_getter_setter ty =
193202
let attrs, core_type =
194203
match Ast_attributes.process_attributes_rev ptyp_attrs with
@@ -199,7 +208,7 @@ let handle_core_type
199208
attrs, attr +> ty
200209
| Meth_callback attr, attrs ->
201210
attrs, attr +> ty in
202-
label, attrs, self.typ self core_type in
211+
Ast_compatible.object_field label attrs (self.typ self core_type) in
203212
process_getter_setter ~not_getter_setter ~get ~set
204213
loc label ptyp_attrs core_type acc
205214
) methods [] in

lib/bsdep.ml

+48-19
Original file line numberDiff line numberDiff line change
@@ -24608,6 +24608,18 @@ val rec_type_sig:
2460824608
type_declaration list ->
2460924609
signature_item
2461024610

24611+
val mk_fn_type:
24612+
(arg_label * core_type * attributes * loc) list ->
24613+
core_type ->
24614+
core_type
24615+
24616+
type object_field =
24617+
24618+
string * attributes * core_type
24619+
val object_field : string -> attributes -> core_type -> object_field
24620+
24621+
24622+
2461124623
end = struct
2461224624
#1 "ast_compatible.ml"
2461324625
(* Copyright (C) 2018 Authors of BuckleScript
@@ -24841,6 +24853,25 @@ let const_exp_string_list_as_array xs =
2484124853
Ast_helper.Exp.array
2484224854
(Ext_list.map (fun x -> const_exp_string x ) xs)
2484324855

24856+
24857+
let mk_fn_type
24858+
(new_arg_types_ty : (arg_label * core_type * attributes * loc) list)
24859+
(result : core_type) : core_type =
24860+
Ext_list.fold_right (fun (label, ty, attrs, loc) acc ->
24861+
{
24862+
ptyp_desc = Ptyp_arrow(label,ty,acc);
24863+
ptyp_loc = loc;
24864+
ptyp_attributes = attrs
24865+
}
24866+
) new_arg_types_ty result
24867+
24868+
type object_field =
24869+
24870+
string * attributes * core_type
24871+
24872+
24873+
let object_field l attrs ty =
24874+
(l,attrs,ty)
2484424875
end
2484524876
module Ext_utf8 : sig
2484624877
#1 "ext_utf8.mli"
@@ -33539,12 +33570,9 @@ let handle_attributes
3353933570
snd @@ get_arg_type ~nolabel:true false result_type (* result type can not be labeled *)
3354033571

3354133572
in
33542-
begin
33543-
(
33544-
Ext_list.fold_right (fun (label,ty,attrs,loc) acc ->
33545-
Ast_compatible.label_arrow ~loc ~attrs label ty acc
33546-
) new_arg_types_ty result
33547-
) ,
33573+
begin
33574+
Ast_compatible.mk_fn_type new_arg_types_ty result
33575+
,
3354833576
prim_name,
3354933577
Ffi_obj_create arg_kinds,
3355033578
left_attrs
@@ -33950,12 +33978,7 @@ let handle_attributes
3395033978
let return_wrapper : External_ffi_types.return_wrapper =
3395133979
check_return_wrapper loc st.return_wrapper new_result_type
3395233980
in
33953-
(
33954-
Ext_list.fold_right (fun (label,ty,attrs,loc) acc ->
33955-
Ast_compatible.label_arrow ~loc ~attrs label ty acc
33956-
) new_arg_types_ty new_result_type
33957-
) ,
33958-
33981+
Ast_compatible.mk_fn_type new_arg_types_ty new_result_type,
3395933982
prim_name,
3396033983
(Ffi_bs (arg_type_specs,return_wrapper , ffi)), left_attrs
3396133984
end
@@ -35033,10 +35056,13 @@ end = struct
3503335056
* along with this program; if not, write to the Free Software
3503435057
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
3503535058
open Ast_helper
35036-
let process_getter_setter ~not_getter_setter ~get ~set
35059+
35060+
let process_getter_setter
35061+
~not_getter_setter
35062+
~(get : Parsetree.core_type -> _ -> Parsetree.attributes -> _) ~set
3503735063
loc name
3503835064
(attrs : Ast_attributes.t)
35039-
(ty : Parsetree.core_type) acc =
35065+
(ty : Parsetree.core_type) (acc : _ list) =
3504035066
match Ast_attributes.process_method_attributes_rev attrs with
3504135067
| {get = None; set = None}, _ -> not_getter_setter ty :: acc
3504235068
| st , pctf_attributes
@@ -35172,7 +35198,10 @@ let handle_core_type
3517235198
let (+>) attr (typ : Parsetree.core_type) =
3517335199
{typ with ptyp_attributes = attr :: typ.ptyp_attributes} in
3517435200
let new_methods =
35175-
Ext_list.fold_right (fun (label, ptyp_attrs, core_type) acc ->
35201+
Ext_list.fold_right (fun meth_ acc ->
35202+
match meth_ with
35203+
35204+
(label, ptyp_attrs, core_type) ->
3517635205
let get ty name attrs =
3517735206
let attrs, core_type =
3517835207
match Ast_attributes.process_attributes_rev attrs with
@@ -35184,7 +35213,7 @@ let handle_core_type
3518435213
| Meth_callback attr, attrs ->
3518535214
attrs, attr +> ty
3518635215
in
35187-
name , attrs, self.typ self core_type in
35216+
Ast_compatible.object_field name attrs (self.typ self core_type) in
3518835217
let set ty name attrs =
3518935218
let attrs, core_type =
3519035219
match Ast_attributes.process_attributes_rev attrs with
@@ -35196,8 +35225,8 @@ let handle_core_type
3519635225
| Meth_callback attr, attrs ->
3519735226
attrs, attr +> ty
3519835227
in
35199-
name, attrs, Ast_util.to_method_type loc self Ast_compatible.no_label core_type
35200-
(Ast_literal.type_unit ~loc ()) in
35228+
Ast_compatible.object_field name attrs (Ast_util.to_method_type loc self Ast_compatible.no_label core_type
35229+
(Ast_literal.type_unit ~loc ())) in
3520135230
let not_getter_setter ty =
3520235231
let attrs, core_type =
3520335232
match Ast_attributes.process_attributes_rev ptyp_attrs with
@@ -35208,7 +35237,7 @@ let handle_core_type
3520835237
attrs, attr +> ty
3520935238
| Meth_callback attr, attrs ->
3521035239
attrs, attr +> ty in
35211-
label, attrs, self.typ self core_type in
35240+
Ast_compatible.object_field label attrs (self.typ self core_type) in
3521235241
process_getter_setter ~not_getter_setter ~get ~set
3521335242
loc label ptyp_attrs core_type acc
3521435243
) methods [] in

0 commit comments

Comments
 (0)