-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
AstTransformer.fs
1914 lines (1828 loc) · 77.7 KB
/
AstTransformer.fs
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
module Fantomas.AstTransformer
open FSharp.Compiler.Range
open FSharp.Compiler.SyntaxTree
open Fantomas.TriviaTypes
let rec (|Sequentials|_|) =
function
| SynExpr.Sequential (_, isTrueSeq, e, Sequentials es, range) -> Some((isTrueSeq, e, None, range) :: es)
| SynExpr.Sequential (_, isTrueSeq, e1, e2, range) -> Some [ isTrueSeq, e1, Some e2, range ]
| _ -> None
type Id = { Ident: string; Range: range option }
type FsAstNode = obj
type Node =
{ Type: FsAstType
Range: range option
Properties: Map<string, obj>
Childs: Node list
FsAstNode: FsAstNode }
module Helpers =
let r (r: range) : range option = Some r
let p = Map.ofList
let inline (==>) a b = (a, box b)
let noRange = None
let i (id: Ident) : Id =
{ Ident = id.idText
Range = r id.idRange }
let li (id: LongIdent) = id |> List.map i
let lid (id: LongIdentWithDots) = li id.Lid
module private Ast =
open Helpers
let rec visit (ast: SynModuleOrNamespace) : Node = visitSynModuleOrNamespace ast
and visitSynModuleOrNamespace (modOrNs: SynModuleOrNamespace) : Node =
match modOrNs with
| SynModuleOrNamespace (longIdent, isRecursive, synModuleOrNamespaceKind, decls, _, attrs, access, range) ->
let collectIdents (idents: LongIdent) =
idents
|> List.map
(fun ident ->
{ Type = Ident_
Range = r ident.idRange
Properties = Map.empty
FsAstNode = ident
Childs = [] })
let typeName =
match synModuleOrNamespaceKind with
| SynModuleOrNamespaceKind.AnonModule -> SynModuleOrNamespace_AnonModule
| SynModuleOrNamespaceKind.NamedModule -> SynModuleOrNamespace_NamedModule
| SynModuleOrNamespaceKind.DeclaredNamespace -> SynModuleOrNamespace_DeclaredNamespace
| SynModuleOrNamespaceKind.GlobalNamespace -> SynModuleOrNamespace_GlobalNamespace
{ Type = typeName
Range = r range
Properties =
p [ yield "isRecursive" ==> isRecursive
yield
"synModuleOrNamespaceKind"
==> synModuleOrNamespaceKind
yield "longIdent" ==> li longIdent
if access.IsSome then
yield "access" ==> (access.Value |> visitSynAccess) ]
FsAstNode = modOrNs
Childs =
[ yield!
if synModuleOrNamespaceKind = SynModuleOrNamespaceKind.DeclaredNamespace then
collectIdents longIdent
else
[]
yield! (visitSynAttributeLists range attrs)
yield! (decls |> List.map visitSynModuleDecl) ] }
and visitSynModuleDecl (ast: SynModuleDecl) : Node =
match ast with
| SynModuleDecl.ModuleAbbrev (ident, longIdent, range) ->
{ Type = SynModuleDecl_ModuleAbbrev
Range = r range
Properties =
p [ "ident" ==> i ident
"longIdent" ==> li longIdent ]
FsAstNode = ast
Childs = [] }
| SynModuleDecl.NestedModule (sci, isRecursive, decls, _, range) ->
{ Type = SynModuleDecl_NestedModule
Range = r range
Properties = p [ "isRecursive" ==> isRecursive ]
FsAstNode = ast
Childs =
[ yield visitSynComponentInfo sci
yield! (decls |> List.map visitSynModuleDecl) ] }
| SynModuleDecl.Let (_, bindings, range) ->
{ Type = SynModuleDecl_Let
Range = r range
Properties = p []
FsAstNode = ast
Childs = bindings |> List.map visitSynBinding }
| SynModuleDecl.DoExpr (_, expr, range) ->
{ Type = SynModuleDecl_DoExpr
Range = r range
Properties = p []
FsAstNode = ast
Childs = [ visitSynExpr expr ] }
| SynModuleDecl.Types (typeDefs, range) ->
{ Type = SynModuleDecl_Types
Range = r range
Properties = p []
FsAstNode = ast
Childs = typeDefs |> List.map visitSynTypeDefn }
| SynModuleDecl.Exception (exceptionDef, range) ->
{ Type = SynModuleDecl_Exception
Range = r range
Properties = p []
FsAstNode = ast
Childs = [ visitSynExceptionDefn exceptionDef ] }
| SynModuleDecl.Open (target, parentRange) ->
// we use the parent ranges here to match up with the trivia parsed
match target with
| SynOpenDeclTarget.ModuleOrNamespace (longIdent, _range) ->
{ Type = SynModuleDecl_Open
Range = r parentRange
Properties = p [ "longIdent" ==> li longIdent ]
FsAstNode = ast
Childs = [] }
| SynOpenDeclTarget.Type (synType, _range) ->
{ Type = SynModuleDecl_OpenType
Range = r parentRange
Properties = p []
FsAstNode = ast
Childs = [ visitSynType synType ] }
| SynModuleDecl.Attributes (attrs, range) ->
{ Type = SynModuleDecl_Attributes
Range = r range
Properties = p []
FsAstNode = ast
Childs = visitSynAttributeLists range attrs }
| SynModuleDecl.HashDirective (hash, range) ->
{ Type = SynModuleDecl_HashDirective
Range = r range
Properties = p []
FsAstNode = ast
Childs = [ visitParsedHashDirective hash ] }
| SynModuleDecl.NamespaceFragment (moduleOrNamespace) ->
{ Type = SynModuleDecl_NamespaceFragment
Range = noRange
Properties = p []
FsAstNode = ast
Childs = [ visitSynModuleOrNamespace moduleOrNamespace ] }
and visitSynExpr (synExpr: SynExpr) : Node =
match synExpr with
| SynExpr.Paren (expr, leftParenRange, rightParenRange, range) ->
{ Type = SynExpr_Paren
Range = r range
Properties =
p [ yield "leftParenRange" ==> r leftParenRange
if rightParenRange.IsSome then
yield "rightParenRange" ==> r rightParenRange.Value ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.Quote (operator, isRaw, quotedSynExpr, isFromQueryExpression, range) ->
{ Type = SynExpr_Quote
Range = r range
Properties =
p [ "isRaw" ==> isRaw
"isFromQueryExpression" ==> isFromQueryExpression ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr operator
yield visitSynExpr quotedSynExpr ] }
| SynExpr.Const (constant, range) ->
{ Type = SynExpr_Const
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ visitSynConst range constant ] }
| SynExpr.Typed (expr, typeName, range) ->
{ Type = SynExpr_Typed
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynType typeName ] }
| SynExpr.Tuple (isStruct, exprs, commaRanges, range) ->
{ Type = SynExpr_Tuple
Range = r range
Properties =
p [ "isStruct" ==> isStruct
"commaRanges" ==> (commaRanges |> List.map r) ]
FsAstNode = synExpr
Childs = [ yield! exprs |> List.map visitSynExpr ] }
| SynExpr.ArrayOrList (isList, exprs, range) ->
{ Type = SynExpr_ArrayOrList
Range = r range
Properties = p [ "isList" ==> isList ]
FsAstNode = synExpr
Childs = [ yield! exprs |> List.map visitSynExpr ] }
| SynExpr.Record (_, _, recordFields, range) ->
{ Type = SynExpr_Record
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield! recordFields |> List.map visitRecordField ] }
| SynExpr.AnonRecd (_, _, recordFields, range) ->
{ Type = SynExpr_AnonRecd
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield! recordFields |> List.map visitAnonRecordField ] }
| SynExpr.New (isProtected, typeName, expr, range) ->
{ Type = SynExpr_New
Range = r range
Properties = p [ "isProtected" ==> isProtected ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynType typeName ] }
| SynExpr.ObjExpr (objType, argOptions, bindings, extraImpls, newExprRange, range) ->
{ Type = SynExpr_ObjExpr
Range = r range
Properties = p [ "newExprRange" ==> r newExprRange ]
FsAstNode = synExpr
Childs =
[ yield visitSynType objType
if argOptions.IsSome then
yield visitArgsOption argOptions.Value
yield! extraImpls |> List.map visitSynInterfaceImpl
yield! bindings |> List.map visitSynBinding ] }
| SynExpr.While (_, whileExpr, doExpr, range) ->
{ Type = SynExpr_While
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr whileExpr
yield visitSynExpr doExpr ] }
| SynExpr.For (_, ident, identBody, _, toBody, doBody, range) ->
{ Type = SynExpr_For
Range = r range
Properties = p [ "ident" ==> i ident ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr identBody
yield visitSynExpr toBody
yield visitSynExpr doBody ] }
| SynExpr.ForEach (_, (SeqExprOnly seqExprOnly), isFromSource, pat, enumExpr, bodyExpr, range) ->
{ Type = SynExpr_ForEach
Range = r range
Properties =
p [ "isFromSource" ==> isFromSource
"seqExprOnly" ==> seqExprOnly ]
FsAstNode = synExpr
Childs =
[ yield visitSynPat pat
yield visitSynExpr enumExpr
yield visitSynExpr bodyExpr ] }
| SynExpr.ArrayOrListOfSeqExpr (isArray, expr, range) ->
{ Type = SynExpr_ArrayOrListOfSeqExpr
Range = r range
Properties = p [ "isArray" ==> isArray ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.CompExpr (isArrayOrList, isNotNakedRefCell, expr, range) ->
{ Type = SynExpr_CompExpr
Range = r range
Properties =
p [ "isArrayOrList" ==> isArrayOrList
"isNotNakedRefCell" ==> isNotNakedRefCell ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.Lambda (fromMethod, inLambdaSeq, args, body, _parsedData, range) ->
{ Type = SynExpr_Lambda
Range = r range
Properties =
p [ "fromMethod" ==> fromMethod
"inLambdaSeq" ==> inLambdaSeq ]
FsAstNode = synExpr
Childs =
[ yield visitSynSimplePats args
yield visitSynExpr body ] }
| SynExpr.MatchLambda (isExnMatch, _, matchClauses, _, range) ->
{ Type = SynExpr_MatchLambda
Range = r range
Properties = p [ "isExnMatch" ==> isExnMatch ]
FsAstNode = synExpr
Childs = [ yield! matchClauses |> List.map visitSynMatchClause ] }
| SynExpr.Match (_, expr, clauses, range) ->
{ Type = SynExpr_Match
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield! clauses |> List.map visitSynMatchClause ] }
| SynExpr.Do (expr, range) ->
{ Type = SynExpr_Do
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.Assert (expr, range) ->
{ Type = SynExpr_Assert
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.App (atomicFlag, isInfix, funcExpr, argExpr, range) ->
{ Type = SynExpr_App
Range = r range
Properties =
p [ "atomicFlag"
==> (match atomicFlag with
| ExprAtomicFlag.Atomic -> "Atomic"
| _ -> "Not Atomic")
"isInfix" ==> isInfix ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr funcExpr
yield visitSynExpr argExpr ] }
| SynExpr.TypeApp (expr, lESSrange, typeNames, commaRanges, gREATERrange, typeArgsRange, range) ->
{ Type = SynExpr_TypeApp
Range = r range
Properties =
p [ yield "lESSrange" ==> r lESSrange
yield "commaRanges" ==> (commaRanges |> List.map r)
if gREATERrange.IsSome then
yield "gREATERrange" ==> r gREATERrange.Value
yield "typeArgsRange" ==> r typeArgsRange ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield! typeNames |> List.map visitSynType ] }
| SynExpr.LetOrUse (isRecursive, isUse, bindings, body, range) ->
{ Type = SynExpr_LetOrUse
Range = r range
Properties =
p [ "isRecursive" ==> isRecursive
"isUse" ==> isUse ]
FsAstNode = synExpr
Childs =
[ yield! bindings |> List.map visitSynBinding
yield visitSynExpr body ] }
| SynExpr.TryWith (tryExpr, tryRange, withCases, withRange, range, _, _) ->
{ Type = SynExpr_TryWith
Range = r range
Properties =
p [ "tryRange" ==> r tryRange
"withRange" ==> r withRange ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr tryExpr
yield! withCases |> List.map visitSynMatchClause ] }
| SynExpr.TryFinally (tryExpr, finallyExpr, range, _, _) ->
{ Type = SynExpr_TryFinally
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr tryExpr
yield visitSynExpr finallyExpr ] }
| SynExpr.Lazy (ex, range) ->
{ Type = SynExpr_Lazy
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr ex ] }
| Sequentials xs ->
let rec cons xs =
match xs with
| [] -> failwith "should not happen" // expr2Opt is always Some in last item
| ((isTrueSeq, expr1, expr2Opt, range) :: rest) ->
{ Type = SynExpr_Sequential
Range = r range
Properties = p [ "isTrueSeq" ==> isTrueSeq ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr1
yield
expr2Opt
|> Option.map visitSynExpr
|> Option.defaultWith (fun () -> cons rest) ] }
cons xs
| SynExpr.Sequential (_, isTrueSeq, expr1, expr2, range) ->
{ Type = SynExpr_Sequential
Range = r range
Properties = p [ "isTrueSeq" ==> isTrueSeq ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr1
yield visitSynExpr expr2 ] }
| SynExpr.SequentialOrImplicitYield (seqPoint, expr1, expr2, ifNotStmt, range) ->
{ Type = SynExpr_SequentialOrImplicitYield
Range = r range
FsAstNode = synExpr
Properties = p [ "seqPoint" ==> seqPoint ]
Childs =
[ yield visitSynExpr expr1
yield visitSynExpr expr2
yield visitSynExpr ifNotStmt ] }
| SynExpr.IfThenElse (ifExpr, thenExpr, elseExpr, _, isFromErrorRecovery, ifToThenRange, range) ->
{ Type = SynExpr_IfThenElse
Range = r range
Properties =
p [ "isFromErrorRecovery" ==> isFromErrorRecovery
"ifToThenRange" ==> r ifToThenRange ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr ifExpr
yield visitSynExpr thenExpr
if elseExpr.IsSome then
yield visitSynExpr elseExpr.Value ] }
| SynExpr.Ident (id) ->
{ Type = SynExpr_Ident
Range = (i id).Range
Properties = p [ "ident" ==> i id ]
FsAstNode = synExpr
Childs = [] }
| SynExpr.LongIdent (isOptional, longDotId, _, range) ->
let ids = visitLongIdentWithDots longDotId
{ Type = SynExpr_LongIdent
Range = r range
Properties =
p [ "isOptional" ==> isOptional
"longDotId" ==> lid longDotId ]
FsAstNode = synExpr
Childs = ids }
| SynExpr.LongIdentSet (longDotId, expr, range) ->
{ Type = SynExpr_LongIdentSet
Range = r range
Properties = p [ "longDotId" ==> lid longDotId ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.DotGet (expr, rangeOfDot, longDotId, range) ->
// Idents are collected as childs here to deal with unit test ``Fluent api with comments should remain on same lines``
let ids = visitLongIdentWithDots longDotId
{ Type = SynExpr_DotGet
Range = r range
Properties =
p [ "rangeOfDot" ==> r rangeOfDot
"longDotId" ==> lid longDotId ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr; yield! ids ] }
| SynExpr.DotSet (expr, longDotId, e2, range) ->
{ Type = SynExpr_DotSet
Range = r range
Properties = p [ "longDotId" ==> lid longDotId ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynExpr e2 ] }
| SynExpr.Set (e1, e2, range) ->
{ Type = SynExpr_Set
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr e1
yield visitSynExpr e2 ] }
| SynExpr.DotIndexedGet (objectExpr, indexExprs, dotRange, range) ->
{ Type = SynExpr_DotIndexedGet
Range = r range
Properties = p [ "dotRange" ==> r dotRange ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr objectExpr
yield! indexExprs |> List.map visitSynIndexerArg ] }
| SynExpr.DotIndexedSet (objectExpr, indexExprs, valueExpr, leftOfSetRange, dotRange, range) ->
{ Type = SynExpr_DotIndexedSet
Range = r range
Properties =
p [ "leftOfSetRange" ==> r leftOfSetRange
"dotRange" ==> r dotRange ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr objectExpr
yield! indexExprs |> List.map visitSynIndexerArg
yield visitSynExpr valueExpr ] }
| SynExpr.NamedIndexedPropertySet (longDotId, e1, e2, range) ->
{ Type = SynExpr_NamedIndexedPropertySet
Range = r range
Properties = p [ "longDotId" ==> lid longDotId ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr e1
yield visitSynExpr e2 ] }
| SynExpr.DotNamedIndexedPropertySet (expr, longDotId, e1, e2, range) ->
{ Type = SynExpr_DotNamedIndexedPropertySet
Range = r range
Properties = p [ "longDotId" ==> lid longDotId ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynExpr e1
yield visitSynExpr e2 ] }
| SynExpr.TypeTest (expr, typeName, range) ->
{ Type = SynExpr_TypeTest
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynType typeName ] }
| SynExpr.Upcast (expr, typeName, range) ->
{ Type = SynExpr_Upcast
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynType typeName ] }
| SynExpr.Downcast (expr, typeName, range) ->
{ Type = SynExpr_Downcast
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynType typeName ] }
| SynExpr.InferredUpcast (expr, range) ->
{ Type = SynExpr_InferredUpcast
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.InferredDowncast (expr, range) ->
{ Type = SynExpr_InferredDowncast
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.Null (range) ->
{ Type = SynExpr_Null
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [] }
| SynExpr.AddressOf (isByref, expr, refRange, range) ->
{ Type = SynExpr_AddressOf
Range = r range
Properties =
p [ "isByref" ==> isByref
"refRange" ==> r refRange ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.TraitCall (typars, sign, expr, range) ->
{ Type = SynExpr_TraitCall
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield! typars |> List.map visitSynTypar
yield visitSynMemberSig sign
yield visitSynExpr expr ] }
| SynExpr.JoinIn (expr, inrange, expr2, range) ->
{ Type = SynExpr_JoinIn
Range = r range
Properties = p [ "inRange" ==> r inrange ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield visitSynExpr expr2 ] }
| SynExpr.ImplicitZero (range) ->
{ Type = SynExpr_ImplicitZero
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [] }
| SynExpr.YieldOrReturn (_, expr, range) ->
{ Type = SynExpr_YieldOrReturn
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.YieldOrReturnFrom (_, expr, range) ->
{ Type = SynExpr_YieldOrReturnFrom
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.LetOrUseBang (_, isUse, isFromSource, pat, rhsExpr, andBangs, body, range) ->
{ Type = SynExpr_LetOrUseBang
Range = r range
Properties =
p [ "isUse" ==> isUse
"isFromSource" ==> isFromSource ]
FsAstNode = synExpr
Childs =
[ yield visitSynPat pat
yield visitSynExpr rhsExpr
yield!
andBangs
|> List.collect (fun (_, _, _, pat, body, _) -> visitSynPat pat :: [ visitSynExpr body ])
yield visitSynExpr body ] }
| SynExpr.MatchBang (_, expr, clauses, range) ->
{ Type = SynExpr_MatchBang
Range = r range
Properties = p []
FsAstNode = synExpr
Childs =
[ yield visitSynExpr expr
yield! clauses |> List.map visitSynMatchClause ] }
| SynExpr.DoBang (expr, range) ->
{ Type = SynExpr_DoBang
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.LibraryOnlyILAssembly (_, _, _, _, range) ->
{ Type = SynExpr_LibraryOnlyILAssembly
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [] }
| SynExpr.LibraryOnlyStaticOptimization (_, _, _, range) ->
{ Type = SynExpr_LibraryOnlyStaticOptimization
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [] }
| SynExpr.LibraryOnlyUnionCaseFieldGet (expr, longId, _, range) ->
{ Type = SynExpr_LibraryOnlyUnionCaseFieldGet
Range = r range
Properties = p [ "longId" ==> li longId ]
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.LibraryOnlyUnionCaseFieldSet (e1, longId, _, e2, range) ->
{ Type = SynExpr_LibraryOnlyUnionCaseFieldSet
Range = r range
Properties = p [ "longId" ==> li longId ]
FsAstNode = synExpr
Childs =
[ yield visitSynExpr e1
yield visitSynExpr e2 ] }
| SynExpr.ArbitraryAfterError (debugStr, range) ->
{ Type = SynExpr_ArbitraryAfterError
Range = r range
Properties = p [ "debugStr" ==> debugStr ]
FsAstNode = synExpr
Childs = [] }
| SynExpr.FromParseError (expr, range) ->
{ Type = SynExpr_FromParseError
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.DiscardAfterMissingQualificationAfterDot (expr, range) ->
{ Type = SynExpr_DiscardAfterMissingQualificationAfterDot
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.Fixed (expr, range) ->
{ Type = SynExpr_Fixed
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = [ yield visitSynExpr expr ] }
| SynExpr.InterpolatedString (parts, range) ->
{ Type = SynExpr_InterpolatedString
Range = r range
Properties = p []
FsAstNode = synExpr
Childs = List.map visitSynInterpolatedStringPart parts }
and visitSynInterpolatedStringPart (synInterpolatedStringPart: SynInterpolatedStringPart) =
match synInterpolatedStringPart with
| SynInterpolatedStringPart.String (value, range) ->
{ Type = SynInterpolatedStringPart_String
Range = r range
Properties = p [ "value", box value ]
FsAstNode = synInterpolatedStringPart
Childs = [] }
| SynInterpolatedStringPart.FillExpr (expr, ident) ->
{ Type = SynInterpolatedStringPart_FillExpr
Range = None
Properties = p []
FsAstNode = synInterpolatedStringPart
Childs =
[ visitSynExpr expr
yield! (Option.toList ident |> List.map visitIdent) ] }
and visitRecordField ((longId, _) as rfn: RecordFieldName, expr: SynExpr option, _: BlockSeparator option) =
{ Type = RecordField_
Range = r longId.Range
Properties = p [ "ident" ==> lid longId ]
FsAstNode = rfn
Childs =
[ if expr.IsSome then
yield visitSynExpr expr.Value ] }
and visitAnonRecordField (ident: Ident, expr: SynExpr) =
{ Type = AnonRecordField_
Range = noRange
Properties = p [ "ident" ==> i ident ]
FsAstNode = expr
Childs = [ yield visitSynExpr expr ] }
and visitAnonRecordTypeField (ident: Ident, t: SynType) =
{ Type = AnonRecordTypeField_
Range = noRange
Properties = p [ "ident" ==> i ident ]
FsAstNode = t
Childs = [ yield visitSynType t ] }
and visitSynMemberSig (ms: SynMemberSig) : Node =
match ms with
| SynMemberSig.Member (valSig, _, range) ->
{ Type = SynMemberSig_Member
Range = r range
Properties = p []
FsAstNode = ms
Childs = [ yield visitSynValSig valSig ] }
| SynMemberSig.Interface (typeName, range) ->
{ Type = SynMemberSig_Interface
Range = r range
Properties = p []
FsAstNode = ms
Childs = [ yield visitSynType typeName ] }
| SynMemberSig.Inherit (typeName, range) ->
{ Type = SynMemberSig_Inherit
Range = r range
Properties = p []
FsAstNode = ms
Childs = [ yield visitSynType typeName ] }
| SynMemberSig.ValField (f, range) ->
{ Type = SynMemberSig_ValField
Range = r range
Properties = p []
FsAstNode = ms
Childs = [ yield visitSynField f ] }
| SynMemberSig.NestedType (typedef, range) ->
{ Type = SynMemberSig_NestedType
Range = r range
Properties = p []
FsAstNode = ms
Childs = [ yield visitSynTypeDefnSig typedef ] }
and visitSynIndexerArg (ia: SynIndexerArg) : Node =
match ia with
| SynIndexerArg.One (e, _fromEnd, _) ->
{ Type = SynIndexerArg_One
Range = noRange
Properties = p []
FsAstNode = ia
Childs = [ yield visitSynExpr e ] }
| SynIndexerArg.Two (e1, _fromEnd1, e2, _fromEnd2, _, _) ->
{ Type = SynIndexerArg_Two
Range = noRange
Properties = p []
FsAstNode = ia
Childs =
[ yield visitSynExpr e1
yield visitSynExpr e2 ] }
and visitSynMatchClause (mc: SynMatchClause) : Node =
match mc with
| SynMatchClause.Clause (pat, e1, e2, _range, _) ->
{ Type = SynMatchClause_Clause
Range = r mc.Range // _range is the same range as pat, see https://github.com/dotnet/fsharp/issues/10877
Properties = p []
FsAstNode = mc
Childs =
[ yield visitSynPat pat
if e1.IsSome then
yield visitSynExpr e1.Value
yield visitSynExpr e2 ] }
and visitArgsOption (expr: SynExpr, ident: Ident option) =
{ Type = ArgOptions_
Range = noRange
Properties =
p [ if ident.IsSome then
yield "ident" ==> i ident.Value ]
FsAstNode = expr
Childs = [ yield visitSynExpr expr ] }
and visitSynInterfaceImpl (ii: SynInterfaceImpl) : Node =
match ii with
| InterfaceImpl (typ, bindings, range) ->
{ Type = InterfaceImpl_
Range = r range
Properties = p []
FsAstNode = ii
Childs =
[ yield visitSynType typ
yield! (bindings |> List.map visitSynBinding) ] }
and visitSynTypeDefn (td: SynTypeDefn) =
match td with
| TypeDefn (sci, stdr, members, range) ->
{ Type = TypeDefn_
Range = r range
Properties = p []
FsAstNode = td
Childs =
[ yield visitSynComponentInfo sci
yield visitSynTypeDefnRepr stdr
yield! (members |> List.map visitSynMemberDefn) ] }
and visitSynTypeDefnSig (typeDefSig: SynTypeDefnSig) : Node =
match typeDefSig with
| TypeDefnSig (sci, synTypeDefnSigReprs, memberSig, range) ->
{ Type = TypeDefnSig_
Range = r range
Properties = p []
FsAstNode = typeDefSig
Childs =
[ yield visitSynComponentInfo sci
yield visitSynTypeDefnSigRepr synTypeDefnSigReprs
yield! (memberSig |> List.map visitSynMemberSig) ] }
and visitSynTypeDefnSigRepr (stdr: SynTypeDefnSigRepr) : Node =
match stdr with
| SynTypeDefnSigRepr.ObjectModel (kind, members, range) ->
{ Type = SynTypeDefnSigRepr_ObjectModel
Range = r range
Properties = p []
FsAstNode = stdr
Childs =
[ yield visitSynTypeDefnKind kind
yield! (members |> List.map visitSynMemberSig) ] }
| SynTypeDefnSigRepr.Simple (simpleRepr, range) ->
{ Type = SynTypeDefnSigRepr_ObjectModel
Range = r range
Properties = p []
FsAstNode = stdr
Childs = [ yield visitSynTypeDefnSimpleRepr simpleRepr ] }
| SynTypeDefnSigRepr.Exception (exceptionRepr) ->
{ Type = SynTypeDefnSigRepr_Exception
Range = noRange
Properties = p []
FsAstNode = stdr
Childs = [ yield visitSynExceptionDefnRepr exceptionRepr ] }
and visitSynMemberDefn (mbrDef: SynMemberDefn) : Node =
match mbrDef with
| SynMemberDefn.Open (target, parentRange) ->
// we use the parent ranges here to match up with the trivia parsed
match target with
| SynOpenDeclTarget.ModuleOrNamespace (longIdent, _range) ->
{ Type = SynMemberDefn_Open
Range = r parentRange
Properties = p [ "longIdent" ==> li longIdent ]
FsAstNode = target
Childs = [] }
| SynOpenDeclTarget.Type (synType, _range) ->
{ Type = SynMemberDefn_OpenType
Range = r parentRange
Properties = p []
FsAstNode = target
Childs = [ visitSynType synType ] }
| SynMemberDefn.Member (memberDefn, range) ->
{ Type = SynMemberDefn_Member
Range = r range
Properties = p []
FsAstNode = mbrDef
Childs = [ yield visitSynBinding memberDefn ] }
| SynMemberDefn.ImplicitCtor (access, attrs, ctorArgs, selfIdentifier, _xmlDoc, range) ->
{ Type = SynMemberDefn_ImplicitCtor
Range = r range
Properties =
p [ if selfIdentifier.IsSome then
yield "selfIdent" ==> i selfIdentifier.Value
if access.IsSome then
yield "access" ==> (access.Value |> visitSynAccess) ]
FsAstNode = mbrDef
Childs =
[ yield! (visitSynAttributeLists range attrs)
yield visitSynSimplePats ctorArgs ] }
| SynMemberDefn.ImplicitInherit (inheritType, inheritArgs, inheritAlias, range) ->
{ Type = SynMemberDefn_ImplicitInherit
Range = r range
Properties =
p [ if inheritAlias.IsSome then
yield "inheritAlias" ==> i inheritAlias.Value ]
FsAstNode = mbrDef
Childs =
[ yield visitSynType inheritType
yield visitSynExpr inheritArgs ] }
| SynMemberDefn.LetBindings (bindings, isStatic, isRecursive, range) ->
{ Type = SynMemberDefn_LetBindings
Range = r range
Properties =
p [ "isStatic" ==> isStatic
"isRecursive" ==> isRecursive ]
FsAstNode = mbrDef
Childs = [ yield! bindings |> List.map visitSynBinding ] }
| SynMemberDefn.AbstractSlot (valSig, _, range) ->
{ Type = SynMemberDefn_AbstractSlot
Range = r range
Properties = p []
FsAstNode = mbrDef
Childs = [ yield visitSynValSig valSig ] }
| SynMemberDefn.Interface (typ, members, range) ->
{ Type = SynMemberDefn_Interface
Range = r range
Properties = p []
FsAstNode = mbrDef
Childs =
[ yield visitSynType typ
if members.IsSome then
yield! members.Value |> List.map visitSynMemberDefn ] }
| SynMemberDefn.Inherit (typ, ident, range) ->
{ Type = SynMemberDefn_Inherit
Range = r range
Properties =
p [ if ident.IsSome then
yield "ident" ==> i ident.Value ]
FsAstNode = mbrDef
Childs = [ yield visitSynType typ ] }
| SynMemberDefn.ValField (fld, range) ->
{ Type = SynMemberDefn_ValField
Range = r range
Properties = p []
FsAstNode = mbrDef
Childs = [ yield visitSynField fld ] }
| SynMemberDefn.NestedType (typeDefn, access, range) ->
{ Type = SynMemberDefn_NestedType
Range = r range
Properties =
p [ if access.IsSome then
yield "access" ==> (access.Value |> visitSynAccess) ]
FsAstNode = mbrDef
Childs = [ yield visitSynTypeDefn typeDefn ] }
| SynMemberDefn.AutoProperty (attrs,
isStatic,
ident,
typeOpt,
propKind,
_,
_,
access,
synExpr,
getSetRange,
range) ->
{ Type = SynMemberDefn_AutoProperty
Range = r range
Properties =
p [ yield "isStatic" ==> isStatic
yield "ident" ==> i ident
yield "propKind" ==> visitMemberKind propKind
if access.IsSome then
yield "access" ==> (access.Value |> visitSynAccess)
if getSetRange.IsSome then
yield "getSetRange" ==> (getSetRange.Value |> r) ]
FsAstNode = mbrDef
Childs =
[ yield! (visitSynAttributeLists range attrs)
if typeOpt.IsSome then
yield visitSynType typeOpt.Value
yield visitSynExpr synExpr ] }
and visitSynSimplePat (sp: SynSimplePat) : Node =
match sp with
| SynSimplePat.Id (ident, _, isCompilerGenerated, isThisVar, isOptArg, range) ->
{ Type = SynSimplePat_Id
Range = r range
Properties =
p [ "isCompilerGenerated" ==> isCompilerGenerated
"isThisVar" ==> isThisVar
"isOptArg" ==> isOptArg
"ident" ==> i ident ]
FsAstNode = sp
Childs = [] }
| SynSimplePat.Typed (simplePat, typ, range) ->
{ Type = SynSimplePat_Typed
Range = r range
Properties = p []
FsAstNode = sp
Childs =
[ yield visitSynSimplePat simplePat
yield visitSynType typ ] }
| SynSimplePat.Attrib (simplePat, attrs, range) ->
{ Type = SynSimplePat_Attrib
Range = r range
Properties = p []
FsAstNode = sp
Childs =
[ yield visitSynSimplePat simplePat
yield! (visitSynAttributeLists range attrs) ] }
and visitSynSimplePats (sp: SynSimplePats) : Node =
match sp with
| SynSimplePats.SimplePats (pats, range) ->