Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Map_AST.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347(* Yoann Padioleau * * Copyright (C) 2019 r2c * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation, with the * special exception on linking described in file LICENSE. * * This library 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 file * LICENSE for more details. *) open OCaml open AST_generic module G = AST_generic (*****************************************************************************) (* Prelude *) (*****************************************************************************) (* hooks *) type visitor_in = { kexpr : (expr -> expr) * visitor_out -> expr -> expr; kstmt : (stmt -> stmt) * visitor_out -> stmt -> stmt; kinfo : (tok -> tok) * visitor_out -> tok -> tok; kidinfo : (id_info -> id_info) * visitor_out -> id_info -> id_info; klit : (literal -> literal) * visitor_out -> literal -> literal; kargs : (argument list -> argument list) * visitor_out -> argument list -> argument list; kname : (name -> name) * visitor_out -> name -> name; } and visitor_out = { vitem : item -> item; vprogram : program -> program; vexpr : expr -> expr; vany : any -> any; } let default_visitor = { kexpr = (fun (k, _) x -> k x); kstmt = (fun (k, _) x -> k x); kinfo = (fun (k, _) x -> k x); kidinfo = (fun (k, _) x -> k x); klit = (fun (k, _) x -> k x); kargs = (fun (k, _) x -> k x); kname = (fun (k, _) x -> k x); } let map_id x = x let (mk_visitor : visitor_in -> visitor_out) = fun vin -> (* start of auto generation *) (* generated by ocamltarzan with: camlp4o -o /tmp/yyy.ml -I pa/ pa_type_conv.cmo pa_map.cmo pr_o.cmo /tmp/xxx.ml *) let rec map_tok v = (* old: Parse_info.map_info v *) let k x = match x with | { Parse_info.token = v_pinfo; transfo = v_transfo } -> let v_pinfo = (* todo? map_pinfo v_pinfo *) v_pinfo in (* not recurse in transfo ? *) { Parse_info.token = v_pinfo; (* generete a fresh field *) transfo = v_transfo; } in vin.kinfo (k, all_functions) v and map_wrap : 'a. ('a -> 'a) -> 'a wrap -> 'a wrap = fun _of_a (v1, v2) -> let v1 = _of_a v1 and v2 = map_tok v2 in (v1, v2) and map_sid x = x and map_bracket : 'a. ('a -> 'a) -> 'a bracket -> 'a bracket = fun of_a (v1, v2, v3) -> let v1 = map_tok v1 and v2 = of_a v2 and v3 = map_tok v3 in (v1, v2, v3) and map_ident v = map_wrap map_of_string v and map_dotted_ident v = map_of_list map_ident v and map_ident_and_targs_opt (id, topt) = let id = map_ident id in let topt = map_of_option map_type_arguments topt in (id, topt) and map_qualifier = function | QDots v -> QDots (map_of_list map_ident_and_targs_opt v) | QExpr (e, t) -> let e = map_expr e in let t = map_tok t in QExpr (e, t) and map_module_name = function | FileName v1 -> let v1 = map_wrap map_of_string v1 in FileName v1 | DottedName v1 -> let v1 = map_dotted_ident v1 in DottedName v1 and map_resolved_name (v1, v2) = let v1 = map_resolved_name_kind v1 in let v2 = map_sid v2 in (v1, v2) and map_canonical_name v1 = map_of_list map_of_string v1 and map_resolved_name_kind = function | LocalVar -> LocalVar | Parameter -> Parameter | EnclosedVar -> EnclosedVar | Global -> Global | ImportedEntity v1 -> let v1 = map_canonical_name v1 in ImportedEntity v1 | ImportedModule v1 -> let v1 = map_canonical_name v1 in ImportedModule v1 | Macro -> Macro | EnumConstant -> EnumConstant | TypeName -> TypeName | GlobalName (v1, v2) -> let v1 = map_canonical_name v1 in let v2 = map_of_list map_canonical_name v2 in GlobalName (v1, v2) and map_name_info { name_last = v1; name_middle = v_name_qualifier; name_top = v_top; name_info = v2; } = let v1 = map_ident_and_targs_opt v1 in let v2 = map_id_info v2 in let v_top = map_of_option map_tok v_top in let v_name_qualifier = map_of_option map_qualifier v_name_qualifier in { name_last = v1; name_info = v2; name_middle = v_name_qualifier; name_top = v_top; } and map_id_info v = let k x = match x with | { id_resolved = v_id_resolved; id_type = v_id_type; id_svalue = v3; ; id_info_id; } -> let v3 = map_of_ref (map_of_option map_svalue) v3 in let v_id_type = map_of_ref (map_of_option map_type_) v_id_type in let v_id_resolved = map_of_ref (map_of_option map_resolved_name) v_id_resolved in let = map_of_bool id_hidden in { id_resolved = v_id_resolved; id_type = v_id_type; id_svalue = v3; id_hidden; id_info_id; } in vin.kidinfo (k, all_functions) v and map_xml { xml_kind = v_xml_tag; xml_attrs = v_xml_attrs; xml_body = v_xml_body } = let v_xml_body = map_of_list map_xml_body v_xml_body in let v_xml_attrs = map_of_list map_xml_attribute v_xml_attrs in let v_xml_tag = map_xml_kind v_xml_tag in { xml_kind = v_xml_tag; xml_attrs = v_xml_attrs; xml_body = v_xml_body } and map_xml_kind = function | XmlClassic (v0, v1, v2, v3) -> let v0 = map_tok v0 in let v1 = map_ident v1 in let v2 = map_tok v2 in let v3 = map_tok v3 in XmlClassic (v0, v1, v2, v3) | XmlSingleton (v0, v1, v2) -> let v0 = map_tok v0 in let v1 = map_ident v1 in let v2 = map_tok v2 in XmlSingleton (v0, v1, v2) | XmlFragment (v1, v2) -> let v1 = map_tok v1 in let v2 = map_tok v2 in XmlFragment (v1, v2) and map_xml_attribute = function | XmlAttr (v1, t, v2) -> let v1 = map_ident v1 and t = map_tok t and v2 = map_xml_attr v2 in XmlAttr (v1, t, v2) | XmlAttrExpr v -> let v = map_bracket map_expr v in XmlAttrExpr v | XmlEllipsis v -> let v = map_tok v in XmlEllipsis v and map_xml_attr v = map_expr v and map_xml_body = function | XmlText v1 -> let v1 = map_wrap map_of_string v1 in XmlText v1 | XmlExpr v1 -> let v1 = map_bracket (map_of_option map_expr) v1 in XmlExpr v1 | XmlXml v1 -> let v1 = map_xml v1 in XmlXml v1 and map_name name = let k = function | Id (v1, v2) -> let v1 = map_ident v1 and v2 = map_id_info v2 in Id (v1, v2) | IdQualified v1 -> let v1 = map_name_info v1 in IdQualified v1 in vin.kname (k, all_functions) name and map_expr x = let k x = let ekind = match x.e with | ParenExpr v1 -> let v1 = map_bracket map_expr v1 in ParenExpr v1 | N v1 -> let v1 = map_name v1 in N v1 | DotAccessEllipsis (v1, v2) -> let v1 = map_expr v1 in let v2 = map_tok v2 in DotAccessEllipsis (v1, v2) | DisjExpr (v1, v2) -> let v1 = map_expr v1 in let v2 = map_expr v2 in DisjExpr (v1, v2) | L v1 -> let v1 = map_literal v1 in L v1 | Container (v1, v2) -> let v1 = map_container_operator v1 and v2 = map_bracket (map_of_list map_expr) v2 in Container (v1, v2) | Comprehension (v1, v2) -> let v1 = map_container_operator v1 and v2 = map_bracket map_of_comprehension v2 in Comprehension (v1, v2) | Record v1 -> let v1 = map_bracket (map_of_list map_field) v1 in Record v1 | Constructor (v1, v2) -> let v1 = map_name v1 and v2 = map_bracket (map_of_list map_expr) v2 in Constructor (v1, v2) | RegexpTemplate (v1, v2) -> let v1 = map_bracket map_expr v1 in let v2 = map_of_option (map_wrap map_of_string) v2 in RegexpTemplate (v1, v2) | Lambda v1 -> let v1 = map_function_definition v1 in Lambda v1 | AnonClass v1 -> let v1 = map_class_definition v1 in AnonClass v1 | Xml v1 -> let v1 = map_xml v1 in Xml v1 | IdSpecial v1 -> let v1 = map_wrap map_special v1 in IdSpecial v1 | Call (v1, v2) -> let v1 = map_expr v1 and v2 = map_arguments v2 in Call (v1, v2) | New (v1, v2, v3) -> let v1 = map_tok v1 and v2 = map_type_ v2 and v3 = map_arguments v3 in New (v1, v2, v3) | Assign (v1, v2, v3) -> let v1 = map_expr v1 and v2 = map_tok v2 and v3 = map_expr v3 in Assign (v1, v2, v3) | AssignOp (v1, v2, v3) -> let v1 = map_expr v1 and v2 = map_wrap map_arithmetic_operator v2 and v3 = map_expr v3 in AssignOp (v1, v2, v3) | LetPattern (v1, v2) -> let v1 = map_pattern v1 and v2 = map_expr v2 in LetPattern (v1, v2) | DotAccess (v1, t, v2) -> let v1 = map_expr v1 and t = map_tok t and v2 = map_field_name v2 in DotAccess (v1, t, v2) | ArrayAccess (v1, v2) -> let v1 = map_expr v1 and v2 = map_bracket map_expr v2 in ArrayAccess (v1, v2) | SliceAccess (v1, v2) -> let f = map_of_option map_expr in let v1 = map_expr v1 and v2 = map_bracket (OCaml.map_of_all3 f f f) v2 in SliceAccess (v1, v2) | Conditional (v1, v2, v3) -> let v1 = map_expr v1 and v2 = map_expr v2 and v3 = map_expr v3 in Conditional (v1, v2, v3) | TypedMetavar (v1, v2, v3) -> let v1 = map_ident v1 and v2 = map_tok v2 and v3 = map_type_ v3 in TypedMetavar (v1, v2, v3) | Yield (t, v1, v2) -> let t = map_tok t in let v1 = map_of_option map_expr v1 and v2 = map_of_bool v2 in Yield (t, v1, v2) | Await (t, v1) -> let t = map_tok t in let v1 = map_expr v1 in Await (t, v1) | Cast (v1, t, v2) -> let v1 = map_type_ v1 and t = map_tok t and v2 = map_expr v2 in Cast (v1, t, v2) | Seq v1 -> let v1 = map_of_list map_expr v1 in Seq v1 | Ref (t, v1) -> let t = map_tok t in let v1 = map_expr v1 in Ref (t, v1) | DeRef (t, v1) -> let t = map_tok t in let v1 = map_expr v1 in DeRef (t, v1) | Alias ((str, t), v1) -> let t = map_tok t in let v1 = map_expr v1 in Alias ((str, t), v1) | Ellipsis v1 -> let v1 = map_tok v1 in Ellipsis v1 | DeepEllipsis v1 -> let v1 = map_bracket map_expr v1 in DeepEllipsis v1 | StmtExpr v1 -> let v1 = map_stmt v1 in StmtExpr v1 | OtherExpr (v1, v2) -> let v1 = map_todo_kind v1 and v2 = map_of_list map_any v2 in OtherExpr (v1, v2) | RawExpr x -> RawExpr (map_raw_tree x) in (* TODO? reuse the e_id or create a new one? *) G.e ekind in vin.kexpr (k, all_functions) x and map_of_comprehension (v1, v2) = let v1 = map_expr v1 in let v2 = map_of_list map_for_or_if_comp v2 in (v1, v2) and map_for_or_if_comp = function | CompFor (v1, v2, v3, v4) -> let v1 = map_tok v1 in let v2 = map_pattern v2 in let v3 = map_tok v3 in let v4 = map_expr v4 in CompFor (v1, v2, v3, v4) | CompIf (v1, v2) -> let v1 = map_tok v1 in let v2 = map_expr v2 in CompIf (v1, v2) and map_field_name = function | FN v1 -> let v1 = map_name v1 in FN v1 | FDynamic v1 -> let v1 = map_expr v1 in FDynamic v1 and map_entity_name = function | EN v1 -> let v1 = map_name v1 in EN v1 | EDynamic v1 -> let v1 = map_expr v1 in EDynamic v1 | EPattern v1 -> let v1 = map_pattern v1 in EPattern v1 | OtherEntity (v1, v2) -> let v1 = map_todo_kind v1 and v2 = map_of_list map_any v2 in OtherEntity (v1, v2) and map_literal lit = let k = function | Unit v1 -> let v1 = map_tok v1 in Unit v1 | Bool v1 -> let v1 = map_wrap map_of_bool v1 in Bool v1 | Int v1 -> let v1 = map_wrap map_id v1 in Int v1 | Float v1 -> let v1 = map_wrap map_id v1 in Float v1 | Imag v1 -> let v1 = map_wrap map_of_string v1 in Imag v1 | Ratio v1 -> let v1 = map_wrap map_of_string v1 in Ratio v1 | Atom (v0, v1) -> let v0 = map_tok v0 in let v1 = map_wrap map_of_string v1 in Atom (v0, v1) | Char v1 -> let v1 = map_wrap map_of_string v1 in Char v1 | String v1 -> let v1 = map_bracket (map_wrap map_of_string) v1 in String v1 | Regexp (v1, v2) -> let v1 = map_bracket (map_wrap map_of_string) v1 in let v2 = map_of_option (map_wrap map_of_string) v2 in Regexp (v1, v2) | Null v1 -> let v1 = map_tok v1 in Null v1 | Undefined v1 -> let v1 = map_tok v1 in Undefined v1 in vin.klit (k, all_functions) lit and map_const_type = function | Cbool -> Cbool | Cint -> Cint | Cstr -> Cstr | Cany -> Cany and map_svalue = function | Lit v1 -> let v1 = map_literal v1 in Lit v1 | Cst v1 -> let v1 = map_const_type v1 in Cst v1 | Sym v1 -> let v1 = map_expr v1 in Sym v1 | NotCst -> NotCst and map_container_operator x = x and map_special x = match x with | ForOf | Defined | This | Super | Self | Parent | Eval | Typeof | Instanceof | Sizeof | Spread | HashSplat | NextArrayIndex | Require | InterpolatedElement -> x | Op v1 -> let v1 = map_arithmetic_operator v1 in Op v1 | EncodedString v1 -> let v1 = map_of_string v1 in EncodedString v1 | IncrDecr (v1, v2) -> let v1 = map_of_incdec v1 and v2 = map_of_prepost v2 in IncrDecr (v1, v2) | ConcatString v1 -> let v1 = map_of_interpolated_kind v1 in ConcatString v1 and map_of_interpolated_kind x = x and map_of_incdec x = x and map_of_prepost x = x and map_arithmetic_operator x = x and map_arguments v = map_bracket map_argument_list v and map_argument_list v = let k = map_of_list map_argument in vin.kargs (k, all_functions) v and map_argument = function | Arg v1 -> let v1 = map_expr v1 in Arg v1 | ArgType v1 -> let v1 = map_type_ v1 in ArgType v1 | ArgKwd (v1, v2) -> let v1 = map_ident v1 in let v2 = map_expr v2 in ArgKwd (v1, v2) | ArgKwdOptional (v1, v2) -> let v1 = map_ident v1 in let v2 = map_expr v2 in ArgKwdOptional (v1, v2) | OtherArg (v1, v2) -> let v1 = map_other_argument_operator v1 and v2 = map_of_list map_any v2 in OtherArg (v1, v2) and map_other_argument_operator x = x and map_type_ { t; t_attrs } = let t = map_type_kind t in let t_attrs = map_of_list map_attribute t_attrs in { t; t_attrs } and map_type_kind = function | TyEllipsis v1 -> let v1 = map_tok v1 in TyEllipsis v1 | TyRecordAnon (v0, v1) -> let v0 = map_class_kind v0 in let v1 = map_bracket (map_of_list map_field) v1 in TyRecordAnon (v0, v1) | TyOr (v1, v2, v3) -> let v1 = map_type_ v1 in let v2 = map_tok v2 in let v3 = map_type_ v3 in TyOr (v1, v2, v3) | TyAnd (v1, v2, v3) -> let v1 = map_type_ v1 in let v2 = map_tok v2 in let v3 = map_type_ v3 in TyAnd (v1, v2, v3) | TyFun (v1, v2) -> let v1 = map_of_list map_parameter v1 and v2 = map_type_ v2 in TyFun (v1, v2) | TyApply (v1, v2) -> let v1 = map_type_ v1 and v2 = map_type_arguments v2 in TyApply (v1, v2) | TyN v1 -> let v1 = map_name v1 in TyN v1 | TyVar v1 -> let v1 = map_ident v1 in TyVar v1 | TyAny v1 -> let v1 = map_tok v1 in TyAny v1 | TyArray (v1, v2) -> let v1 = map_bracket (map_of_option map_expr) v1 and v2 = map_type_ v2 in TyArray (v1, v2) | TyPointer (t, v1) -> let t = map_tok t in let v1 = map_type_ v1 in TyPointer (t, v1) | TyRef (t, v1) -> let t = map_tok t in let v1 = map_type_ v1 in TyRef (t, v1) | TyTuple v1 -> let v1 = map_bracket (map_of_list map_type_) v1 in TyTuple v1 | TyQuestion (v1, t) -> let t = map_tok t in let v1 = map_type_ v1 in TyQuestion (v1, t) | TyRest (t, v1) -> let v1 = map_type_ v1 in let t = map_tok t in TyRest (t, v1) | TyExpr v1 -> let v1 = map_expr v1 in TyExpr v1 | OtherType (v1, v2) -> let v1 = map_todo_kind v1 and v2 = map_of_list map_any v2 in OtherType (v1, v2) and map_type_arguments v = map_bracket (map_of_list map_type_argument) v and map_type_argument = function | TA v1 -> let v1 = map_type_ v1 in TA v1 | TAWildcard (v1, v2) -> let v1 = map_tok v1 in let v2 = map_of_option (fun (v1, v2) -> (map_wrap map_of_bool v1, map_type_ v2)) v2 in TAWildcard (v1, v2) | TAExpr v1 -> let v1 = map_expr v1 in TAExpr v1 | OtherTypeArg (v1, v2) -> let v1 = map_todo_kind v1 in let v2 = map_of_list map_any v2 in OtherTypeArg (v1, v2) and map_todo_kind x = x and map_attribute = function | KeywordAttr v1 -> let v1 = map_wrap map_keyword_attribute v1 in KeywordAttr v1 | NamedAttr (t, v1, v3) -> let t = map_tok t in let v1 = map_name v1 and v3 = map_bracket (map_of_list map_argument) v3 in NamedAttr (t, v1, v3) | OtherAttribute (v1, v2) -> let v1 = map_other_attribute_operator v1 and v2 = map_of_list map_any v2 in OtherAttribute (v1, v2) and map_keyword_attribute x = x and map_other_attribute_operator x = x and map_stmt x = let k x = let skind = match x.s with | DisjStmt (v1, v2) -> let v1 = map_stmt v1 in let v2 = map_stmt v2 in DisjStmt (v1, v2) | ExprStmt (v1, t) -> let v1 = map_expr v1 in let t = map_tok t in ExprStmt (v1, t) | DefStmt v1 -> let v1 = map_definition v1 in DefStmt v1 | DirectiveStmt v1 -> let v1 = map_directive v1 in DirectiveStmt v1 | Block v1 -> let v1 = map_bracket (map_of_list map_stmt) v1 in Block v1 | If (t, v1, v2, v3) -> let t = map_tok t in let v1 = map_condition v1 and v2 = map_stmt v2 and v3 = map_of_option map_stmt v3 in If (t, v1, v2, v3) | While (t, v1, v2) -> let t = map_tok t in let v1 = map_condition v1 and v2 = map_stmt v2 in While (t, v1, v2) | DoWhile (t, v1, v2) -> let t = map_tok t in let v1 = map_stmt v1 and v2 = map_expr v2 in DoWhile (t, v1, v2) | For (t, v1, v2) -> let t = map_tok t in let v1 = map_for_header v1 and v2 = map_stmt v2 in For (t, v1, v2) | Switch (v0, v1, v2) -> let v0 = map_tok v0 in let v1 = map_of_option map_condition v1 and v2 = map_of_list map_case_and_body v2 in Switch (v0, v1, v2) | Return (t, v1, sc) -> let t = map_tok t in let v1 = map_of_option map_expr v1 in let sc = map_tok sc in Return (t, v1, sc) | Continue (t, v1, sc) -> let t = map_tok t in let v1 = map_label_ident v1 in let sc = map_tok sc in Continue (t, v1, sc) | Break (t, v1, sc) -> let t = map_tok t in let v1 = map_label_ident v1 in let sc = map_tok sc in Break (t, v1, sc) | Label (v1, v2) -> let v1 = map_label v1 and v2 = map_stmt v2 in Label (v1, v2) | Goto (t, v1, sc) -> let t = map_tok t in let v1 = map_label v1 in let sc = map_tok sc in Goto (t, v1, sc) | Throw (t, v1, sc) -> let t = map_tok t in let v1 = map_expr v1 in let sc = map_tok sc in Throw (t, v1, sc) | Try (t, v1, v2, v3) -> let t = map_tok t in let v1 = map_stmt v1 and v2 = map_of_list map_catch v2 and v3 = map_of_option map_finally v3 in Try (t, v1, v2, v3) | WithUsingResource (t, v1, v2) -> let t = map_tok t in let v1 = map_of_list map_stmt v1 in let v2 = map_stmt v2 in WithUsingResource (t, v1, v2) | Assert (t, args, sc) -> let t = map_tok t in let args = map_arguments args in let sc = map_tok sc in Assert (t, args, sc) | OtherStmtWithStmt (v1, v2, v3) -> let v1 = map_other_stmt_with_stmt_operator v1 and v2 = map_of_list map_any v2 and v3 = map_stmt v3 in OtherStmtWithStmt (v1, v2, v3) | OtherStmt (v1, v2) -> let v1 = map_other_stmt_operator v1 and v2 = map_of_list map_any v2 in OtherStmt (v1, v2) in { x with s = skind } in vin.kstmt (k, all_functions) x and map_condition = function | Cond e -> let e = map_expr e in Cond e | OtherCond (v1, v2) -> let v1 = map_todo_kind v1 and v2 = map_of_list map_any v2 in OtherCond (v1, v2) and map_other_stmt_with_stmt_operator x = x and map_label_ident = function | LNone -> LNone | LId v1 -> let v1 = map_label v1 in LId v1 | LInt v1 -> let v1 = map_wrap map_of_int v1 in LInt v1 | LDynamic v1 -> let v1 = map_expr v1 in LDynamic v1 and map_case_and_body = function | CasesAndBody (v1, v2) -> let v1 = map_of_list map_case v1 and v2 = map_stmt v2 in CasesAndBody (v1, v2) | CaseEllipsis v1 -> let v1 = map_tok v1 in CaseEllipsis v1 and map_case = function | OtherCase (v1, v2) -> let v1 = map_todo_kind v1 in let v2 = map_of_list map_any v2 in OtherCase (v1, v2) | Case (t, v1) -> let t = map_tok t in let v1 = map_pattern v1 in Case (t, v1) | CaseEqualExpr (t, v1) -> let t = map_tok t in let v1 = map_expr v1 in CaseEqualExpr (t, v1) | Default t -> let t = map_tok t in Default t and map_catch (t, v1, v2) = let t = map_tok t in let v1 = map_catch_exn v1 and v2 = map_stmt v2 in (t, v1, v2) and map_catch_exn = function | OtherCatch (v1, v2) -> let v1 = map_todo_kind v1 in let v2 = map_of_list map_any v2 in OtherCatch (v1, v2) | CatchPattern v1 -> let v1 = map_pattern v1 in CatchPattern v1 | CatchParam p -> let p = map_parameter_classic p in CatchParam p and map_finally v = map_tok_and_stmt v and map_tok_and_stmt (t, v) = let t = map_tok t in let v = map_stmt v in (t, v) and map_label v = map_ident v and map_for_header = function | ForClassic (v1, v2, v3) -> let v1 = map_of_list map_for_var_or_expr v1 and v2 = map_of_option map_expr v2 and v3 = map_of_option map_expr v3 in ForClassic (v1, v2, v3) | ForEach v1 -> ForEach (map_for_each v1) | MultiForEach v1 -> MultiForEach (map_of_list map_multi_for_each v1) | ForEllipsis t -> let t = map_tok t in ForEllipsis t | ForIn (v1, v2) -> let v1 = map_of_list map_for_var_or_expr v1 and v2 = map_of_list map_expr v2 in ForIn (v1, v2) and map_for_each (v1, t, v2) = let t = map_tok t in let v1 = map_pattern v1 and v2 = map_expr v2 in (v1, t, v2) and map_multi_for_each = function | FE v1 -> FE (map_for_each v1) | FECond (v1, t, v2) -> FECond (map_for_each v1, map_tok t, map_expr v2) | FEllipsis t -> FEllipsis (map_tok t) and map_for_var_or_expr = function | ForInitVar (v1, v2) -> let v1 = map_entity v1 and v2 = map_variable_definition v2 in ForInitVar (v1, v2) | ForInitExpr v1 -> let v1 = map_expr v1 in ForInitExpr v1 and map_other_stmt_operator x = x and map_pattern = function | PatEllipsis v1 -> let v1 = map_tok v1 in PatEllipsis v1 | PatRecord v1 -> let v1 = map_bracket (map_of_list (fun (v1, v2) -> let v1 = map_dotted_ident v1 and v2 = map_pattern v2 in (v1, v2))) v1 in PatRecord v1 | PatId (v1, v2) -> let v1 = map_ident v1 and v2 = map_id_info v2 in PatId (v1, v2) | PatLiteral v1 -> let v1 = map_literal v1 in PatLiteral v1 | PatType v1 -> let v1 = map_type_ v1 in PatType v1 | PatConstructor (v1, v2) -> let v1 = map_name v1 and v2 = map_of_list map_pattern v2 in PatConstructor (v1, v2) | PatTuple v1 -> let v1 = map_bracket (map_of_list map_pattern) v1 in PatTuple v1 | PatList v1 -> let v1 = map_bracket (map_of_list map_pattern) v1 in PatList v1 | PatKeyVal (v1, v2) -> let v1 = map_pattern v1 and v2 = map_pattern v2 in PatKeyVal (v1, v2) | PatUnderscore v1 -> let v1 = map_tok v1 in PatUnderscore v1 | PatDisj (v1, v2) -> let v1 = map_pattern v1 and v2 = map_pattern v2 in PatDisj (v1, v2) | DisjPat (v1, v2) -> let v1 = map_pattern v1 and v2 = map_pattern v2 in DisjPat (v1, v2) | PatTyped (v1, v2) -> let v1 = map_pattern v1 and v2 = map_type_ v2 in PatTyped (v1, v2) | PatAs (v1, v2) -> let v1 = map_pattern v1 and v2 = match v2 with | v1, v2 -> let v1 = map_ident v1 and v2 = map_id_info v2 in (v1, v2) in PatAs (v1, v2) | PatWhen (v1, v2) -> let v1 = map_pattern v1 and v2 = map_expr v2 in PatWhen (v1, v2) | OtherPat (v1, v2) -> let v1 = map_other_pattern_operator v1 and v2 = map_of_list map_any v2 in OtherPat (v1, v2) and map_other_pattern_operator x = x and map_definition (v1, v2) = let v1 = map_entity v1 and v2 = map_definition_kind v2 in (v1, v2) and map_entity { name = v_name; attrs = v_attrs; tparams = v_tparams } = let v_tparams = map_of_list map_type_parameter v_tparams in let v_attrs = map_of_list map_attribute v_attrs in let v_name = map_entity_name v_name in { name = v_name; attrs = v_attrs; tparams = v_tparams } and map_enum_entry_definition { ee_args; ee_body } = let ee_args = map_of_option map_arguments ee_args in let ee_body = map_of_option (map_bracket (map_of_list map_field)) ee_body in { ee_args; ee_body } and map_definition_kind = function | EnumEntryDef v1 -> let v1 = map_enum_entry_definition v1 in EnumEntryDef v1 | FuncDef v1 -> let v1 = map_function_definition v1 in FuncDef v1 | VarDef v1 -> let v1 = map_variable_definition v1 in VarDef v1 | FieldDefColon v1 -> let v1 = map_variable_definition v1 in FieldDefColon v1 | ClassDef v1 -> let v1 = map_class_definition v1 in ClassDef v1 | TypeDef v1 -> let v1 = map_type_definition v1 in TypeDef v1 | ModuleDef v1 -> let v1 = map_module_definition v1 in ModuleDef v1 | MacroDef v1 -> let v1 = map_macro_definition v1 in MacroDef v1 | Signature v1 -> let v1 = map_type_ v1 in Signature v1 | UseOuterDecl v1 -> let v1 = map_tok v1 in UseOuterDecl v1 | OtherDef (v1, v2) -> let v1 = map_other_def_operator v1 in let v2 = map_of_list map_any v2 in OtherDef (v1, v2) and map_other_def_operator x = x and map_module_definition { mbody = v_mbody } = let v_mbody = map_module_definition_kind v_mbody in { mbody = v_mbody } and map_module_definition_kind = function | ModuleAlias v1 -> let v1 = map_dotted_ident v1 in ModuleAlias v1 | ModuleStruct (v1, v2) -> let v1 = map_of_option map_dotted_ident v1 and v2 = map_of_list map_item v2 in ModuleStruct (v1, v2) | OtherModule (v1, v2) -> let v1 = map_other_module_operator v1 and v2 = map_of_list map_any v2 in OtherModule (v1, v2) and map_other_module_operator x = x and map_macro_definition { macroparams = v_macroparams; macrobody = v_macrobody } = let v_macrobody = map_of_list map_any v_macrobody in let v_macroparams = map_of_list map_ident v_macroparams in { macroparams = v_macroparams; macrobody = v_macrobody } and map_type_parameter = function | TParamEllipsis v1 -> let v1 = map_tok v1 in TParamEllipsis v1 | TP v1 -> let v1 = map_type_parameter_classic v1 in TP v1 | OtherTypeParam (t, xs) -> let t = map_todo_kind t in let xs = map_of_list map_any xs in OtherTypeParam (t, xs) and map_type_parameter_classic { tp_id = v1; tp_attrs = v2; tp_bounds = v3; tp_default = v4; tp_variance = v5; } = let v1 = map_ident v1 in let v2 = map_of_list map_attribute v2 in let v3 = map_of_list map_type_ v3 in let v4 = map_of_option map_type_ v4 in let v5 = map_of_option (map_wrap map_variance) v5 in { tp_id = v1; tp_attrs = v2; tp_bounds = v3; tp_default = v4; tp_variance = v5; } and map_variance = function | Covariant -> Covariant | Contravariant -> Contravariant and map_function_kind x = x and map_function_definition { fkind; fparams = v_fparams; frettype = v_frettype; fbody = v_fbody } = let fkind = map_wrap map_function_kind fkind in let v_fbody = map_function_body v_fbody in let v_frettype = map_of_option map_type_ v_frettype in let v_fparams = map_parameters v_fparams in { fkind; fparams = v_fparams; frettype = v_frettype; fbody = v_fbody } and map_parameters v = map_bracket (map_of_list map_parameter) v and map_parameter = function | Param v1 -> let v1 = map_parameter_classic v1 in Param v1 | ParamRest (v0, v1) -> let v0 = map_tok v0 in let v1 = map_parameter_classic v1 in ParamRest (v0, v1) | ParamHashSplat (v0, v1) -> let v0 = map_tok v0 in let v1 = map_parameter_classic v1 in ParamHashSplat (v0, v1) | ParamPattern v1 -> let v1 = map_pattern v1 in ParamPattern v1 | ParamEllipsis v1 -> let v1 = map_tok v1 in ParamEllipsis v1 | OtherParam (v1, v2) -> let v1 = map_todo_kind v1 and v2 = map_of_list map_any v2 in OtherParam (v1, v2) and map_parameter_classic { pname = v_pname; pdefault = v_pdefault; ptype = v_ptype; pattrs = v_pattrs; pinfo = v_pinfo; } = let v_pinfo = map_id_info v_pinfo in let v_pattrs = map_of_list map_attribute v_pattrs in let v_ptype = map_of_option map_type_ v_ptype in let v_pdefault = map_of_option map_expr v_pdefault in let v_pname = map_of_option map_ident v_pname in { pname = v_pname; pdefault = v_pdefault; ptype = v_ptype; pattrs = v_pattrs; pinfo = v_pinfo; } and map_function_body = function | FBStmt v1 -> let v1 = map_stmt v1 in FBStmt v1 | FBExpr v1 -> let v1 = map_expr v1 in FBExpr v1 | FBDecl v1 -> let v1 = map_tok v1 in FBDecl v1 | FBNothing -> FBNothing and map_variable_definition { vinit = v_vinit; vtype = v_vtype } = let v_vtype = map_of_option map_type_ v_vtype in let v_vinit = map_of_option map_expr v_vinit in { vinit = v_vinit; vtype = v_vtype } and map_field = function | F v1 -> let v1 = map_stmt v1 in F v1 and map_type_definition { tbody = v_tbody } = let v_tbody = map_type_definition_kind v_tbody in { tbody = v_tbody } and map_type_definition_kind = function | OrType v1 -> let v1 = map_of_list map_or_type_element v1 in OrType v1 | AndType v1 -> let v1 = map_bracket (map_of_list map_field) v1 in AndType v1 | AliasType v1 -> let v1 = map_type_ v1 in AliasType v1 | NewType v1 -> let v1 = map_type_ v1 in NewType v1 | Exception (v1, v2) -> let v1 = map_ident v1 and v2 = map_of_list map_type_ v2 in Exception (v1, v2) | AbstractType v1 -> let v1 = map_tok v1 in AbstractType v1 | OtherTypeKind (v1, v2) -> let v1 = map_other_type_kind_operator v1 and v2 = map_of_list map_any v2 in OtherTypeKind (v1, v2) and map_other_type_kind_operator x = x and map_or_type_element = function | OrConstructor (v1, v2) -> let v1 = map_ident v1 and v2 = map_of_list map_type_ v2 in OrConstructor (v1, v2) | OrEnum (v1, v2) -> let v1 = map_ident v1 and v2 = map_of_option map_expr v2 in OrEnum (v1, v2) | OrUnion (v1, v2) -> let v1 = map_ident v1 and v2 = map_type_ v2 in OrUnion (v1, v2) and map_class_definition { ckind = v_ckind; cextends = v_cextends; cimplements = v_cimplements; cbody = v_cbody; cmixins = v_cmixins; cparams; } = let v_cbody = map_bracket (map_of_list map_field) v_cbody in let v_cmixins = map_of_list map_type_ v_cmixins in let v_cimplements = map_of_list map_type_ v_cimplements in let v_cextends = map_of_list map_class_parent v_cextends in let v_ckind = map_class_kind v_ckind in let cparams = map_parameters cparams in { ckind = v_ckind; cextends = v_cextends; cimplements = v_cimplements; cbody = v_cbody; cmixins = v_cmixins; cparams; } and map_class_kind (x, t) = (x, map_tok t) and map_class_parent (v1, v2) = let v1 = map_type_ v1 in let v2 = map_of_option map_arguments v2 in (v1, v2) and map_directive { d; d_attrs } = let d = map_directive_kind d in let d_attrs = map_of_list map_attribute d_attrs in { d; d_attrs } and map_directive_kind = function | ImportFrom (t, v1, v2) -> let t = map_tok t in let v1 = map_module_name v1 in let v2 = map_of_list map_alias v2 in ImportFrom (t, v1, v2) | ImportAs (t, v1, v2) -> let t = map_tok t in let v1 = map_module_name v1 and v2 = map_of_option map_ident_and_id_info v2 in ImportAs (t, v1, v2) | ImportAll (t, v1, v2) -> let t = map_tok t in let v1 = map_module_name v1 and v2 = map_tok v2 in ImportAll (t, v1, v2) | Pragma (v1, v2) -> let v1 = map_ident v1 and v2 = map_of_list map_any v2 in Pragma (v1, v2) | Package (t, v1) -> let t = map_tok t in let v1 = map_dotted_ident v1 in Package (t, v1) | PackageEnd t -> let t = map_tok t in PackageEnd t | OtherDirective (v1, v2) -> let v1 = map_todo_kind v1 and v2 = map_of_list map_any v2 in OtherDirective (v1, v2) and map_ident_and_id_info (v1, v2) = let v1 = map_ident v1 in let v2 = map_id_info v2 in (v1, v2) and map_alias (v1, v2) = let v1 = map_ident v1 and v2 = map_of_option map_ident_and_id_info v2 in (v1, v2) and map_item x = map_stmt x and map_program v = map_of_list map_item v and map_partial = function | PartialMatch (v1, v2) -> let v1 = map_tok v1 in let v2 = map_expr v2 in PartialMatch (v1, v2) | PartialLambdaOrFuncDef v1 -> let v1 = map_function_definition v1 in PartialLambdaOrFuncDef v1 | PartialDef v1 -> let v1 = map_definition v1 in PartialDef v1 | PartialIf (v1, v2) -> let v1 = map_tok v1 in let v2 = map_expr v2 in PartialIf (v1, v2) | PartialTry (v1, v2) -> let v1 = map_tok v1 in let v2 = map_stmt v2 in PartialTry (v1, v2) | PartialFinally (v1, v2) -> let v1 = map_tok v1 in let v2 = map_stmt v2 in PartialFinally (v1, v2) | PartialCatch v1 -> let v1 = map_catch v1 in PartialCatch v1 | PartialSingleField (v1, v2, v3) -> let v1 = map_wrap map_of_string v1 in let v2 = map_tok v2 in let v3 = map_expr v3 in PartialSingleField (v1, v2, v3) | PartialSwitchCase v1 -> let v1 = map_case_and_body v1 in PartialSwitchCase v1 and map_any = function | Raw v1 -> let v1 = map_raw_tree v1 in Raw v1 | Name v1 -> let v1 = map_name v1 in Name v1 | Xmls v1 -> let v1 = map_of_list map_xml_body v1 in Xmls v1 | ForOrIfComp v1 -> let v1 = map_for_or_if_comp v1 in ForOrIfComp v1 | Tp v1 -> let v1 = map_type_parameter v1 in Tp v1 | Ta v1 -> let v1 = map_type_argument v1 in Ta v1 | Cs v1 -> let v1 = map_case v1 in Cs v1 | Anys v1 -> let v1 = map_of_list map_any v1 in Anys v1 | Str v1 -> let v1 = map_bracket (map_wrap map_of_string) v1 in Str v1 | Args v1 -> let v1 = map_of_list map_argument v1 in Args v1 | Params v1 -> let v1 = map_of_list map_parameter v1 in Params v1 | Flds v1 -> let v1 = map_of_list map_field v1 in Flds v1 | Partial v1 -> let v1 = map_partial v1 in Partial v1 | TodoK v1 -> let v1 = map_ident v1 in TodoK v1 | Tk v1 -> let v1 = map_tok v1 in Tk v1 | I v1 -> let v1 = map_ident v1 in I v1 | Modn v1 -> let v1 = map_module_name v1 in Modn v1 | ModDk v1 -> let v1 = map_module_definition_kind v1 in ModDk v1 | En v1 -> let v1 = map_entity v1 in En v1 | E v1 -> let v1 = map_expr v1 in E v1 | S v1 -> let v1 = map_stmt v1 in S v1 | Ss v1 -> let v1 = map_of_list map_stmt v1 in Ss v1 | T v1 -> let v1 = map_type_ v1 in T v1 | P v1 -> let v1 = map_pattern v1 in P v1 | Def v1 -> let v1 = map_definition v1 in Def v1 | Dir v1 -> let v1 = map_directive v1 in Dir v1 | Fld v1 -> let v1 = map_field v1 in Fld v1 | Di v1 -> let v1 = map_dotted_ident v1 in Di v1 | Pa v1 -> let v1 = map_parameter v1 in Pa v1 | Ce v1 -> let v1 = map_catch_exn v1 in Ce v1 | Ar v1 -> let v1 = map_argument v1 in Ar v1 | At v1 -> let v1 = map_attribute v1 in At v1 | Dk v1 -> let v1 = map_definition_kind v1 in Dk v1 | Pr v1 -> let v1 = map_program v1 in Pr v1 | Lbli v1 -> let v1 = map_label_ident v1 in Lbli v1 and map_raw_tree v = match v with | Token v -> let v = map_wrap map_of_string v in Token v | List v -> let v = (map_of_list map_raw_tree) v in List v | Tuple v -> let v = (map_of_list map_raw_tree) v in Tuple v | Case (v1, v2) -> let v1 = map_of_string v1 in let v2 = map_raw_tree v2 in Case (v1, v2) | Option v -> let v = (map_of_option map_raw_tree) v in Option v | Any v -> let v = map_any v in Any v and all_functions = { vitem = map_item; vprogram = map_program; vexpr = map_expr; vany = map_any; } in all_functions (*****************************************************************************) (* Fix token locations *) (*****************************************************************************) (* Fix token locations to "relocate" a sub-AST. *) let mk_fix_token_locations fix = mk_visitor { default_visitor with kidinfo = (fun (_k, _vout) ii -> (* The id_info contains locations that should not be modified, and they * are likely outside the sub-AST of interest anyways. *) ii); kexpr = (fun (k, _) e -> k { e with e_range = Option.map (fun (x, y) -> (fix x, fix y)) e.e_range; }); kstmt = (fun (k, _) s -> k { s with s_range = Option.map (fun (x, y) -> (fix x, fix y)) s.s_range; }); kinfo = (fun (_, _) t -> Parsing_helpers.fix_token_location fix t); }