forked from jrh13/hol-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pa_j_3.1x_6.02.2.ml
2845 lines (2718 loc) · 94.6 KB
/
pa_j_3.1x_6.02.2.ml
1
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
(* ------------------------------------------------------------------------- *)
(* New version. *)
(* ------------------------------------------------------------------------- *)
(* camlp5r *)
(* $Id: pa_o.ml,v 6.33 2010-11-16 16:48:21 deraugla Exp $ *)
(* Copyright (c) INRIA 2007-2010 *)
#load "pa_extend.cmo";
#load "q_MLast.cmo";
#load "pa_reloc.cmo";
open Pcaml;
Pcaml.syntax_name.val := "OCaml";
Pcaml.no_constructors_arity.val := True;
(* ------------------------------------------------------------------------- *)
(* The main/reloc.ml file. *)
(* ------------------------------------------------------------------------- *)
(* camlp5r *)
(* $Id: reloc.ml,v 6.19 2011-02-17 10:20:50 deraugla Exp $ *)
(* Copyright (c) INRIA 2007-2010 *)
#load "pa_macro.cmo";
open MLast;
value option_map f =
fun
[ Some x -> Some (f x)
| None -> None ]
;
value vala_map f =
IFNDEF STRICT THEN
fun x -> f x
ELSE
fun
[ Ploc.VaAnt s -> Ploc.VaAnt s
| Ploc.VaVal x -> Ploc.VaVal (f x) ]
END
;
value class_infos_map floc f x =
{ciLoc = floc x.ciLoc; ciVir = x.ciVir;
ciPrm =
let (x1, x2) = x.ciPrm in
(floc x1, x2);
ciNam = x.ciNam; ciExp = f x.ciExp}
;
value anti_loc qloc sh loc loc1 =
(*
...<:reloc_expr<.....$lid:...xxxxxxxx...$...>>...
|..|-----------------------------------| qloc
<-----> sh
|.........|------------| loc
|..|------| loc1
*)
let sh1 = Ploc.first_pos qloc + sh in
let sh2 = sh1 + Ploc.first_pos loc in
let line_nb_qloc = Ploc.line_nb qloc in
let line_nb_loc = Ploc.line_nb loc in
let line_nb_loc1 = Ploc.line_nb loc1 in
if line_nb_qloc < 0 || line_nb_loc < 0 || line_nb_loc1 < 0 then
Ploc.make_unlined
(sh2 + Ploc.first_pos loc1, sh2 + Ploc.last_pos loc1)
else
Ploc.make_loc (Ploc.file_name loc)
(line_nb_qloc + line_nb_loc + line_nb_loc1 - 2)
(if line_nb_loc1 = 1 then
if line_nb_loc = 1 then Ploc.bol_pos qloc
else sh1 + Ploc.bol_pos loc
else sh2 + Ploc.bol_pos loc1)
(sh2 + Ploc.first_pos loc1, sh2 + Ploc.last_pos loc1) ""
;
value rec reloc_ctyp floc sh =
self where rec self =
fun
[ TyAcc loc x1 x2 →
let loc = floc loc in
TyAcc loc (self x1) (self x2)
| TyAli loc x1 x2 →
let loc = floc loc in
TyAli loc (self x1) (self x2)
| TyAny loc →
let loc = floc loc in
TyAny loc
| TyApp loc x1 x2 →
let loc = floc loc in
TyApp loc (self x1) (self x2)
| TyArr loc x1 x2 →
let loc = floc loc in
TyArr loc (self x1) (self x2)
| TyCls loc x1 →
let loc = floc loc in
TyCls loc x1
| TyLab loc x1 x2 →
let loc = floc loc in
TyLab loc x1 (self x2)
| TyLid loc x1 →
let loc = floc loc in
TyLid loc x1
| TyMan loc x1 x2 x3 →
let loc = floc loc in
TyMan loc (self x1) x2 (self x3)
| TyObj loc x1 x2 →
let loc = floc loc in
TyObj loc (vala_map (List.map (fun (x1, x2) → (x1, self x2))) x1) x2
| TyOlb loc x1 x2 →
let loc = floc loc in
TyOlb loc x1 (self x2)
| TyPck loc x1 →
let loc = floc loc in
TyPck loc (reloc_module_type floc sh x1)
| TyPol loc x1 x2 →
let loc = floc loc in
TyPol loc x1 (self x2)
| TyPot loc x1 x2 →
let loc = floc loc in
TyPot loc x1 (self x2)
| TyQuo loc x1 →
let loc = floc loc in
TyQuo loc x1
| TyRec loc x1 →
let loc = floc loc in
TyRec loc
(vala_map
(List.map (fun (loc, x1, x2, x3) → (floc loc, x1, x2, self x3)))
x1)
| TySum loc x1 →
let loc = floc loc in
TySum loc
(vala_map
(List.map
(fun (loc, x1, x2, x3) →
(floc loc, x1, vala_map (List.map self) x2,
option_map self x3)))
x1)
| TyTup loc x1 →
let loc = floc loc in
TyTup loc (vala_map (List.map self) x1)
| TyUid loc x1 →
let loc = floc loc in
TyUid loc x1
| TyVrn loc x1 x2 →
let loc = floc loc in
TyVrn loc (vala_map (List.map (reloc_poly_variant floc sh)) x1) x2
| TyXtr loc x1 x2 →
let loc = floc loc in
TyXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_poly_variant floc sh =
fun
[ PvTag loc x1 x2 x3 →
let loc = floc loc in
PvTag loc x1 x2 (vala_map (List.map (reloc_ctyp floc sh)) x3)
| PvInh loc x1 →
let loc = floc loc in
PvInh loc (reloc_ctyp floc sh x1) ]
and reloc_patt floc sh =
self where rec self =
fun
[ PaAcc loc x1 x2 →
let loc = floc loc in
PaAcc loc (self x1) (self x2)
| PaAli loc x1 x2 →
let loc = floc loc in
PaAli loc (self x1) (self x2)
| PaAnt loc x1 →
let new_floc loc1 = anti_loc (floc loc) sh loc loc1 in
reloc_patt new_floc sh x1
| PaAny loc →
let loc = floc loc in
PaAny loc
| PaApp loc x1 x2 →
let loc = floc loc in
PaApp loc (self x1) (self x2)
| PaArr loc x1 →
let loc = floc loc in
PaArr loc (vala_map (List.map self) x1)
| PaChr loc x1 →
let loc = floc loc in
PaChr loc x1
| PaFlo loc x1 →
let loc = floc loc in
PaFlo loc x1
| PaInt loc x1 x2 →
let loc = floc loc in
PaInt loc x1 x2
| PaLab loc x1 →
let loc = floc loc in
PaLab loc
(vala_map
(List.map
(fun (x1, x2) → (self x1, vala_map (option_map self) x2)))
x1)
| PaLaz loc x1 →
let loc = floc loc in
PaLaz loc (self x1)
| PaLid loc x1 →
let loc = floc loc in
PaLid loc x1
| PaNty loc x1 →
let loc = floc loc in
PaNty loc x1
| PaOlb loc x1 x2 →
let loc = floc loc in
PaOlb loc (self x1) (vala_map (option_map (reloc_expr floc sh)) x2)
| PaOrp loc x1 x2 →
let loc = floc loc in
PaOrp loc (self x1) (self x2)
| PaRec loc x1 →
let loc = floc loc in
PaRec loc (vala_map (List.map (fun (x1, x2) → (self x1, self x2))) x1)
| PaRng loc x1 x2 →
let loc = floc loc in
PaRng loc (self x1) (self x2)
| PaStr loc x1 →
let loc = floc loc in
PaStr loc x1
| PaTup loc x1 →
let loc = floc loc in
PaTup loc (vala_map (List.map self) x1)
| PaTyc loc x1 x2 →
let loc = floc loc in
PaTyc loc (self x1) (reloc_ctyp floc sh x2)
| PaTyp loc x1 →
let loc = floc loc in
PaTyp loc x1
| PaUid loc x1 →
let loc = floc loc in
PaUid loc x1
| PaUnp loc x1 x2 →
let loc = floc loc in
PaUnp loc x1 (option_map (reloc_module_type floc sh) x2)
| PaVrn loc x1 →
let loc = floc loc in
PaVrn loc x1
| PaXtr loc x1 x2 →
let loc = floc loc in
PaXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_expr floc sh =
self where rec self =
fun
[ ExAcc loc x1 x2 →
let loc = floc loc in
ExAcc loc (self x1) (self x2)
| ExAnt loc x1 →
let new_floc loc1 = anti_loc (floc loc) sh loc loc1 in
reloc_expr new_floc sh x1
| ExApp loc x1 x2 →
let loc = floc loc in
ExApp loc (self x1) (self x2)
| ExAre loc x1 x2 →
let loc = floc loc in
ExAre loc (self x1) (self x2)
| ExArr loc x1 →
let loc = floc loc in
ExArr loc (vala_map (List.map self) x1)
| ExAsr loc x1 →
let loc = floc loc in
ExAsr loc (self x1)
| ExAss loc x1 x2 →
let loc = floc loc in
ExAss loc (self x1) (self x2)
| ExBae loc x1 x2 →
let loc = floc loc in
ExBae loc (self x1) (vala_map (List.map self) x2)
| ExChr loc x1 →
let loc = floc loc in
ExChr loc x1
| ExCoe loc x1 x2 x3 →
let loc = floc loc in
ExCoe loc (self x1) (option_map (reloc_ctyp floc sh) x2) (reloc_ctyp floc sh x3)
| ExFlo loc x1 →
let loc = floc loc in
ExFlo loc x1
| ExFor loc x1 x2 x3 x4 x5 →
let loc = floc loc in
ExFor loc x1 (self x2) (self x3) x4 (vala_map (List.map self) x5)
| ExFun loc x1 →
let loc = floc loc in
ExFun loc
(vala_map
(List.map
(fun (x1, x2, x3) →
(reloc_patt floc sh x1, vala_map (option_map self) x2, self x3)))
x1)
| ExIfe loc x1 x2 x3 →
let loc = floc loc in
ExIfe loc (self x1) (self x2) (self x3)
| ExInt loc x1 x2 →
let loc = floc loc in
ExInt loc x1 x2
| ExLab loc x1 →
let loc = floc loc in
ExLab loc
(vala_map
(List.map
(fun (x1, x2) →
(reloc_patt floc sh x1, vala_map (option_map self) x2)))
x1)
| ExLaz loc x1 →
let loc = floc loc in
ExLaz loc (self x1)
| ExLet loc x1 x2 x3 →
let loc = floc loc in
ExLet loc x1
(vala_map (List.map (fun (x1, x2) → (reloc_patt floc sh x1, self x2))) x2)
(self x3)
| ExLid loc x1 →
let loc = floc loc in
ExLid loc x1
| ExLmd loc x1 x2 x3 →
let loc = floc loc in
ExLmd loc x1 (reloc_module_expr floc sh x2) (self x3)
| ExMat loc x1 x2 →
let loc = floc loc in
ExMat loc (self x1)
(vala_map
(List.map
(fun (x1, x2, x3) →
(reloc_patt floc sh x1, vala_map (option_map self) x2, self x3)))
x2)
| ExNew loc x1 →
let loc = floc loc in
ExNew loc x1
| ExObj loc x1 x2 →
let loc = floc loc in
ExObj loc (vala_map (option_map (reloc_patt floc sh)) x1)
(vala_map (List.map (reloc_class_str_item floc sh)) x2)
| ExOlb loc x1 x2 →
let loc = floc loc in
ExOlb loc (reloc_patt floc sh x1) (vala_map (option_map self) x2)
| ExOvr loc x1 →
let loc = floc loc in
ExOvr loc (vala_map (List.map (fun (x1, x2) → (x1, self x2))) x1)
| ExPck loc x1 x2 →
let loc = floc loc in
ExPck loc (reloc_module_expr floc sh x1)
(option_map (reloc_module_type floc sh) x2)
| ExRec loc x1 x2 →
let loc = floc loc in
ExRec loc
(vala_map (List.map (fun (x1, x2) → (reloc_patt floc sh x1, self x2))) x1)
(option_map self x2)
| ExSeq loc x1 →
let loc = floc loc in
ExSeq loc (vala_map (List.map self) x1)
| ExSnd loc x1 x2 →
let loc = floc loc in
ExSnd loc (self x1) x2
| ExSte loc x1 x2 →
let loc = floc loc in
ExSte loc (self x1) (self x2)
| ExStr loc x1 →
let loc = floc loc in
ExStr loc x1
| ExTry loc x1 x2 →
let loc = floc loc in
ExTry loc (self x1)
(vala_map
(List.map
(fun (x1, x2, x3) →
(reloc_patt floc sh x1, vala_map (option_map self) x2, self x3)))
x2)
| ExTup loc x1 →
let loc = floc loc in
ExTup loc (vala_map (List.map self) x1)
| ExTyc loc x1 x2 →
let loc = floc loc in
ExTyc loc (self x1) (reloc_ctyp floc sh x2)
| ExUid loc x1 →
let loc = floc loc in
ExUid loc x1
| ExVrn loc x1 →
let loc = floc loc in
ExVrn loc x1
| ExWhi loc x1 x2 →
let loc = floc loc in
ExWhi loc (self x1) (vala_map (List.map self) x2)
| ExXtr loc x1 x2 →
let loc = floc loc in
ExXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_module_type floc sh =
self where rec self =
fun
[ MtAcc loc x1 x2 →
let loc = floc loc in
MtAcc loc (self x1) (self x2)
| MtApp loc x1 x2 →
let loc = floc loc in
MtApp loc (self x1) (self x2)
| MtFun loc x1 x2 x3 →
let loc = floc loc in
MtFun loc x1 (self x2) (self x3)
| MtLid loc x1 →
let loc = floc loc in
MtLid loc x1
| MtQuo loc x1 →
let loc = floc loc in
MtQuo loc x1
| MtSig loc x1 →
let loc = floc loc in
MtSig loc (vala_map (List.map (reloc_sig_item floc sh)) x1)
| MtTyo loc x1 →
let loc = floc loc in
MtTyo loc (reloc_module_expr floc sh x1)
| MtUid loc x1 →
let loc = floc loc in
MtUid loc x1
| MtWit loc x1 x2 →
let loc = floc loc in
MtWit loc (self x1) (vala_map (List.map (reloc_with_constr floc sh)) x2)
| MtXtr loc x1 x2 →
let loc = floc loc in
MtXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_sig_item floc sh =
self where rec self =
fun
[ SgCls loc x1 →
let loc = floc loc in
SgCls loc
(vala_map (List.map (class_infos_map floc (reloc_class_type floc sh))) x1)
| SgClt loc x1 →
let loc = floc loc in
SgClt loc
(vala_map (List.map (class_infos_map floc (reloc_class_type floc sh))) x1)
| SgDcl loc x1 →
let loc = floc loc in
SgDcl loc (vala_map (List.map self) x1)
| SgDir loc x1 x2 →
let loc = floc loc in
SgDir loc x1 (vala_map (option_map (reloc_expr floc sh)) x2)
| SgExc loc x1 x2 →
let loc = floc loc in
SgExc loc x1 (vala_map (List.map (reloc_ctyp floc sh)) x2)
| SgExt loc x1 x2 x3 →
let loc = floc loc in
SgExt loc x1 (reloc_ctyp floc sh x2) x3
| SgInc loc x1 →
let loc = floc loc in
SgInc loc (reloc_module_type floc sh x1)
| SgMod loc x1 x2 →
let loc = floc loc in
SgMod loc x1
(vala_map (List.map (fun (x1, x2) → (x1, reloc_module_type floc sh x2)))
x2)
| SgMty loc x1 x2 →
let loc = floc loc in
SgMty loc x1 (reloc_module_type floc sh x2)
| SgOpn loc x1 →
let loc = floc loc in
SgOpn loc x1
| SgTyp loc x1 →
let loc = floc loc in
SgTyp loc (vala_map (List.map (reloc_type_decl floc sh)) x1)
| SgUse loc x1 x2 →
let loc = floc loc in
SgUse loc x1
(vala_map (List.map (fun (x1, loc) → (self x1, floc loc))) x2)
| SgVal loc x1 x2 →
let loc = floc loc in
SgVal loc x1 (reloc_ctyp floc sh x2)
| SgXtr loc x1 x2 →
let loc = floc loc in
SgXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_with_constr floc sh =
fun
[ WcMod loc x1 x2 →
let loc = floc loc in
WcMod loc x1 (reloc_module_expr floc sh x2)
| WcMos loc x1 x2 →
let loc = floc loc in
WcMos loc x1 (reloc_module_expr floc sh x2)
| WcTyp loc x1 x2 x3 x4 →
let loc = floc loc in
WcTyp loc x1 x2 x3 (reloc_ctyp floc sh x4)
| WcTys loc x1 x2 x3 →
let loc = floc loc in
WcTys loc x1 x2 (reloc_ctyp floc sh x3) ]
and reloc_module_expr floc sh =
self where rec self =
fun
[ MeAcc loc x1 x2 →
let loc = floc loc in
MeAcc loc (self x1) (self x2)
| MeApp loc x1 x2 →
let loc = floc loc in
MeApp loc (self x1) (self x2)
| MeFun loc x1 x2 x3 →
let loc = floc loc in
MeFun loc x1 (reloc_module_type floc sh x2) (self x3)
| MeStr loc x1 →
let loc = floc loc in
MeStr loc (vala_map (List.map (reloc_str_item floc sh)) x1)
| MeTyc loc x1 x2 →
let loc = floc loc in
MeTyc loc (self x1) (reloc_module_type floc sh x2)
| MeUid loc x1 →
let loc = floc loc in
MeUid loc x1
| MeUnp loc x1 x2 →
let loc = floc loc in
MeUnp loc (reloc_expr floc sh x1) (option_map (reloc_module_type floc sh) x2)
| MeXtr loc x1 x2 →
let loc = floc loc in
MeXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_str_item floc sh =
self where rec self =
fun
[ StCls loc x1 →
let loc = floc loc in
StCls loc
(vala_map (List.map (class_infos_map floc (reloc_class_expr floc sh))) x1)
| StClt loc x1 →
let loc = floc loc in
StClt loc
(vala_map (List.map (class_infos_map floc (reloc_class_type floc sh))) x1)
| StDcl loc x1 →
let loc = floc loc in
StDcl loc (vala_map (List.map self) x1)
| StDir loc x1 x2 →
let loc = floc loc in
StDir loc x1 (vala_map (option_map (reloc_expr floc sh)) x2)
| StExc loc x1 x2 x3 →
let loc = floc loc in
StExc loc x1 (vala_map (List.map (reloc_ctyp floc sh)) x2) x3
| StExp loc x1 →
let loc = floc loc in
StExp loc (reloc_expr floc sh x1)
| StExt loc x1 x2 x3 →
let loc = floc loc in
StExt loc x1 (reloc_ctyp floc sh x2) x3
| StInc loc x1 →
let loc = floc loc in
StInc loc (reloc_module_expr floc sh x1)
| StMod loc x1 x2 →
let loc = floc loc in
StMod loc x1
(vala_map (List.map (fun (x1, x2) → (x1, reloc_module_expr floc sh x2)))
x2)
| StMty loc x1 x2 →
let loc = floc loc in
StMty loc x1 (reloc_module_type floc sh x2)
| StOpn loc x1 →
let loc = floc loc in
StOpn loc x1
| StTyp loc x1 →
let loc = floc loc in
StTyp loc (vala_map (List.map (reloc_type_decl floc sh)) x1)
| StUse loc x1 x2 →
let loc = floc loc in
StUse loc x1
(vala_map (List.map (fun (x1, loc) → (self x1, floc loc))) x2)
| StVal loc x1 x2 →
let loc = floc loc in
StVal loc x1
(vala_map
(List.map (fun (x1, x2) → (reloc_patt floc sh x1, reloc_expr floc sh x2)))
x2)
| StXtr loc x1 x2 →
let loc = floc loc in
StXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_type_decl floc sh x =
{tdNam = vala_map (fun (loc, x1) → (floc loc, x1)) x.tdNam; tdPrm = x.tdPrm;
tdPrv = x.tdPrv; tdDef = reloc_ctyp floc sh x.tdDef;
tdCon =
vala_map (List.map (fun (x1, x2) → (reloc_ctyp floc sh x1, reloc_ctyp floc sh x2)))
x.tdCon}
and reloc_class_type floc sh =
self where rec self =
fun
[ CtAcc loc x1 x2 →
let loc = floc loc in
CtAcc loc (self x1) (self x2)
| CtApp loc x1 x2 →
let loc = floc loc in
CtApp loc (self x1) (self x2)
| CtCon loc x1 x2 →
let loc = floc loc in
CtCon loc (self x1) (vala_map (List.map (reloc_ctyp floc sh)) x2)
| CtFun loc x1 x2 →
let loc = floc loc in
CtFun loc (reloc_ctyp floc sh x1) (self x2)
| CtIde loc x1 →
let loc = floc loc in
CtIde loc x1
| CtSig loc x1 x2 →
let loc = floc loc in
CtSig loc (vala_map (option_map (reloc_ctyp floc sh)) x1)
(vala_map (List.map (reloc_class_sig_item floc sh)) x2)
| CtXtr loc x1 x2 →
let loc = floc loc in
CtXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_class_sig_item floc sh =
self where rec self =
fun
[ CgCtr loc x1 x2 →
let loc = floc loc in
CgCtr loc (reloc_ctyp floc sh x1) (reloc_ctyp floc sh x2)
| CgDcl loc x1 →
let loc = floc loc in
CgDcl loc (vala_map (List.map self) x1)
| CgInh loc x1 →
let loc = floc loc in
CgInh loc (reloc_class_type floc sh x1)
| CgMth loc x1 x2 x3 →
let loc = floc loc in
CgMth loc x1 x2 (reloc_ctyp floc sh x3)
| CgVal loc x1 x2 x3 →
let loc = floc loc in
CgVal loc x1 x2 (reloc_ctyp floc sh x3)
| CgVir loc x1 x2 x3 →
let loc = floc loc in
CgVir loc x1 x2 (reloc_ctyp floc sh x3) ]
and reloc_class_expr floc sh =
self where rec self =
fun
[ CeApp loc x1 x2 →
let loc = floc loc in
CeApp loc (self x1) (reloc_expr floc sh x2)
| CeCon loc x1 x2 →
let loc = floc loc in
CeCon loc x1 (vala_map (List.map (reloc_ctyp floc sh)) x2)
| CeFun loc x1 x2 →
let loc = floc loc in
CeFun loc (reloc_patt floc sh x1) (self x2)
| CeLet loc x1 x2 x3 →
let loc = floc loc in
CeLet loc x1
(vala_map
(List.map (fun (x1, x2) → (reloc_patt floc sh x1, reloc_expr floc sh x2)))
x2)
(self x3)
| CeStr loc x1 x2 →
let loc = floc loc in
CeStr loc (vala_map (option_map (reloc_patt floc sh)) x1)
(vala_map (List.map (reloc_class_str_item floc sh)) x2)
| CeTyc loc x1 x2 →
let loc = floc loc in
CeTyc loc (self x1) (reloc_class_type floc sh x2)
| CeXtr loc x1 x2 →
let loc = floc loc in
CeXtr loc x1 (option_map (vala_map self) x2) ]
and reloc_class_str_item floc sh =
self where rec self =
fun
[ CrCtr loc x1 x2 →
let loc = floc loc in
CrCtr loc (reloc_ctyp floc sh x1) (reloc_ctyp floc sh x2)
| CrDcl loc x1 →
let loc = floc loc in
CrDcl loc (vala_map (List.map self) x1)
| CrInh loc x1 x2 →
let loc = floc loc in
CrInh loc (reloc_class_expr floc sh x1) x2
| CrIni loc x1 →
let loc = floc loc in
CrIni loc (reloc_expr floc sh x1)
| CrMth loc x1 x2 x3 x4 x5 →
let loc = floc loc in
CrMth loc x1 x2 x3 (vala_map (option_map (reloc_ctyp floc sh)) x4)
(reloc_expr floc sh x5)
| CrVal loc x1 x2 x3 x4 →
let loc = floc loc in
CrVal loc x1 x2 x3 (reloc_expr floc sh x4)
| CrVav loc x1 x2 x3 →
let loc = floc loc in
CrVav loc x1 x2 (reloc_ctyp floc sh x3)
| CrVir loc x1 x2 x3 →
let loc = floc loc in
CrVir loc x1 x2 (reloc_ctyp floc sh x3) ]
;
(* Equality over syntax trees *)
value eq_expr x y =
reloc_expr (fun _ -> Ploc.dummy) 0 x =
reloc_expr (fun _ -> Ploc.dummy) 0 y
;
value eq_patt x y =
reloc_patt (fun _ -> Ploc.dummy) 0 x =
reloc_patt (fun _ -> Ploc.dummy) 0 y
;
value eq_ctyp x y =
reloc_ctyp (fun _ -> Ploc.dummy) 0 x =
reloc_ctyp (fun _ -> Ploc.dummy) 0 y
;
value eq_str_item x y =
reloc_str_item (fun _ -> Ploc.dummy) 0 x =
reloc_str_item (fun _ -> Ploc.dummy) 0 y
;
value eq_sig_item x y =
reloc_sig_item (fun _ -> Ploc.dummy) 0 x =
reloc_sig_item (fun _ -> Ploc.dummy) 0 y
;
value eq_module_expr x y =
reloc_module_expr (fun _ -> Ploc.dummy) 0 x =
reloc_module_expr (fun _ -> Ploc.dummy) 0 y
;
value eq_module_type x y =
reloc_module_type (fun _ -> Ploc.dummy) 0 x =
reloc_module_type (fun _ -> Ploc.dummy) 0 y
;
value eq_class_sig_item x y =
reloc_class_sig_item (fun _ -> Ploc.dummy) 0 x =
reloc_class_sig_item (fun _ -> Ploc.dummy) 0 y
;
value eq_class_str_item x y =
reloc_class_str_item (fun _ -> Ploc.dummy) 0 x =
reloc_class_str_item (fun _ -> Ploc.dummy) 0 y
;
value eq_reloc_class_type x y =
reloc_class_type (fun _ -> Ploc.dummy) 0 x =
reloc_class_type (fun _ -> Ploc.dummy) 0 y
;
value eq_class_expr x y =
reloc_class_expr (fun _ -> Ploc.dummy) 0 x =
reloc_class_expr (fun _ -> Ploc.dummy) 0 y
;
(* ------------------------------------------------------------------------- *)
(* Now the lexer. *)
(* ------------------------------------------------------------------------- *)
(* camlp5r *)
(* $Id: plexer.ml,v 6.11 2010-10-04 20:14:58 deraugla Exp $ *)
(* Copyright (c) INRIA 2007-2010 *)
#load "pa_lexer.cmo";
(* ------------------------------------------------------------------------- *)
(* Added by JRH as a backdoor to change lexical conventions. *)
(* ------------------------------------------------------------------------- *)
value jrh_lexer = ref False;
open Versdep;
value no_quotations = ref False;
value error_on_unknown_keywords = ref False;
value dollar_for_antiquotation = ref True;
value specific_space_dot = ref False;
value force_antiquot_loc = ref False;
type context =
{ after_space : mutable bool;
dollar_for_antiquotation : bool;
specific_space_dot : bool;
find_kwd : string -> string;
line_cnt : int -> char -> unit;
set_line_nb : unit -> unit;
make_lined_loc : (int * int) -> string -> Ploc.t }
;
value err ctx loc msg =
Ploc.raise (ctx.make_lined_loc loc "") (Plexing.Error msg)
;
(* ------------------------------------------------------------------------- *)
(* JRH's hack to make the case distinction "unmixed" versus "mixed" *)
(* ------------------------------------------------------------------------- *)
value is_uppercase s = String.uppercase s = s;
value is_only_lowercase s = String.lowercase s = s && not(is_uppercase s);
value jrh_identifier find_kwd id =
let jflag = jrh_lexer.val in
if id = "set_jrh_lexer" then
(let _ = jrh_lexer.val := True in ("",find_kwd "true"))
else if id = "unset_jrh_lexer" then
(let _ = jrh_lexer.val := False in ("",find_kwd "false"))
else
try ("", find_kwd id) with
[ Not_found ->
if not(jflag) then
if is_uppercase (String.sub id 0 1) then ("UIDENT", id)
else ("LIDENT", id)
else if is_uppercase (String.sub id 0 1) &&
is_only_lowercase (String.sub id 1 (String.length id - 1))
(***** JRH: Carl's alternative version
then ("UIDENT", id)
else if is_uppercase (String.sub id 0 1) then ("LIDENT", "__uc_"^id)
else ("LIDENT", id)];
*****)
then ("UIDENT", id) else ("LIDENT", id)];
(* ------------------------------------------------------------------------- *)
(* Back to original file with the mod of using the above. *)
(* ------------------------------------------------------------------------- *)
value keyword_or_error ctx loc s =
try ("", ctx.find_kwd s) with
[ Not_found ->
if error_on_unknown_keywords.val then
err ctx loc ("illegal token: " ^ s)
else ("", s) ]
;
value stream_peek_nth n strm =
loop n (Stream.npeek n strm) where rec loop n =
fun
[ [] -> None
| [x] -> if n == 1 then Some x else None
| [_ :: l] -> loop (n - 1) l ]
;
value utf8_lexing = ref False;
value misc_letter buf strm =
if utf8_lexing.val then
match strm with lexer [ '\128'-'\225' | '\227'-'\255' ]
else
match strm with lexer [ '\128'-'\255' ]
;
value misc_punct buf strm =
if utf8_lexing.val then
match strm with lexer [ '\226' _ _ ]
else
match strm with parser []
;
value rec ident =
lexer
[ [ 'A'-'Z' | 'a'-'z' | '0'-'9' | '_' | ''' | misc_letter ] ident! | ]
;
value rec ident2 =
lexer
[ [ '!' | '?' | '~' | '=' | '@' | '^' | '&' | '+' | '-' | '*' | '/' |
'%' | '.' | ':' | '<' | '>' | '|' | '$' | misc_punct ]
ident2!
| ]
;
value rec ident3 =
lexer
[ [ '0'-'9' | 'A'-'Z' | 'a'-'z' | '_' | '!' | '%' | '&' | '*' | '+' | '-' |
'.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' | ''' |
'$' | '\128'-'\255' ] ident3!
| ]
;
value binary = lexer [ '0' | '1' ];
value octal = lexer [ '0'-'7' ];
value decimal = lexer [ '0'-'9' ];
value hexa = lexer [ '0'-'9' | 'a'-'f' | 'A'-'F' ];
value end_integer =
lexer
[ "l"/ -> ("INT_l", $buf)
| "L"/ -> ("INT_L", $buf)
| "n"/ -> ("INT_n", $buf)
| -> ("INT", $buf) ]
;
value rec digits_under kind =
lexer
[ kind (digits_under kind)!
| "_" (digits_under kind)!
| end_integer ]
;
value digits kind =
lexer
[ kind (digits_under kind)!
| -> raise (Stream.Error "ill-formed integer constant") ]
;
value rec decimal_digits_under =
lexer [ [ '0'-'9' | '_' ] decimal_digits_under! | ]
;
value exponent_part =
lexer
[ [ 'e' | 'E' ] [ '+' | '-' | ]
'0'-'9' ? "ill-formed floating-point constant"
decimal_digits_under! ]
;
value number =
lexer
[ decimal_digits_under "." decimal_digits_under! exponent_part ->
("FLOAT", $buf)
| decimal_digits_under "." decimal_digits_under! -> ("FLOAT", $buf)
| decimal_digits_under exponent_part -> ("FLOAT", $buf)
| decimal_digits_under end_integer! ]
;
value char_after_bslash =
lexer
[ "'"/
| _ [ "'"/ | _ [ "'"/ | ] ] ]
;
value char ctx bp =
lexer
[ "\\" _ char_after_bslash!
| "\\" -> err ctx (bp, $pos) "char not terminated"
| ?= [ _ '''] _! "'"/ ]
;
value any ctx buf =
parser bp [: `c :] -> do { ctx.line_cnt bp c; $add c }
;
value rec string ctx bp =
lexer
[ "\""/
| "\\" (any ctx) (string ctx bp)!
| (any ctx) (string ctx bp)!
| -> err ctx (bp, $pos) "string not terminated" ]
;
value rec qstring ctx bp =
lexer
[ "`"/
| (any ctx) (qstring ctx bp)!
| -> err ctx (bp, $pos) "quotation not terminated" ]
;
value comment ctx bp =
comment where rec comment =
lexer
[ "*)"
| "*" comment!
| "(*" comment! comment!
| "(" comment!
| "\"" (string ctx bp)! [ -> $add "\"" ] comment!
| "'*)"
| "'*" comment!
| "'" (any ctx) comment!
| (any ctx) comment!
| -> err ctx (bp, $pos) "comment not terminated" ]
;
value rec quotation ctx bp =
lexer
[ ">>"/
| ">" (quotation ctx bp)!
| "<<" (quotation ctx bp)! [ -> $add ">>" ]! (quotation ctx bp)!
| "<:" ident! "<" (quotation ctx bp)! [ -> $add ">>" ]! (quotation ctx bp)!
| "<:" ident! (quotation ctx bp)!
| "<" (quotation ctx bp)!
| "\\"/ [ '>' | '<' | '\\' ] (quotation ctx bp)!
| "\\" (quotation ctx bp)!
| (any ctx) (quotation ctx bp)!
| -> err ctx (bp, $pos) "quotation not terminated" ]
;
value less_expected = "character '<' expected";
value less ctx bp buf strm =
if no_quotations.val then
match strm with lexer
[ [ -> $add "<" ] ident2! -> keyword_or_error ctx (bp, $pos) $buf ]
else
match strm with lexer
[ "<"/ (quotation ctx bp) -> ("QUOTATION", ":" ^ $buf)
| ":"/ ident! "<"/ ? less_expected [ -> $add ":" ]! (quotation ctx bp) ->
("QUOTATION", $buf)
| ":"/ ident! ":<"/ ? less_expected [ -> $add "@" ]! (quotation ctx bp) ->
("QUOTATION", $buf)
| [ -> $add "<" ] ident2! -> keyword_or_error ctx (bp, $pos) $buf ]
;
value rec antiquot_rest ctx bp =
lexer
[ "$"/
| "\\"/ (any ctx) (antiquot_rest ctx bp)!
| (any ctx) (antiquot_rest ctx bp)!
| -> err ctx (bp, $pos) "antiquotation not terminated" ]
;
value rec antiquot ctx bp =
lexer
[ "$"/ -> ":" ^ $buf
| [ 'a'-'z' | 'A'-'Z' | '0'-'9' | '!' | '_' ] (antiquot ctx bp)!
| ":" (antiquot_rest ctx bp)! -> $buf
| "\\"/ (any ctx) (antiquot_rest ctx bp)! -> ":" ^ $buf
| (any ctx) (antiquot_rest ctx bp)! -> ":" ^ $buf
| -> err ctx (bp, $pos) "antiquotation not terminated" ]
;
value antiloc bp ep s = Printf.sprintf "%d,%d:%s" bp ep s;
value rec antiquot_loc ctx bp =
lexer
[ "$"/ -> antiloc bp $pos (":" ^ $buf)
| [ 'a'-'z' | 'A'-'Z' | '0'-'9' | '!' | '_' ] (antiquot_loc ctx bp)!
| ":" (antiquot_rest ctx bp)! -> antiloc bp $pos $buf
| "\\"/ (any ctx) (antiquot_rest ctx bp)! -> antiloc bp $pos (":" ^ $buf)
| (any ctx) (antiquot_rest ctx bp)! -> antiloc bp $pos (":" ^ $buf)