Skip to content

Commit 1786093

Browse files
committed
Remove str/sig class type from untyped and typed ast.
Sig and str class type cannot be generated by the .res parser. Remove a bunch of code that deals with that.
1 parent 88c6ba6 commit 1786093

25 files changed

+264
-685
lines changed

jscomp/frontend/bs_ast_mapper.ml

+2-4
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ module MT = struct
280280
| Psig_open x -> open_ ~loc (sub.open_description sub x)
281281
| Psig_include x -> include_ ~loc (sub.include_description sub x)
282282
| Psig_class () -> assert false
283-
| Psig_class_type l ->
284-
class_type ~loc (List.map (sub.class_type_declaration sub) l)
283+
| Psig_class_type () -> assert false
285284
| Psig_extension (x, attrs) ->
286285
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)
287286
| Psig_attribute x -> attribute ~loc (sub.attribute sub x)
@@ -336,8 +335,7 @@ module M = struct
336335
| Pstr_modtype x -> modtype ~loc (sub.module_type_declaration sub x)
337336
| Pstr_open x -> open_ ~loc (sub.open_description sub x)
338337
| Pstr_class () -> {pstr_loc = loc; pstr_desc = Pstr_class ()}
339-
| Pstr_class_type l ->
340-
class_type ~loc (List.map (sub.class_type_declaration sub) l)
338+
| Pstr_class_type () -> {pstr_loc = loc; pstr_desc = Pstr_class_type ()}
341339
| Pstr_include x -> include_ ~loc (sub.include_declaration sub x)
342340
| Pstr_extension (x, attrs) ->
343341
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)

jscomp/ml/ast_helper.ml

-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ module Sig = struct
240240
let open_ ?loc a = mk ?loc (Psig_open a)
241241
let include_ ?loc a = mk ?loc (Psig_include a)
242242

243-
let class_type ?loc a = mk ?loc (Psig_class_type a)
244243
let extension ?loc ?(attrs = []) a = mk ?loc (Psig_extension (a, attrs))
245244
let attribute ?loc a = mk ?loc (Psig_attribute a)
246245
let text txt =
@@ -263,7 +262,6 @@ module Str = struct
263262
let rec_module ?loc a = mk ?loc (Pstr_recmodule a)
264263
let modtype ?loc a = mk ?loc (Pstr_modtype a)
265264
let open_ ?loc a = mk ?loc (Pstr_open a)
266-
let class_type ?loc a = mk ?loc (Pstr_class_type a)
267265
let include_ ?loc a = mk ?loc (Pstr_include a)
268266
let extension ?loc ?(attrs = []) a = mk ?loc (Pstr_extension (a, attrs))
269267
let attribute ?loc a = mk ?loc (Pstr_attribute a)

jscomp/ml/ast_helper.mli

-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ module Sig:
267267
val modtype: ?loc:loc -> module_type_declaration -> signature_item
268268
val open_: ?loc:loc -> open_description -> signature_item
269269
val include_: ?loc:loc -> include_description -> signature_item
270-
val class_type: ?loc:loc -> class_type_declaration list -> signature_item
271270
val extension: ?loc:loc -> ?attrs:attrs -> extension -> signature_item
272271
val attribute: ?loc:loc -> attribute -> signature_item
273272
val text: text -> signature_item list
@@ -288,7 +287,6 @@ module Str:
288287
val rec_module: ?loc:loc -> module_binding list -> structure_item
289288
val modtype: ?loc:loc -> module_type_declaration -> structure_item
290289
val open_: ?loc:loc -> open_description -> structure_item
291-
val class_type: ?loc:loc -> class_type_declaration list -> structure_item
292290
val include_: ?loc:loc -> include_declaration -> structure_item
293291
val extension: ?loc:loc -> ?attrs:attrs -> extension -> structure_item
294292
val attribute: ?loc:loc -> attribute -> structure_item

jscomp/ml/ast_iterator.ml

+2-4
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ module MT = struct
249249
| Psig_open x -> sub.open_description sub x
250250
| Psig_include x -> sub.include_description sub x
251251
| Psig_class () -> ()
252-
| Psig_class_type l ->
253-
List.iter (sub.class_type_declaration sub) l
252+
| Psig_class_type () -> ()
254253
| Psig_extension (x, attrs) ->
255254
sub.extension sub x; sub.attributes sub attrs
256255
| Psig_attribute x -> sub.attribute sub x
@@ -292,8 +291,7 @@ module M = struct
292291
| Pstr_modtype x -> sub.module_type_declaration sub x
293292
| Pstr_open x -> sub.open_description sub x
294293
| Pstr_class () -> ()
295-
| Pstr_class_type l ->
296-
List.iter (sub.class_type_declaration sub) l
294+
| Pstr_class_type () -> ()
297295
| Pstr_include x -> sub.include_declaration sub x
298296
| Pstr_extension (x, attrs) ->
299297
sub.extension sub x; sub.attributes sub attrs

jscomp/ml/ast_mapper.ml

+2-4
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ module MT = struct
264264
| Psig_open x -> open_ ~loc (sub.open_description sub x)
265265
| Psig_include x -> include_ ~loc (sub.include_description sub x)
266266
| Psig_class _ -> assert false
267-
| Psig_class_type l ->
268-
class_type ~loc (List.map (sub.class_type_declaration sub) l)
267+
| Psig_class_type _ -> assert false
269268
| Psig_extension (x, attrs) ->
270269
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)
271270
| Psig_attribute x -> attribute ~loc (sub.attribute sub x)
@@ -310,8 +309,7 @@ module M = struct
310309
| Pstr_modtype x -> modtype ~loc (sub.module_type_declaration sub x)
311310
| Pstr_open x -> open_ ~loc (sub.open_description sub x)
312311
| Pstr_class () -> {pstr_loc = loc ; pstr_desc = Pstr_class ()}
313-
| Pstr_class_type l ->
314-
class_type ~loc (List.map (sub.class_type_declaration sub) l)
312+
| Pstr_class_type () -> {pstr_loc = loc ; pstr_desc = Pstr_class_type ()}
315313
| Pstr_include x -> include_ ~loc (sub.include_declaration sub x)
316314
| Pstr_extension (x, attrs) ->
317315
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)

jscomp/ml/depend.ml

+4-31
Original file line numberDiff line numberDiff line change
@@ -160,33 +160,6 @@ let add_type_extension bv te =
160160
add bv te.ptyext_path;
161161
List.iter (add_extension_constructor bv) te.ptyext_constructors
162162

163-
let rec add_class_type bv cty =
164-
match cty.pcty_desc with
165-
Pcty_constr(l, tyl) ->
166-
add bv l; List.iter (add_type bv) tyl
167-
| Pcty_signature { pcsig_self = ty; pcsig_fields = fieldl } ->
168-
add_type bv ty;
169-
List.iter (add_class_type_field bv) fieldl
170-
| Pcty_arrow(_, ty1, cty2) ->
171-
add_type bv ty1; add_class_type bv cty2
172-
| Pcty_extension e -> handle_extension e
173-
| Pcty_open (_ovf, m, e) ->
174-
let bv = open_module bv m.txt in add_class_type bv e
175-
176-
and add_class_type_field bv pctf =
177-
match pctf.pctf_desc with
178-
Pctf_inherit cty -> add_class_type bv cty
179-
| Pctf_val(_, _, _, ty) -> add_type bv ty
180-
| Pctf_method(_, _, _, ty) -> add_type bv ty
181-
| Pctf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2
182-
| Pctf_attribute _ -> ()
183-
| Pctf_extension e -> handle_extension e
184-
185-
let add_class_description bv infos =
186-
add_class_type bv infos.pci_expr
187-
188-
let add_class_type_declaration = add_class_description
189-
190163
let pattern_bv = ref StringMap.empty
191164

192165
let rec add_pattern bv pat =
@@ -378,8 +351,8 @@ and add_sig_item (bv, m) item =
378351
(add bv, add m)
379352
| Psig_class () ->
380353
(bv, m)
381-
| Psig_class_type cdtl ->
382-
List.iter (add_class_type_declaration bv) cdtl; (bv, m)
354+
| Psig_class_type () ->
355+
(bv, m)
383356
| Psig_attribute _ -> (bv, m)
384357
| Psig_extension (e, _) ->
385358
handle_extension e;
@@ -464,8 +437,8 @@ and add_struct_item (bv, m) item : _ StringMap.t * _ StringMap.t =
464437
(open_module bv od.popen_lid.txt, m)
465438
| Pstr_class () ->
466439
(bv,m)
467-
| Pstr_class_type cdtl ->
468-
List.iter (add_class_type_declaration bv) cdtl; (bv, m)
440+
| Pstr_class_type () ->
441+
(bv, m)
469442
| Pstr_include incl ->
470443
let Node (s, m') = add_module_binding bv incl.pincl_mod in
471444
add_names s;

jscomp/ml/parser.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6710,7 +6710,7 @@ let yyact = [|
67106710
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'class_type_declarations) in
67116711
Obj.repr(
67126712
# 697 "ml/parser.mly"
6713-
( let (l, ext) = _1 in mkstr_ext (Pstr_class_type (List.rev l)) ext )
6713+
( let (_l, ext) = _1 in mkstr_ext (Pstr_class_type ()) ext )
67146714
# 6715 "ml/parser.ml"
67156715
: 'structure_item))
67166716
; (fun __caml_parser_env ->
@@ -7014,7 +7014,7 @@ let yyact = [|
70147014
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'class_type_declarations) in
70157015
Obj.repr(
70167016
# 809 "ml/parser.mly"
7017-
( let (l, ext) = _1 in mksig_ext (Psig_class_type (List.rev l)) ext )
7017+
( let (_l, ext) = _1 in mksig_ext (Psig_class_type ()) ext )
70187018
# 7019 "ml/parser.ml"
70197019
: 'signature_item))
70207020
; (fun __caml_parser_env ->

jscomp/ml/parser.mly

+2-2
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ structure_item:
694694
| open_statement
695695
{ let (body, ext) = $1 in mkstr_ext (Pstr_open body) ext }
696696
| class_type_declarations
697-
{ let (l, ext) = $1 in mkstr_ext (Pstr_class_type (List.rev l)) ext }
697+
{ let (_l, ext) = $1 in mkstr_ext (Pstr_class_type ()) ext }
698698
| str_include_statement
699699
{ let (body, ext) = $1 in mkstr_ext (Pstr_include body) ext }
700700
| item_extension post_item_attributes
@@ -806,7 +806,7 @@ signature_item:
806806
| sig_include_statement
807807
{ let (body, ext) = $1 in mksig_ext (Psig_include body) ext }
808808
| class_type_declarations
809-
{ let (l, ext) = $1 in mksig_ext (Psig_class_type (List.rev l)) ext }
809+
{ let (l, ext) = $1 in mksig_ext (Psig_class_type ()) ext }
810810
| item_extension post_item_attributes
811811
{ mksig(Psig_extension ($1, (add_docs_attrs (symbol_docs ()) $2))) }
812812
| floating_attribute

jscomp/ml/parsetree.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,9 @@ and signature_item_desc =
706706
| Psig_include of include_description
707707
(* include MT *)
708708
| Psig_class of unit
709-
(* class c1 : ... and ... and cn : ... *)
710-
| Psig_class_type of class_type_declaration list
711-
(* class type ct1 = ... and ... and ctn = ... *)
709+
(* Dummy AST node *)
710+
| Psig_class_type of unit
711+
(* Dummy AST node *)
712712
| Psig_attribute of attribute
713713
(* [@@@id] *)
714714
| Psig_extension of extension * attributes
@@ -832,8 +832,8 @@ and structure_item_desc =
832832
(* open X *)
833833
| Pstr_class of unit
834834
(* Dummy AST node *)
835-
| Pstr_class_type of class_type_declaration list
836-
(* class type ct1 = ... and ... and ctn = ... *)
835+
| Pstr_class_type of unit
836+
(* Dummy AST node *)
837837
| Pstr_include of include_declaration
838838
(* include ME *)
839839
| Pstr_attribute of attribute

jscomp/ml/pprintast.ml

+3-82
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ let constant f = function
208208
let mutable_flag f = function
209209
| Immutable -> ()
210210
| Mutable -> pp f "mutable@;"
211-
let virtual_flag f = function
212-
| Concrete -> ()
213-
| Virtual -> pp f "virtual@;"
214211

215212
(* trailing space added *)
216213
let rec_flag f rf =
@@ -233,14 +230,8 @@ let tyvar f str = pp f "'%s" str
233230
let tyvar_loc f str = pp f "'%s" str.txt
234231
let string_quot f x = pp f "`%s" x
235232

236-
(* c ['a,'b] *)
237-
let rec class_params_def ctxt f = function
238-
| [] -> ()
239-
| l ->
240-
pp f "[%a] " (* space *)
241-
(list (type_param ctxt) ~sep:",") l
242233

243-
and type_with_label ctxt f (label, c) =
234+
let rec type_with_label ctxt f (label, c) =
244235
match label with
245236
| Nolabel -> core_type1 ctxt f c (* otherwise parenthesize *)
246237
| Labelled s -> pp f "%s:%a" s (core_type1 ctxt) c
@@ -797,76 +788,6 @@ and item_extension ctxt f (s, e) =
797788
and exception_declaration ctxt f ext =
798789
pp f "@[<hov2>exception@ %a@]" (extension_constructor ctxt) ext
799790

800-
and class_signature ctxt f { pcsig_self = ct; pcsig_fields = l ;_} =
801-
let class_type_field f x =
802-
match x.pctf_desc with
803-
| Pctf_inherit (ct) ->
804-
pp f "@[<2>inherit@ %a@]%a" (class_type ctxt) ct
805-
(item_attributes ctxt) x.pctf_attributes
806-
| Pctf_val (s, mf, vf, ct) ->
807-
pp f "@[<2>val @ %a%a%s@ :@ %a@]%a"
808-
mutable_flag mf virtual_flag vf s.txt (core_type ctxt) ct
809-
(item_attributes ctxt) x.pctf_attributes
810-
| Pctf_method (s, pf, vf, ct) ->
811-
pp f "@[<2>method %a %a%s :@;%a@]%a"
812-
private_flag pf virtual_flag vf s.txt (core_type ctxt) ct
813-
(item_attributes ctxt) x.pctf_attributes
814-
| Pctf_constraint (ct1, ct2) ->
815-
pp f "@[<2>constraint@ %a@ =@ %a@]%a"
816-
(core_type ctxt) ct1 (core_type ctxt) ct2
817-
(item_attributes ctxt) x.pctf_attributes
818-
| Pctf_attribute a -> floating_attribute ctxt f a
819-
| Pctf_extension e ->
820-
item_extension ctxt f e;
821-
item_attributes ctxt f x.pctf_attributes
822-
in
823-
pp f "@[<hv0>@[<hv2>object@[<1>%a@]@ %a@]@ end@]"
824-
(fun f -> function
825-
{ptyp_desc=Ptyp_any; ptyp_attributes=[]; _} -> ()
826-
| ct -> pp f " (%a)" (core_type ctxt) ct) ct
827-
(list class_type_field ~sep:"@;") l
828-
829-
(* call [class_signature] called by [class_signature] *)
830-
and class_type ctxt f x =
831-
match x.pcty_desc with
832-
| Pcty_signature cs ->
833-
class_signature ctxt f cs;
834-
attributes ctxt f x.pcty_attributes
835-
| Pcty_constr (li, l) ->
836-
pp f "%a%a%a"
837-
(fun f l -> match l with
838-
| [] -> ()
839-
| _ -> pp f "[%a]@ " (list (core_type ctxt) ~sep:"," ) l) l
840-
longident_loc li
841-
(attributes ctxt) x.pcty_attributes
842-
| Pcty_arrow (l, co, cl) ->
843-
pp f "@[<2>%a@;->@;%a@]" (* FIXME remove parens later *)
844-
(type_with_label ctxt) (l,co)
845-
(class_type ctxt) cl
846-
| Pcty_extension e ->
847-
extension ctxt f e;
848-
attributes ctxt f x.pcty_attributes
849-
| Pcty_open (ovf, lid, e) ->
850-
pp f "@[<2>let open%s %a in@;%a@]" (override ovf) longident_loc lid
851-
(class_type ctxt) e
852-
853-
(* [class type a = object end] *)
854-
and class_type_declaration_list ctxt f l =
855-
let class_type_declaration kwd f x =
856-
let { pci_params=ls; pci_name={ txt; _ }; _ } = x in
857-
pp f "@[<2>%s %a%a%s@ =@ %a@]%a" kwd
858-
virtual_flag x.pci_virt
859-
(class_params_def ctxt) ls txt
860-
(class_type ctxt) x.pci_expr
861-
(item_attributes ctxt) x.pci_attributes
862-
in
863-
match l with
864-
| [] -> ()
865-
| [x] -> class_type_declaration "class type" f x
866-
| x :: xs ->
867-
pp f "@[<v>%a@,%a@]"
868-
(class_type_declaration "class type") x
869-
(list ~sep:"@," (class_type_declaration "and")) xs
870791

871792
and class_field ctxt f x =
872793
match x.pcf_desc with
@@ -1023,7 +944,7 @@ and signature_item ctxt f x : unit =
1023944
pp f "@ =@ %a" (module_type ctxt) mt
1024945
) md
1025946
(item_attributes ctxt) attrs
1026-
| Psig_class_type (l) -> class_type_declaration_list ctxt f l
947+
| Psig_class_type () -> ()
1027948
| Psig_recmodule decls ->
1028949
let rec string_x_module_type_list f ?(first=true) l =
1029950
match l with
@@ -1222,7 +1143,7 @@ and structure_item ctxt f x =
12221143
) md
12231144
(item_attributes ctxt) attrs
12241145
| Pstr_class () -> ()
1225-
| Pstr_class_type l -> class_type_declaration_list ctxt f l
1146+
| Pstr_class_type () -> ()
12261147
| Pstr_primitive vd ->
12271148
pp f "@[<hov2>external@ %a@ :@ %a@]%a"
12281149
protect_ident vd.pval_name.txt

0 commit comments

Comments
 (0)