|
| 1 | +open Stdlib0 |
| 2 | + |
1 | 3 | module Ext_name = struct |
2 | | - let ptyp_labeled_tuple = "ppxlib.migration.ptyp_labeled_tuple_504" |
3 | | - let pexp_labeled_tuple = "ppxlib.migration.pexp_labeled_tuple_504" |
4 | | - let ppat_labeled_tuple = "ppxlib.migration.ppat_labeled_tuple_504" |
| 4 | + let ptyp_labeled_tuple = "ppxlib.migration.ptyp_labeled_tuple_5_4" |
| 5 | + let pexp_labeled_tuple = "ppxlib.migration.pexp_labeled_tuple_5_4" |
| 6 | + let ppat_labeled_tuple = "ppxlib.migration.ppat_labeled_tuple_5_4" |
| 7 | + let bivariant_param = "ppxlib.migration.bivariant_param_5_4" |
| 8 | + let bivariant_pstr = "ppxlib.migration.bivariant_str_item_5_4" |
| 9 | + let bivariant_psig = "ppxlib.migration.bivariant_sig_item_5_4" |
| 10 | + let bivariant_pmty_with = "ppxlib.migration.bivariant_pmty_with_5_4" |
5 | 11 | end |
6 | 12 |
|
7 | 13 | let invalid_encoding ~loc name = |
@@ -197,7 +203,7 @@ module Make (X : AST) = struct |
197 | 203 | | None -> invalid_encoding ~loc Ext_name.ppat_labeled_tuple |
198 | 204 | end |
199 | 205 |
|
200 | | -module Ast_503 = struct |
| 206 | +module Ast_503_arg = struct |
201 | 207 | include Ast_503.Asttypes |
202 | 208 | include Ast_503.Parsetree |
203 | 209 |
|
@@ -277,7 +283,7 @@ module Ast_503 = struct |
277 | 283 | end |
278 | 284 | end |
279 | 285 |
|
280 | | -module Ast_502 = struct |
| 286 | +module Ast_502_arg = struct |
281 | 287 | include Ast_502.Asttypes |
282 | 288 | include Ast_502.Parsetree |
283 | 289 |
|
@@ -358,9 +364,151 @@ module Ast_502 = struct |
358 | 364 | end |
359 | 365 |
|
360 | 366 | module To_503 = struct |
361 | | - include Make (Ast_503) |
| 367 | + include Make (Ast_503_arg) |
| 368 | + open Ast_503.Asttypes |
| 369 | + open Ast_503.Parsetree |
| 370 | + |
| 371 | + let encode_bivariant_param typ inj = |
| 372 | + let loc = { typ.ptyp_loc with Location.loc_ghost = true } in |
| 373 | + let attr = |
| 374 | + { |
| 375 | + attr_name = { txt = Ext_name.bivariant_param; loc }; |
| 376 | + attr_payload = PStr []; |
| 377 | + attr_loc = loc; |
| 378 | + } |
| 379 | + in |
| 380 | + ( { typ with ptyp_attributes = attr :: typ.ptyp_attributes }, |
| 381 | + (NoVariance, inj) ) |
| 382 | + |
| 383 | + let decode_bivariant_param (typ, (var, inj)) = |
| 384 | + let ptyp_attributes = |
| 385 | + List.without_first typ.ptyp_attributes ~pred:(fun attr -> |
| 386 | + String.equal attr.attr_name.txt Ext_name.bivariant_param) |
| 387 | + in |
| 388 | + match (ptyp_attributes, var) with |
| 389 | + | Some ptyp_attributes, NoVariance -> |
| 390 | + Some ({ typ with ptyp_attributes }, inj) |
| 391 | + | None, _ -> None |
| 392 | + | Some _, _ -> invalid_encoding ~loc:typ.ptyp_loc "bivariant type parameter" |
| 393 | + |
| 394 | + let encode_bivariant_pstr ~loc pstr_desc = |
| 395 | + let loc = { loc with Location.loc_ghost = true } in |
| 396 | + let ext = |
| 397 | + ( { txt = Ext_name.bivariant_pstr; loc }, |
| 398 | + PStr [ { pstr_loc = loc; pstr_desc } ] ) |
| 399 | + in |
| 400 | + Pstr_extension (ext, []) |
| 401 | + |
| 402 | + let encode_bivariant_pstr_type ~loc rec_flag tds = |
| 403 | + encode_bivariant_pstr ~loc (Pstr_type (rec_flag, tds)) |
| 404 | + |
| 405 | + let encode_bivariant_pstr_typext ~loc te = |
| 406 | + encode_bivariant_pstr ~loc (Pstr_typext te) |
| 407 | + |
| 408 | + let encode_bivariant_pstr_class ~loc cds = |
| 409 | + encode_bivariant_pstr ~loc (Pstr_class cds) |
| 410 | + |
| 411 | + let encode_bivariant_pstr_class_type ~loc ctds = |
| 412 | + encode_bivariant_pstr ~loc (Pstr_class_type ctds) |
| 413 | + |
| 414 | + let encode_bivariant_psig ~loc psig_desc = |
| 415 | + let loc = { loc with Location.loc_ghost = true } in |
| 416 | + let ext = |
| 417 | + ( { txt = Ext_name.bivariant_psig; loc }, |
| 418 | + PSig [ { psig_loc = loc; psig_desc } ] ) |
| 419 | + in |
| 420 | + Psig_extension (ext, []) |
| 421 | + |
| 422 | + let encode_bivariant_psig_type ~loc rec_flag tds = |
| 423 | + encode_bivariant_psig ~loc (Psig_type (rec_flag, tds)) |
| 424 | + |
| 425 | + let encode_bivariant_psig_typesubst ~loc tds = |
| 426 | + encode_bivariant_psig ~loc (Psig_typesubst tds) |
| 427 | + |
| 428 | + let encode_bivariant_psig_typext ~loc te = |
| 429 | + encode_bivariant_psig ~loc (Psig_typext te) |
| 430 | + |
| 431 | + let encode_bivariant_psig_class ~loc cds = |
| 432 | + encode_bivariant_psig ~loc (Psig_class cds) |
| 433 | + |
| 434 | + let encode_bivariant_psig_class_type ~loc ctds = |
| 435 | + encode_bivariant_psig ~loc (Psig_class_type ctds) |
| 436 | + |
| 437 | + let decode_bivariant_pstr ~loc payload attributes = |
| 438 | + match (payload, attributes) with |
| 439 | + | ( PStr |
| 440 | + [ |
| 441 | + { |
| 442 | + pstr_desc = |
| 443 | + (Pstr_type _ | Pstr_typext _ | Pstr_class _ | Pstr_class_type _) |
| 444 | + as x; |
| 445 | + _; |
| 446 | + }; |
| 447 | + ], |
| 448 | + [] ) -> |
| 449 | + x |
| 450 | + | _ -> invalid_encoding ~loc "bivariant structure_item" |
| 451 | + |
| 452 | + let decode_bivariant_psig ~loc payload attributes = |
| 453 | + match (payload, attributes) with |
| 454 | + | ( PSig |
| 455 | + [ |
| 456 | + { |
| 457 | + psig_desc = |
| 458 | + ( Psig_type _ | Psig_typesubst _ | Psig_typext _ | Psig_class _ |
| 459 | + | Psig_class_type _ ) as x; |
| 460 | + _; |
| 461 | + }; |
| 462 | + ], |
| 463 | + [] ) -> |
| 464 | + x |
| 465 | + | _ -> invalid_encoding ~loc "bivariant signature_item" |
| 466 | + |
| 467 | + let encode_bivariant_pmty_with ~loc mty constraints = |
| 468 | + let loc = { loc with Location.loc_ghost = true } in |
| 469 | + let pmd_type = |
| 470 | + { |
| 471 | + pmty_loc = loc; |
| 472 | + pmty_attributes = []; |
| 473 | + pmty_desc = Pmty_with (mty, constraints); |
| 474 | + } |
| 475 | + in |
| 476 | + let psig_desc = |
| 477 | + Psig_module |
| 478 | + { |
| 479 | + pmd_name = { txt = None; loc }; |
| 480 | + pmd_type; |
| 481 | + pmd_attributes = []; |
| 482 | + pmd_loc = loc; |
| 483 | + } |
| 484 | + in |
| 485 | + let ext = |
| 486 | + ( { txt = Ext_name.bivariant_pmty_with; loc }, |
| 487 | + PSig [ { psig_loc = loc; psig_desc } ] ) |
| 488 | + in |
| 489 | + Pmty_extension ext |
| 490 | + |
| 491 | + let decode_bivariant_pmty_with ~loc payload = |
| 492 | + match payload with |
| 493 | + | PSig |
| 494 | + [ |
| 495 | + { |
| 496 | + psig_desc = |
| 497 | + Psig_module |
| 498 | + { |
| 499 | + pmd_name = { txt = None; _ }; |
| 500 | + pmd_attributes = []; |
| 501 | + pmd_type = |
| 502 | + { pmty_attributes = []; pmty_desc = Pmty_with _ as x; _ }; |
| 503 | + _; |
| 504 | + }; |
| 505 | + _; |
| 506 | + }; |
| 507 | + ] -> |
| 508 | + x |
| 509 | + | _ -> invalid_encoding ~loc "bivariant pmty_with" |
362 | 510 | end |
363 | 511 |
|
364 | 512 | module To_502 = struct |
365 | | - include Make (Ast_502) |
| 513 | + include Make (Ast_502_arg) |
366 | 514 | end |
0 commit comments