/
ast.d
4073 lines (3704 loc) · 119 KB
/
ast.d
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
// Written in the D programming language.
/**
* This module defines an Abstract Syntax Tree for the D language
*
* Examples:
* ---
* // TODO
* ---
*
* Copyright: Brian Schott 2013
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt Boost, License 1.0)
* Authors: Brian Schott
*/
module dparse.ast;
import dparse.lexer;
import std.traits;
import std.algorithm;
import std.array;
import std.string;
private immutable uint[TypeInfo] typeMap;
shared static this()
{
typeMap[typeid(AddExpression)] = 1;
typeMap[typeid(AndAndExpression)] = 2;
typeMap[typeid(AndExpression)] = 3;
typeMap[typeid(AsmAddExp)] = 4;
typeMap[typeid(AsmAndExp)] = 5;
typeMap[typeid(AsmBrExp)] = 6;
typeMap[typeid(AsmExp)] = 7;
typeMap[typeid(AsmEqualExp)] = 8;
typeMap[typeid(AsmLogAndExp)] = 9;
typeMap[typeid(AsmLogOrExp)] = 10;
typeMap[typeid(AsmMulExp)] = 11;
typeMap[typeid(AsmOrExp)] = 12;
typeMap[typeid(AsmRelExp)] = 13;
typeMap[typeid(AsmUnaExp)] = 14;
typeMap[typeid(AsmShiftExp)] = 15;
typeMap[typeid(AsmXorExp)] = 16;
typeMap[typeid(AssertExpression)] = 17;
typeMap[typeid(AssignExpression)] = 18;
typeMap[typeid(CmpExpression)] = 19;
typeMap[typeid(DeleteExpression)] = 20;
typeMap[typeid(EqualExpression)] = 21;
typeMap[typeid(Expression)] = 22;
typeMap[typeid(FunctionCallExpression)] = 23;
typeMap[typeid(FunctionLiteralExpression)] = 24;
typeMap[typeid(IdentityExpression)] = 25;
typeMap[typeid(ImportExpression)] = 26;
typeMap[typeid(IndexExpression)] = 27;
typeMap[typeid(InExpression)] = 28;
typeMap[typeid(IsExpression)] = 29;
typeMap[typeid(MixinExpression)] = 30;
typeMap[typeid(MulExpression)] = 31;
typeMap[typeid(NewAnonClassExpression)] = 32;
typeMap[typeid(NewExpression)] = 33;
typeMap[typeid(OrExpression)] = 34;
typeMap[typeid(OrOrExpression)] = 35;
typeMap[typeid(PowExpression)] = 36;
typeMap[typeid(PragmaExpression)] = 37;
typeMap[typeid(PrimaryExpression)] = 38;
typeMap[typeid(RelExpression)] = 39;
typeMap[typeid(ShiftExpression)] = 40;
typeMap[typeid(Index)] = 41;
typeMap[typeid(TemplateMixinExpression)] = 42;
typeMap[typeid(TernaryExpression)] = 43;
typeMap[typeid(TraitsExpression)] = 44;
typeMap[typeid(TypeidExpression)] = 45;
typeMap[typeid(TypeofExpression)] = 46;
typeMap[typeid(UnaryExpression)] = 47;
typeMap[typeid(XorExpression)] = 48;
}
/// Describes which syntax was used in a list of declarations in the containing AST node
enum DeclarationListStyle : ubyte
{
/// A declaration directly after the containing AST node making it the only child
single,
/// A colon (`:`) was used in the containing AST node meaning all following declarations are part here.
colon,
/// The declarations have been specified in a block denoted by starting `{` and ending `}` tokens.
block
}
/**
* Implements the $(LINK2 http://en.wikipedia.org/wiki/Visitor_pattern, Visitor Pattern)
* for the various AST classes
*/
abstract class ASTVisitor
{
/** */
void visit(const ExpressionNode n)
{
switch (typeMap[typeid(n)])
{
case 1: visit(cast(AddExpression) n); break;
case 2: visit(cast(AndAndExpression) n); break;
case 3: visit(cast(AndExpression) n); break;
case 4: visit(cast(AsmAddExp) n); break;
case 5: visit(cast(AsmAndExp) n); break;
case 6: visit(cast(AsmBrExp) n); break;
case 7: visit(cast(AsmExp) n); break;
case 8: visit(cast(AsmEqualExp) n); break;
case 9: visit(cast(AsmLogAndExp) n); break;
case 10: visit(cast(AsmLogOrExp) n); break;
case 11: visit(cast(AsmMulExp) n); break;
case 12: visit(cast(AsmOrExp) n); break;
case 13: visit(cast(AsmRelExp) n); break;
case 14: visit(cast(AsmUnaExp) n); break;
case 15: visit(cast(AsmShiftExp) n); break;
case 16: visit(cast(AsmXorExp) n); break;
case 17: visit(cast(AssertExpression) n); break;
case 18: visit(cast(AssignExpression) n); break;
case 19: visit(cast(CmpExpression) n); break;
case 20: visit(cast(DeleteExpression) n); break;
case 21: visit(cast(EqualExpression) n); break;
case 22: visit(cast(Expression) n); break;
case 23: visit(cast(FunctionCallExpression) n); break;
case 24: visit(cast(FunctionLiteralExpression) n); break;
case 25: visit(cast(IdentityExpression) n); break;
case 26: visit(cast(ImportExpression) n); break;
case 27: visit(cast(IndexExpression) n); break;
case 28: visit(cast(InExpression) n); break;
case 29: visit(cast(IsExpression) n); break;
case 30: visit(cast(MixinExpression) n); break;
case 31: visit(cast(MulExpression) n); break;
case 32: visit(cast(NewAnonClassExpression) n); break;
case 33: visit(cast(NewExpression) n); break;
case 34: visit(cast(OrExpression) n); break;
case 35: visit(cast(OrOrExpression) n); break;
case 36: visit(cast(PowExpression) n); break;
case 37: visit(cast(PragmaExpression) n); break;
case 38: visit(cast(PrimaryExpression) n); break;
case 39: visit(cast(RelExpression) n); break;
case 40: visit(cast(ShiftExpression) n); break;
case 41: visit(cast(Index) n); break;
case 42: visit(cast(TemplateMixinExpression) n); break;
case 43: visit(cast(TernaryExpression) n); break;
case 44: visit(cast(TraitsExpression) n); break;
case 45: visit(cast(TypeidExpression) n); break;
case 46: visit(cast(TypeofExpression) n); break;
case 47: visit(cast(UnaryExpression) n); break;
case 48: visit(cast(XorExpression) n); break;
default: assert(false, __MODULE__ ~ " has a bug");
}
}
/** */ void visit(const AddExpression addExpression) { addExpression.accept(this); }
/** */ void visit(const AliasDeclaration aliasDeclaration) { aliasDeclaration.accept(this); }
/** */ void visit(const AliasAssign aliasAssign) { aliasAssign.accept(this); }
/** */ void visit(const AliasInitializer aliasInitializer) { aliasInitializer.accept(this); }
/** */ void visit(const AliasThisDeclaration aliasThisDeclaration) { aliasThisDeclaration.accept(this); }
/** */ void visit(const AlignAttribute alignAttribute) { alignAttribute.accept(this); }
/** */ void visit(const AndAndExpression andAndExpression) { andAndExpression.accept(this); }
/** */ void visit(const AndExpression andExpression) { andExpression.accept(this); }
/** */ void visit(const AnonymousEnumDeclaration anonymousEnumDeclaration) { anonymousEnumDeclaration.accept(this); }
/** */ void visit(const AnonymousEnumMember anonymousEnumMember) { anonymousEnumMember.accept(this); }
/** */ void visit(const ArgumentList argumentList) { argumentList.accept(this); }
/** */ void visit(const Arguments arguments) { arguments.accept(this); }
/** */ void visit(const ArrayInitializer arrayInitializer) { arrayInitializer.accept(this); }
/** */ void visit(const ArrayLiteral arrayLiteral) { arrayLiteral.accept(this); }
/** */ void visit(const ArrayMemberInitialization arrayMemberInitialization) { arrayMemberInitialization.accept(this); }
/** */ void visit(const AsmAddExp asmAddExp) { asmAddExp.accept(this); }
/** */ void visit(const AsmAndExp asmAndExp) { asmAndExp.accept(this); }
/** */ void visit(const AsmBrExp asmBrExp) { asmBrExp.accept(this); }
/** */ void visit(const AsmEqualExp asmEqualExp) { asmEqualExp.accept(this); }
/** */ void visit(const AsmExp asmExp) { asmExp.accept(this); }
/** */ void visit(const AsmInstruction asmInstruction) { asmInstruction.accept(this); }
/** */ void visit(const AsmLogAndExp asmLogAndExp) { asmLogAndExp.accept(this); }
/** */ void visit(const AsmLogOrExp asmLogOrExp) { asmLogOrExp.accept(this); }
/** */ void visit(const AsmMulExp asmMulExp) { asmMulExp.accept(this); }
/** */ void visit(const AsmOrExp asmOrExp) { asmOrExp.accept(this); }
/** */ void visit(const AsmPrimaryExp asmPrimaryExp) { asmPrimaryExp.accept(this); }
/** */ void visit(const AsmRelExp asmRelExp) { asmRelExp.accept(this); }
/** */ void visit(const AsmShiftExp asmShiftExp) { asmShiftExp.accept(this); }
/** */ void visit(const AsmStatement asmStatement) { asmStatement.accept(this); }
/** */ void visit(const AsmTypePrefix asmTypePrefix) { asmTypePrefix.accept(this); }
/** */ void visit(const AsmUnaExp asmUnaExp) { asmUnaExp.accept(this); }
/** */ void visit(const AsmXorExp asmXorExp) { asmXorExp.accept(this); }
/** */ void visit(const AssertArguments assertArguments) { assertArguments.accept(this); }
/** */ void visit(const AssertExpression assertExpression) { assertExpression.accept(this); }
/** */ void visit(const AssignExpression assignExpression) { assignExpression.accept(this); }
/** */ void visit(const AssocArrayLiteral assocArrayLiteral) { assocArrayLiteral.accept(this); }
/** */ void visit(const AtAttribute atAttribute) { atAttribute.accept(this); }
/** */ void visit(const Attribute attribute) { attribute.accept(this); }
/** */ void visit(const AttributeDeclaration attributeDeclaration) { attributeDeclaration.accept(this); }
/** */ void visit(const AutoDeclaration autoDeclaration) { autoDeclaration.accept(this); }
/** */ void visit(const AutoDeclarationPart autoDeclarationPart) { autoDeclarationPart.accept(this); }
/** */ void visit(const BlockStatement blockStatement) { blockStatement.accept(this); }
/** */ void visit(const BreakStatement breakStatement) { breakStatement.accept(this); }
/** */ void visit(const BaseClass baseClass) { baseClass.accept(this); }
/** */ void visit(const BaseClassList baseClassList) { baseClassList.accept(this); }
/** */ void visit(const BitfieldWidth bitfieldWidth) { bitfieldWidth.accept(this); }
/** */ void visit(const CaseRangeStatement caseRangeStatement) { caseRangeStatement.accept(this); }
/** */ void visit(const CaseStatement caseStatement) { caseStatement.accept(this); }
/** */ void visit(const CastExpression castExpression) { castExpression.accept(this); }
/** */ void visit(const CastQualifier castQualifier) { castQualifier.accept(this); }
/** */ void visit(const Catch catch_) { catch_.accept(this); }
/** */ void visit(const Catches catches) { catches.accept(this); }
/** */ void visit(const ClassDeclaration classDeclaration) { classDeclaration.accept(this); }
/** */ void visit(const CmpExpression cmpExpression) { cmpExpression.accept(this); }
/** */ void visit(const CompileCondition compileCondition) { compileCondition.accept(this); }
/** */ void visit(const ConditionalDeclaration conditionalDeclaration) { conditionalDeclaration.accept(this); }
/** */ void visit(const ConditionalStatement conditionalStatement) { conditionalStatement.accept(this); }
/** */ void visit(const Constraint constraint) { constraint.accept(this); }
/** */ void visit(const Constructor constructor) { constructor.accept(this); }
/** */ void visit(const ContinueStatement continueStatement) { continueStatement.accept(this); }
/** */ void visit(const DebugCondition debugCondition) { debugCondition.accept(this); }
/** */ void visit(const DebugSpecification debugSpecification) { debugSpecification.accept(this); }
/** */ void visit(const Declaration declaration) { declaration.accept(this); }
/** */ void visit(const DeclarationOrStatement declarationsOrStatement) { declarationsOrStatement.accept(this); }
/** */ void visit(const DeclarationsAndStatements declarationsAndStatements) { declarationsAndStatements.accept(this); }
/** */ void visit(const Declarator declarator) { declarator.accept(this); }
/** */ void visit(const DefaultStatement defaultStatement) { defaultStatement.accept(this); }
/** */ void visit(const DeleteExpression deleteExpression) { deleteExpression.accept(this); }
/** */ void visit(const DeleteStatement deleteStatement) { deleteStatement.accept(this); }
/** */ void visit(const Deprecated deprecated_) { deprecated_.accept(this); }
/** */ void visit(const Destructor destructor) { destructor.accept(this); }
/** */ void visit(const DoStatement doStatement) { doStatement.accept(this); }
/** */ void visit(const EnumBody enumBody) { enumBody.accept(this); }
/** */ void visit(const EnumDeclaration enumDeclaration) { enumDeclaration.accept(this); }
/** */ void visit(const EnumMember enumMember) { enumMember.accept(this); }
/** */ void visit(const EnumMemberAttribute enumMemberAttribute) { enumMemberAttribute.accept(this); }
/** */ void visit(const EponymousTemplateDeclaration eponymousTemplateDeclaration) { eponymousTemplateDeclaration.accept(this); }
/** */ void visit(const EqualExpression equalExpression) { equalExpression.accept(this); }
/** */ void visit(const Expression expression) { expression.accept(this); }
/** */ void visit(const ExpressionStatement expressionStatement) { expressionStatement.accept(this); }
/** */ void visit(const FinalSwitchStatement finalSwitchStatement) { finalSwitchStatement.accept(this); }
/** */ void visit(const Finally finally_) { finally_.accept(this); }
/** */ void visit(const ForStatement forStatement) { forStatement.accept(this); }
/** */ void visit(const ForeachStatement foreachStatement) { foreachStatement.accept(this); }
/** */ void visit(const StaticForeachDeclaration staticForeachDeclaration) { staticForeachDeclaration.accept(this); }
/** */ void visit(const StaticForeachStatement staticForeachStatement) { staticForeachStatement.accept(this); }
/** */ void visit(const ForeachType foreachType) { foreachType.accept(this); }
/** */ void visit(const ForeachTypeList foreachTypeList) { foreachTypeList.accept(this); }
/** */ void visit(const FunctionAttribute functionAttribute) { functionAttribute.accept(this); }
/** */ void visit(const FunctionBody functionBody) { functionBody.accept(this); }
/** */ void visit(const FunctionCallExpression functionCallExpression) { functionCallExpression.accept(this); }
/** */ void visit(const FunctionContract functionContract) { functionContract.accept(this); }
/** */ void visit(const FunctionDeclaration functionDeclaration) { functionDeclaration.accept(this); }
/** */ void visit(const FunctionLiteralExpression functionLiteralExpression) { functionLiteralExpression.accept(this); }
/** */ void visit(const GccAsmInstruction gccAsmInstruction) { gccAsmInstruction.accept(this); }
/** */ void visit(const GccAsmOperandList gccAsmOperands) { gccAsmOperands.accept(this); }
/** */ void visit(const GccAsmOperand gccAsmOperand) { gccAsmOperand.accept(this); }
/** */ void visit(const GotoStatement gotoStatement) { gotoStatement.accept(this); }
/** */ void visit(const IdentifierChain identifierChain) { identifierChain.accept(this); }
/** */ void visit(const DeclaratorIdentifierList identifierList) { identifierList.accept(this); }
/** */ void visit(const IdentifierOrTemplateChain identifierOrTemplateChain) { identifierOrTemplateChain.accept(this); }
/** */ void visit(const IdentifierOrTemplateInstance identifierOrTemplateInstance) { identifierOrTemplateInstance.accept(this); }
/** */ void visit(const IdentityExpression identityExpression) { identityExpression.accept(this); }
/** */ void visit(const IfStatement ifStatement) { ifStatement.accept(this); }
/** */ void visit(const IfCondition ifCondition) { ifCondition.accept(this); }
/** */ void visit(const ImportBind importBind) { importBind.accept(this); }
/** */ void visit(const ImportBindings importBindings) { importBindings.accept(this); }
/** */ void visit(const ImportDeclaration importDeclaration) { importDeclaration.accept(this); }
/** */ void visit(const ImportExpression importExpression) { importExpression.accept(this); }
/** */ void visit(const IndexExpression indexExpression) { indexExpression.accept(this); }
/** */ void visit(const InContractExpression inContractExpression) { inContractExpression.accept(this); }
/** */ void visit(const InExpression inExpression) { inExpression.accept(this); }
/** */ void visit(const InOutContractExpression inOutContractExpression) { inOutContractExpression.accept(this); }
/** */ void visit(const InOutStatement inOutStatement) { inOutStatement.accept(this); }
/** */ void visit(const InStatement inStatement) { inStatement.accept(this); }
/** */ void visit(const Initialize initialize) { initialize.accept(this); }
/** */ void visit(const Initializer initializer) { initializer.accept(this); }
/** */ void visit(const InterfaceDeclaration interfaceDeclaration) { interfaceDeclaration.accept(this); }
/** */ void visit(const Invariant invariant_) { invariant_.accept(this); }
/** */ void visit(const IsExpression isExpression) { isExpression.accept(this); }
/** */ void visit(const KeyValuePair keyValuePair) { keyValuePair.accept(this); }
/** */ void visit(const KeyValuePairs keyValuePairs) { keyValuePairs.accept(this); }
/** */ void visit(const LabeledStatement labeledStatement) { labeledStatement.accept(this); }
/** */ void visit(const LastCatch lastCatch) { lastCatch.accept(this); }
/** */ void visit(const LinkageAttribute linkageAttribute) { linkageAttribute.accept(this); }
/** */ void visit(const MemberFunctionAttribute memberFunctionAttribute) { memberFunctionAttribute.accept(this); }
/** */ void visit(const MissingFunctionBody missingFunctionBody) { missingFunctionBody.accept(this); }
/** */ void visit(const MixinDeclaration mixinDeclaration) { mixinDeclaration.accept(this); }
/** */ void visit(const MixinExpression mixinExpression) { mixinExpression.accept(this); }
/** */ void visit(const MixinTemplateDeclaration mixinTemplateDeclaration) { mixinTemplateDeclaration.accept(this); }
/** */ void visit(const MixinTemplateName mixinTemplateName) { mixinTemplateName.accept(this); }
/** */ void visit(const Module module_) { module_.accept(this); }
/** */ void visit(const ModuleDeclaration moduleDeclaration) { moduleDeclaration.accept(this); }
/** */ void visit(const MulExpression mulExpression) { mulExpression.accept(this); }
/** */ void visit(const NamespaceList namespaceList) { namespaceList.accept(this); }
/** */ void visit(const NewAnonClassExpression newAnonClassExpression) { newAnonClassExpression.accept(this); }
/** */ void visit(const NewExpression newExpression) { newExpression.accept(this); }
/** */ void visit(const NonVoidInitializer nonVoidInitializer) { nonVoidInitializer.accept(this); }
/** */ void visit(const Operands operands) { operands.accept(this); }
/** */ void visit(const OrExpression orExpression) { orExpression.accept(this); }
/** */ void visit(const OrOrExpression orOrExpression) { orOrExpression.accept(this); }
/** */ void visit(const OutContractExpression outContractExpression) { outContractExpression.accept(this); }
/** */ void visit(const OutStatement outStatement) { outStatement.accept(this); }
/** */ void visit(const ParameterAttribute parameterAttribute) { parameterAttribute.accept(this); }
/** */ void visit(const Parameter parameter) { parameter.accept(this); }
/** */ void visit(const Parameters parameters) { parameters.accept(this); }
/** */ void visit(const Postblit postblit) { postblit.accept(this); }
/** */ void visit(const PowExpression powExpression) { powExpression.accept(this); }
/** */ void visit(const PragmaDeclaration pragmaDeclaration) { pragmaDeclaration.accept(this); }
/** */ void visit(const PragmaStatement pragmaStatement) { pragmaStatement.accept(this); }
/** */ void visit(const PragmaExpression pragmaExpression) { pragmaExpression.accept(this); }
/** */ void visit(const PrimaryExpression primaryExpression) { primaryExpression.accept(this); }
/** */ void visit(const Register register) { register.accept(this); }
/** */ void visit(const RelExpression relExpression) { relExpression.accept(this); }
/** */ void visit(const ReturnStatement returnStatement) { returnStatement.accept(this); }
/** */ void visit(const ScopeGuardStatement scopeGuardStatement) { scopeGuardStatement.accept(this); }
/** */ void visit(const SharedStaticConstructor sharedStaticConstructor) { sharedStaticConstructor.accept(this); }
/** */ void visit(const SharedStaticDestructor sharedStaticDestructor) { sharedStaticDestructor.accept(this); }
/** */ void visit(const ShiftExpression shiftExpression) { shiftExpression.accept(this); }
/** */ void visit(const ShortenedFunctionBody shortenedFunctionBody) { shortenedFunctionBody.accept(this); }
/** */ void visit(const SingleImport singleImport) { singleImport.accept(this); }
/** */ void visit(const Index index) { index.accept(this); }
/** */ void visit(const SpecifiedFunctionBody specifiedFunctionBody) { specifiedFunctionBody.accept(this); }
/** */ void visit(const Statement statement) { statement.accept(this); }
/** */ void visit(const StatementNoCaseNoDefault statementNoCaseNoDefault) { statementNoCaseNoDefault.accept(this); }
/** */ void visit(const StaticAssertDeclaration staticAssertDeclaration) { staticAssertDeclaration.accept(this); }
/** */ void visit(const StaticAssertStatement staticAssertStatement) { staticAssertStatement.accept(this); }
/** */ void visit(const StaticConstructor staticConstructor) { staticConstructor.accept(this); }
/** */ void visit(const StaticDestructor staticDestructor) { staticDestructor.accept(this); }
/** */ void visit(const StaticIfCondition staticIfCondition) { staticIfCondition.accept(this); }
/** */ void visit(const StorageClass storageClass) { storageClass.accept(this); }
/** */ void visit(const StringLiteralList stringLiteralList) { stringLiteralList.accept(this); }
/** */ void visit(const StructBody structBody) { structBody.accept(this); }
/** */ void visit(const StructDeclaration structDeclaration) { structDeclaration.accept(this); }
/** */ void visit(const StructInitializer structInitializer) { structInitializer.accept(this); }
/** */ void visit(const StructMemberInitializer structMemberInitializer) { structMemberInitializer.accept(this); }
/** */ void visit(const StructMemberInitializers structMemberInitializers) { structMemberInitializers.accept(this); }
/** */ void visit(const SwitchStatement switchStatement) { switchStatement.accept(this); }
/** */ void visit(const Symbol symbol) { symbol.accept(this); }
/** */ void visit(const SynchronizedStatement synchronizedStatement) { synchronizedStatement.accept(this); }
/** */ void visit(const TemplateAliasParameter templateAliasParameter) { templateAliasParameter.accept(this); }
/** */ void visit(const TemplateArgument templateArgument) { templateArgument.accept(this); }
/** */ void visit(const TemplateArgumentList templateArgumentList) { templateArgumentList.accept(this); }
/** */ void visit(const TemplateArguments templateArguments) { templateArguments.accept(this); }
/** */ void visit(const TemplateDeclaration templateDeclaration) { templateDeclaration.accept(this); }
/** */ void visit(const TemplateInstance templateInstance) { templateInstance.accept(this); }
/** */ void visit(const TemplateMixinExpression templateMixinExpression) { templateMixinExpression.accept(this); }
/** */ void visit(const TemplateParameter templateParameter) { templateParameter.accept(this); }
/** */ void visit(const TemplateParameterList templateParameterList) { templateParameterList.accept(this); }
/** */ void visit(const TemplateParameters templateParameters) { templateParameters.accept(this); }
/** */ void visit(const TemplateSingleArgument templateSingleArgument) { templateSingleArgument.accept(this); }
/** */ void visit(const TemplateThisParameter templateThisParameter) { templateThisParameter.accept(this); }
/** */ void visit(const TemplateTupleParameter templateTupleParameter) { templateTupleParameter.accept(this); }
/** */ void visit(const TemplateTypeParameter templateTypeParameter) { templateTypeParameter.accept(this); }
/** */ void visit(const TemplateValueParameter templateValueParameter) { templateValueParameter.accept(this); }
/** */ void visit(const TemplateValueParameterDefault templateValueParameterDefault) { templateValueParameterDefault.accept(this); }
/** */ void visit(const TernaryExpression ternaryExpression) { ternaryExpression.accept(this); }
/** */ void visit(const ThrowExpression throwExpression) { throwExpression.accept(this); }
/** */ void visit(const Token) { }
/** */ void visit(const TraitsExpression traitsExpression) { traitsExpression.accept(this); }
/** */ void visit(const TryStatement tryStatement) { tryStatement.accept(this); }
/** */ void visit(const Type type) { type.accept(this); }
/** */ void visit(const TypeIdentifierPart typeIdentChain) { typeIdentChain.accept(this); }
/** */ void visit(const Type2 type2) { type2.accept(this); }
/** */ void visit(const TypeSpecialization typeSpecialization) { typeSpecialization.accept(this); }
/** */ void visit(const TypeSuffix typeSuffix) { typeSuffix.accept(this); }
/** */ void visit(const TypeidExpression typeidExpression) { typeidExpression.accept(this); }
/** */ void visit(const TypeofExpression typeofExpression) { typeofExpression.accept(this); }
/** */ void visit(const UnaryExpression unaryExpression) { unaryExpression.accept(this); }
/** */ void visit(const UnionDeclaration unionDeclaration) { unionDeclaration.accept(this); }
/** */ void visit(const Unittest unittest_) { unittest_.accept(this); }
/** */ void visit(const VariableDeclaration variableDeclaration) { variableDeclaration.accept(this); }
/** */ void visit(const Vector vector) { vector.accept(this); }
/** */ void visit(const VersionCondition versionCondition) { versionCondition.accept(this); }
/** */ void visit(const VersionSpecification versionSpecification) { versionSpecification.accept(this); }
/** */ void visit(const WhileStatement whileStatement) { whileStatement.accept(this); }
/** */ void visit(const WithStatement withStatement) { withStatement.accept(this); }
/** */ void visit(const XorExpression xorExpression) { xorExpression.accept(this); }
}
interface ASTNode
{
/** */ void accept(ASTVisitor visitor) const;
}
template visitIfNotNull(fields ...)
{
static if (fields.length > 1)
immutable visitIfNotNull = visitIfNotNull!(fields[0]) ~ visitIfNotNull!(fields[1..$]);
else
{
static if (typeof(fields[0]).stringof[$ - 2 .. $] == "[]")
{
static if (__traits(hasMember, typeof(fields[0][0]), "classinfo"))
immutable visitIfNotNull = "foreach (i; " ~ fields[0].stringof ~ ") if (i !is null) visitor.visit(i);\n";
else
immutable visitIfNotNull = "foreach (i; " ~ fields[0].stringof ~ ") visitor.visit(i);\n";
}
else static if (__traits(hasMember, typeof(fields[0]), "classinfo"))
immutable visitIfNotNull = "if (" ~ fields[0].stringof ~ " !is null) visitor.visit(" ~ fields[0].stringof ~ ");\n";
else static if (is(Unqual!(typeof(fields[0])) == Token))
immutable visitIfNotNull = "if (" ~ fields[0].stringof ~ ` != tok!""` ~ ") visitor.visit(" ~ fields[0].stringof ~ ");\n";
else
immutable visitIfNotNull = "visitor.visit(" ~ fields[0].stringof ~ ");\n";
}
}
mixin template OpEquals(bool print = false)
{
override bool opEquals(Object other) const
{
static if (print)
pragma(msg, generateOpEquals!(typeof(this)));
mixin (generateOpEquals!(typeof(this)));
}
}
template generateOpEquals(T)
{
template opEqualsPart(p ...)
{
import std.traits : isSomeFunction, isDynamicArray;
import std.algorithm : among;
static if (p.length > 1)
{
enum opEqualsPart = opEqualsPart!(p[0 .. $/2]) ~ opEqualsPart!(p[$/2 .. $]);
}
else static if (p.length
&& !__traits(isDeprecated, __traits(getMember, T, p[0]))
&& !isSomeFunction!(typeof(__traits(getMember, T, p[0])))
&& !p[0].among("comment", "line", "column", "endLocation", "startLocation", "index", "dotLocation"))
{
static if (isDynamicArray!(typeof(__traits(getMember, T, p[0]))))
{
enum opEqualsPart = "\tif (obj." ~ p[0] ~ ".length != " ~ p[0] ~ ".length) return false;\n"
~ "\tforeach (i; 0 .. " ~ p[0] ~ ".length)\n"
~ "\t\tif (" ~ p[0] ~ "[i] != obj." ~ p[0] ~ "[i]) return false;\n";
}
else
enum opEqualsPart = "\tif (obj." ~ p[0] ~ " != " ~ p[0] ~ ") return false;\n";
}
else
enum opEqualsPart = "";
}
enum generateOpEquals = "if (auto obj = cast(" ~ T.stringof ~ ") other){\n"
~ opEqualsPart!(__traits(derivedMembers, T))
~ "\treturn true;\n}\nreturn false;";
}
abstract class BaseNode : ASTNode
{
/** List of tokens consumed by this AST node */ const(Token)[] tokens;
abstract void accept(ASTVisitor visitor) const;
}
abstract class ExpressionNode : BaseNode
{
override void accept(ASTVisitor visitor) const
{
assert (false);
}
}
mixin template BinaryExpressionBody()
{
ExpressionNode left;
ExpressionNode right;
size_t line;
size_t column;
}
///
final class AddExpression : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin OpEquals;
/** */ IdType operator;
mixin BinaryExpressionBody;
}
///
final class AliasDeclaration : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(storageClasses, type, declaratorIdentifierList,
initializers, parameters, memberFunctionAttributes));
}
mixin OpEquals;
/** */ StorageClass[] storageClasses;
/** */ Type type;
/** */ DeclaratorIdentifierList declaratorIdentifierList;
/** */ AliasInitializer[] initializers;
/** */ string comment;
/** */ Parameters parameters;
/** */ MemberFunctionAttribute[] memberFunctionAttributes;
}
///
final class AliasAssign : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(identifier, type));
}
mixin OpEquals;
/** */ Token identifier;
/** */ Type type;
/** */ string comment;
}
///
final class AliasInitializer : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(name, templateParameters, storageClasses, type,
functionLiteralExpression));
}
mixin OpEquals;
/** */ Token name;
/** */ StorageClass[] storageClasses;
/** */ TemplateParameters templateParameters;
/** */ Type type;
/** */ FunctionLiteralExpression functionLiteralExpression;
/** */ Parameters parameters;
/** */ MemberFunctionAttribute[] memberFunctionAttributes;
}
///
final class AliasThisDeclaration : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(identifier));
}
mixin OpEquals;
/** */ Token identifier;
/** */ string comment;
}
///
final class AlignAttribute : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(assignExpression));
}
mixin OpEquals;
/** */ ExpressionNode assignExpression;
}
///
final class AndAndExpression : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin OpEquals;
mixin BinaryExpressionBody;
}
///
final class AndExpression : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin OpEquals;
mixin BinaryExpressionBody;
}
///
final class AnonymousEnumDeclaration : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(baseType, members));
}
mixin OpEquals;
/** */ Type baseType;
/** */ AnonymousEnumMember[] members;
}
///
final class AnonymousEnumMember : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(type, name, assignExpression));
}
/** */ Type type;
/** */ Token name;
/** */ ExpressionNode assignExpression;
/** */ string comment;
}
///
final class ArgumentList : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(items));
}
mixin OpEquals;
/** */ ExpressionNode[] items;
/** */ size_t startLocation;
/** */ size_t endLocation;
}
///
final class Arguments : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(argumentList));
}
mixin OpEquals;
/** */ ArgumentList argumentList;
}
///
final class ArrayInitializer : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(arrayMemberInitializations));
}
mixin OpEquals;
/** */ size_t startLocation;
/** */ size_t endLocation;
/** */ ArrayMemberInitialization[] arrayMemberInitializations;
}
///
final class ArrayLiteral : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(argumentList));
}
mixin OpEquals;
/** */ ArgumentList argumentList;
}
///
final class ArrayMemberInitialization : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(assignExpression, nonVoidInitializer));
}
mixin OpEquals;
/** */ ExpressionNode assignExpression;
/** */ NonVoidInitializer nonVoidInitializer;
}
///
final class AsmAddExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin OpEquals;
/** */ IdType operator;
mixin BinaryExpressionBody;
}
///
final class AsmAndExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin OpEquals;
mixin BinaryExpressionBody;
}
///
final class AsmBrExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(asmBrExp, asmExp, asmUnaExp));
}
mixin OpEquals;
size_t line;
size_t column;
/** */ AsmBrExp asmBrExp;
/** */ ExpressionNode asmExp;
/** */ AsmUnaExp asmUnaExp;
}
///
final class AsmEqualExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
mixin OpEquals;
/** */ IdType operator;
}
///
final class AsmExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, middle, right));
}
mixin OpEquals;
/** */ ExpressionNode left;
/** */ ExpressionNode middle;
/** */ ExpressionNode right;
}
///
final class AsmInstruction : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(identifierOrIntegerOrOpcode, asmInstruction, operands));
}
mixin OpEquals;
/** */ Token identifierOrIntegerOrOpcode;
/** */ bool hasAlign;
/** */ bool isLabel;
/** */ AsmInstruction asmInstruction;
/** */ Operands operands;
}
///
final class AsmLogAndExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
mixin OpEquals;
}
///
final class AsmLogOrExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
mixin OpEquals;
}
///
final class AsmMulExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
/** */ IdType operator;
mixin BinaryExpressionBody;
mixin OpEquals;
}
///
final class AsmOrExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
mixin OpEquals;
}
///
final class AsmPrimaryExp : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(token, register, asmExp, identifierChain,
segmentOverrideSuffix));
}
/** */ ExpressionNode asmExp;
/** */ IdentifierChain identifierChain;
/** */ Register register;
/** */ ExpressionNode segmentOverrideSuffix;
/** */ Token token;
mixin OpEquals;
}
///
final class AsmRelExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
/** */ IdType operator;
mixin OpEquals;
}
///
final class AsmShiftExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
/** */ IdType operator;
mixin OpEquals;
}
///
final class AsmStatement : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(functionAttributes, asmInstructions, gccAsmInstructions));
}
/** */ AsmInstruction[] asmInstructions;
/** */ GccAsmInstruction[] gccAsmInstructions;
/** */ FunctionAttribute[] functionAttributes;
mixin OpEquals;
}
///
final class AsmTypePrefix : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
/** */ Token left;
/** */ Token right;
mixin OpEquals;
}
///
final class AsmUnaExp : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(prefix, asmTypePrefix, asmExp, asmPrimaryExp, asmUnaExp));
}
/** */ AsmTypePrefix asmTypePrefix;
/** */ ExpressionNode asmExp;
/** */ Token prefix;
/** */ AsmPrimaryExp asmPrimaryExp;
/** */ AsmUnaExp asmUnaExp;
mixin OpEquals;
}
///
final class AsmXorExp : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(left, right));
}
mixin BinaryExpressionBody;
mixin OpEquals;
}
///
final class AssertArguments : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(assertion, message));
}
/** */ ExpressionNode assertion;
/** */ ExpressionNode message;
mixin OpEquals;
}
///
final class AssertExpression : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(assertArguments));
}
/** */ size_t line;
/** */ size_t column;
/** */ AssertArguments assertArguments;
mixin OpEquals;
}
///
final class AssignExpression : ExpressionNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(ternaryExpression, expression));
}
/** */ ExpressionNode ternaryExpression;
/** */ ExpressionNode expression;
/** */ IdType operator;
/** */ size_t line;
/** */ size_t column;
mixin OpEquals;
}
///
final class AssocArrayLiteral : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(keyValuePairs));
}
/** */ KeyValuePairs keyValuePairs;
mixin OpEquals;
}
///
final class AtAttribute : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(templateInstance, argumentList));
}
/** */ ArgumentList argumentList;
/** */ TemplateInstance templateInstance;
/** */ Token identifier;
/** */ bool useParen;
/** */ size_t startLocation;
/** */ size_t endLocation;
mixin OpEquals;
}
///
final class Attribute : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(pragmaExpression, deprecated_, atAttribute,
alignAttribute, identifierChain, linkageAttribute));
}
/** */ PragmaExpression pragmaExpression;
/** */ Deprecated deprecated_;
/** */ AtAttribute atAttribute;
/** */ AlignAttribute alignAttribute;
/** */ LinkageAttribute linkageAttribute;
/** */ Token attribute;
/** */ IdentifierChain identifierChain;
mixin OpEquals;
}
///
final class AttributeDeclaration : BaseNode
{
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(attribute));
}
/** */ Attribute attribute;
/** */ size_t line;
mixin OpEquals;
}
///
final class AutoDeclaration : BaseNode
{
override void accept(ASTVisitor visitor) const
{
foreach (sc; storageClasses)
visitor.visit(sc);
foreach (part; parts)
visitor.visit(part);
}
/** */ AutoDeclarationPart[] parts;
/** */ StorageClass[] storageClasses;
/** */ string comment;
mixin OpEquals;
}
final class AutoDeclarationPart : BaseNode
{
override void accept(ASTVisitor visitor) const
{
if (templateParameters !is null)
visitor.visit(templateParameters);
visitor.visit(initializer);
}
/** */ Token identifier;
/** */ Initializer initializer;
/** */ TemplateParameters templateParameters;
}
///
final class BlockStatement : BaseNode