-
Notifications
You must be signed in to change notification settings - Fork 40
/
extractor.rs
1100 lines (939 loc) · 31.1 KB
/
extractor.rs
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
use crate::{
ast::*,
visitor::ast_visitor::{ASTConstVisitor, Node},
};
use eyre::Result;
////////// PUBLICLY AVAILABLE EXTRACTION LIBRARY /////////////////////////
// ExtractArrayTypeNames is an extractor that extracts all ArrayTypeName nodes from a node.
#[derive(Default)]
pub struct ExtractArrayTypeNames {
pub extracted: Vec<ArrayTypeName>,
}
impl ExtractArrayTypeNames {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractArrayTypeNames = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractArrayTypeNames {
fn visit_array_type_name(&mut self, node: &ArrayTypeName) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractAssignments is an extractor that extracts all Assignments nodes from a node.
#[derive(Default)]
pub struct ExtractAssignments {
pub extracted: Vec<Assignment>,
}
impl ExtractAssignments {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractAssignments = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractAssignments {
fn visit_assignment(&mut self, node: &Assignment) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractBinaryOperations is an extractor that extracts all BinaryOperations nodes from a node.
#[derive(Default)]
pub struct ExtractBinaryOperations {
pub extracted: Vec<BinaryOperation>,
}
impl ExtractBinaryOperations {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractBinaryOperations = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractBinaryOperations {
fn visit_binary_operation(&mut self, node: &BinaryOperation) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractBlocks extracts all Block nodes from a given node.
#[derive(Default)]
pub struct ExtractBlocks {
pub extracted: Vec<Block>,
}
impl ExtractBlocks {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractBlocks {
fn visit_block(&mut self, node: &Block) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractConditionals extracts all Conditional nodes from a given node.
#[derive(Default)]
pub struct ExtractConditionals {
pub extracted: Vec<Conditional>,
}
impl ExtractConditionals {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractConditionals {
fn visit_conditional(&mut self, node: &Conditional) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractContractDefinitions extracts all ContractDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractContractDefinitions {
pub extracted: Vec<ContractDefinition>,
}
impl ExtractContractDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractContractDefinitions {
fn visit_contract_definition(&mut self, node: &ContractDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractElementaryTypeNames extracts all ElementaryTypeName nodes from a given node.
#[derive(Default)]
pub struct ExtractElementaryTypeNames {
pub extracted: Vec<ElementaryTypeName>,
}
impl ExtractElementaryTypeNames {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractElementaryTypeNames {
fn visit_elementary_type_name(&mut self, node: &ElementaryTypeName) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractElementaryTypeNameExpressions extracts all ElementaryTypeNameExpression nodes from a given node.
#[derive(Default)]
pub struct ExtractElementaryTypeNameExpressions {
pub extracted: Vec<ElementaryTypeNameExpression>,
}
impl ExtractElementaryTypeNameExpressions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractElementaryTypeNameExpressions {
fn visit_elementary_type_name_expression(
&mut self,
node: &ElementaryTypeNameExpression,
) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractEmitStatements extracts all EmitStatement nodes from a given node.
#[derive(Default)]
pub struct ExtractEmitStatements {
pub extracted: Vec<EmitStatement>,
}
impl ExtractEmitStatements {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractEmitStatements {
fn visit_emit_statement(&mut self, node: &EmitStatement) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractEnumDefinitions extracts all EnumDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractEnumDefinitions {
pub extracted: Vec<EnumDefinition>,
}
impl ExtractEnumDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractEnumDefinitions {
fn visit_enum_definition(&mut self, node: &EnumDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractEnumValues extracts all EnumValue nodes from a given node.
#[derive(Default)]
pub struct ExtractEnumValues {
pub extracted: Vec<EnumValue>,
}
impl ExtractEnumValues {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractEnumValues {
fn visit_enum_value(&mut self, node: &EnumValue) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractEventDefinitions extracts all EventDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractEventDefinitions {
pub extracted: Vec<EventDefinition>,
}
impl ExtractEventDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractEventDefinitions {
fn visit_event_definition(&mut self, node: &EventDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractErrorDefinitions extracts all ErrorDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractErrorDefinitions {
pub extracted: Vec<ErrorDefinition>,
}
impl ExtractErrorDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractErrorDefinitions {
fn visit_error_definition(&mut self, node: &ErrorDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractExpressionStatements extracts all ExpressionStatement nodes from a given node.
#[derive(Default)]
pub struct ExtractExpressionStatements {
pub extracted: Vec<ExpressionStatement>,
}
impl ExtractExpressionStatements {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractExpressionStatements {
fn visit_expression_statement(&mut self, node: &ExpressionStatement) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractFunctionCalls extracts all FunctionCall nodes from a given node.
#[derive(Default)]
pub struct ExtractFunctionCalls {
pub extracted: Vec<FunctionCall>,
}
impl ExtractFunctionCalls {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractFunctionCalls {
fn visit_function_call(&mut self, node: &FunctionCall) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractFunctionCallsOps extracts all FunctionCallOps nodes from a given node.
#[derive(Default)]
pub struct ExtractFunctionCallOptions {
pub extracted: Vec<FunctionCallOptions>,
}
impl ExtractFunctionCallOptions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractFunctionCallOptions {
fn visit_function_call_options(&mut self, node: &FunctionCallOptions) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractFunctionDefinitions extracts all FunctionDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractFunctionDefinitions {
pub extracted: Vec<FunctionDefinition>,
}
impl ExtractFunctionDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractFunctionDefinitions {
fn visit_function_definition(&mut self, node: &FunctionDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractFunctionTypeNames extracts all FunctionTypeName nodes from a given node.
#[derive(Default)]
pub struct ExtractFunctionTypeNames {
pub extracted: Vec<FunctionTypeName>,
}
impl ExtractFunctionTypeNames {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractFunctionTypeNames {
fn visit_function_type_name(&mut self, node: &FunctionTypeName) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractForStatements extracts all ForStatement nodes from a given node.
#[derive(Default)]
pub struct ExtractForStatements {
pub extracted: Vec<ForStatement>,
}
impl ExtractForStatements {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractForStatements {
fn visit_for_statement(&mut self, node: &ForStatement) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractIdentifiers extracts all Identifier nodes from a given node.
#[derive(Default)]
pub struct ExtractIdentifiers {
pub extracted: Vec<Identifier>,
}
impl ExtractIdentifiers {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractIdentifiers {
fn visit_identifier(&mut self, node: &Identifier) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractIdentifierPaths extracts all IdentifierPath nodes from a given node.
#[derive(Default)]
pub struct ExtractIdentifierPaths {
pub extracted: Vec<IdentifierPath>,
}
impl ExtractIdentifierPaths {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractIdentifierPaths {
fn visit_identifier_path(&mut self, node: &IdentifierPath) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractIfStatements extracts all IfStatement nodes from a given node.
#[derive(Default)]
pub struct ExtractIfStatements {
pub extracted: Vec<IfStatement>,
}
impl ExtractIfStatements {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractIfStatements = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractIfStatements {
fn visit_if_statement(&mut self, node: &IfStatement) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractImportDirectives extracts all ImportDirective nodes from a given node.
#[derive(Default)]
pub struct ExtractImportDirectives {
pub extracted: Vec<ImportDirective>,
}
impl ExtractImportDirectives {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractImportDirectives = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractImportDirectives {
fn visit_import_directive(&mut self, node: &ImportDirective) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractIndexAccesses extracts all IndexAccess nodes from a given node.
#[derive(Default)]
pub struct ExtractIndexAccesses {
pub extracted: Vec<IndexAccess>,
}
impl ExtractIndexAccesses {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractIndexAccesses = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractIndexAccesses {
fn visit_index_access(&mut self, node: &IndexAccess) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractIndexRangeAccesses extracts all IndexRangeAccess nodes from a given node.
#[derive(Default)]
pub struct ExtractIndexRangeAccesses {
pub extracted: Vec<IndexRangeAccess>,
}
impl ExtractIndexRangeAccesses {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractIndexRangeAccesses = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractIndexRangeAccesses {
fn visit_index_range_access(&mut self, node: &IndexRangeAccess) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractInheritanceSpecifiers extracts all InheritanceSpecifier nodes from a given node.
#[derive(Default)]
pub struct ExtractInheritanceSpecifiers {
pub extracted: Vec<InheritanceSpecifier>,
}
impl ExtractInheritanceSpecifiers {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractInheritanceSpecifiers = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractInheritanceSpecifiers {
fn visit_inheritance_specifier(&mut self, node: &InheritanceSpecifier) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractInlineAssemblys extracts all InlineAssembly nodes from a given node.
#[derive(Default)]
pub struct ExtractInlineAssemblys {
pub extracted: Vec<InlineAssembly>,
}
impl ExtractInlineAssemblys {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractInlineAssemblys = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractInlineAssemblys {
fn visit_inline_assembly(&mut self, node: &InlineAssembly) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractLiterals extracts all Literal nodes from a given node.
#[derive(Default)]
pub struct ExtractLiterals {
pub extracted: Vec<Literal>,
}
impl ExtractLiterals {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractLiterals = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractLiterals {
fn visit_literal(&mut self, node: &Literal) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractMemberAccesses is an extractor that extracts all MemberAccess nodes from a node.
#[derive(Default)]
pub struct ExtractMemberAccesses {
pub extracted: Vec<MemberAccess>,
}
impl ExtractMemberAccesses {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractMemberAccesses = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractMemberAccesses {
fn visit_member_access(&mut self, node: &MemberAccess) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractNewExpressions extracts all NewExpression nodes from a given node.
#[derive(Default)]
pub struct ExtractNewExpressions {
pub extracted: Vec<NewExpression>,
}
impl ExtractNewExpressions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractNewExpressions = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractNewExpressions {
fn visit_new_expression(&mut self, node: &NewExpression) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractMappings extracts all Mapping nodes from a given node.
#[derive(Default)]
pub struct ExtractMappings {
pub extracted: Vec<Mapping>,
}
impl ExtractMappings {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractMappings = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractMappings {
fn visit_mapping(&mut self, node: &Mapping) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractModifierDefinitions extracts all ModifierDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractModifierDefinitions {
pub extracted: Vec<ModifierDefinition>,
}
impl ExtractModifierDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractModifierDefinitions = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractModifierDefinitions {
fn visit_modifier_definition(&mut self, node: &ModifierDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractModifierInvocations extracts all ModifierInvocation nodes from a given node.
#[derive(Default)]
pub struct ExtractModifierInvocations {
pub extracted: Vec<ModifierInvocation>,
}
impl ExtractModifierInvocations {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractModifierInvocations = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractModifierInvocations {
fn visit_modifier_invocation(&mut self, node: &ModifierInvocation) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractOverrideSpecifiers extracts all OverrideSpecifier nodes from a given node.
#[derive(Default)]
pub struct ExtractOverrideSpecifiers {
pub extracted: Vec<OverrideSpecifier>,
}
impl ExtractOverrideSpecifiers {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractOverrideSpecifiers = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractOverrideSpecifiers {
fn visit_override_specifier(&mut self, node: &OverrideSpecifier) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractParameterLists extracts all ParameterList nodes from a given node.
#[derive(Default)]
pub struct ExtractParameterLists {
pub extracted: Vec<ParameterList>,
}
impl ExtractParameterLists {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractParameterLists = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractParameterLists {
fn visit_parameter_list(&mut self, node: &ParameterList) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractPragmaDirectives extracts all PragmaDirective nodes from a given node.
#[derive(Default)]
pub struct ExtractPragmaDirectives {
pub extracted: Vec<PragmaDirective>,
}
impl ExtractPragmaDirectives {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractPragmaDirectives = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractPragmaDirectives {
fn visit_pragma_directive(&mut self, node: &PragmaDirective) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractReturns extracts all Return nodes from a given node.
#[derive(Default)]
pub struct ExtractReturns {
pub extracted: Vec<Return>,
}
impl ExtractReturns {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractReturns = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractReturns {
fn visit_return(&mut self, node: &Return) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractRevertStatements extracts all RevertStatement nodes from a given node.
#[derive(Default)]
pub struct ExtractRevertStatements {
pub extracted: Vec<RevertStatement>,
}
impl ExtractRevertStatements {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractRevertStatements = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractRevertStatements {
fn visit_revert_statement(&mut self, node: &RevertStatement) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractSourceUnits is not needed
// ExtractStructDefinitions extracts all StructDefinition nodes from a given node.
#[derive(Default)]
pub struct ExtractStructDefinitions {
pub extracted: Vec<StructDefinition>,
}
impl ExtractStructDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractStructDefinitions = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractStructDefinitions {
fn visit_struct_definition(&mut self, node: &StructDefinition) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractStructuredDocumentations extracts all StructuredDocumentation nodes from a given node.
#[derive(Default)]
pub struct ExtractStructuredDocumentations {
pub extracted: Vec<StructuredDocumentation>,
}
impl ExtractStructuredDocumentations {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractStructuredDocumentations = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractStructuredDocumentations {
fn visit_structured_documentation(&mut self, node: &StructuredDocumentation) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractTryStatements extracts all TryStatement nodes from a given node.
#[derive(Default)]
pub struct ExtractTryStatements {
pub extracted: Vec<TryStatement>,
}
impl ExtractTryStatements {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractTryStatements = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractTryStatements {
fn visit_try_statement(&mut self, node: &TryStatement) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractTryCatchClauses extracts all TryCatchClause nodes from a given node.
#[derive(Default)]
pub struct ExtractTryCatchClauses {
pub extracted: Vec<TryCatchClause>,
}
impl ExtractTryCatchClauses {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractTryCatchClauses = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractTryCatchClauses {
fn visit_try_catch_clause(&mut self, node: &TryCatchClause) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractTupleExpressions extracts all TupleExpression nodes from a given node.
#[derive(Default)]
pub struct ExtractTupleExpressions {
pub extracted: Vec<TupleExpression>,
}
impl ExtractTupleExpressions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractTupleExpressions = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractTupleExpressions {
fn visit_tuple_expression(&mut self, node: &TupleExpression) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractUnaryOperations extracts all UnaryOperations nodes from a given node.
#[derive(Default)]
pub struct ExtractUnaryOperations {
pub extracted: Vec<UnaryOperation>,
}
impl ExtractUnaryOperations {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractUnaryOperations = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractUnaryOperations {
fn visit_unary_operation(&mut self, node: &UnaryOperation) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractUserDefinedTypeNames extracts all UserDefinedTypeName nodes from a given node.
#[derive(Default)]
pub struct ExtractUserDefinedTypeNames {
pub extracted: Vec<UserDefinedTypeName>,
}
impl ExtractUserDefinedTypeNames {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractUserDefinedTypeNames = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractUserDefinedTypeNames {
fn visit_user_defined_type_name(&mut self, node: &UserDefinedTypeName) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractUserDefinedValueTypeDefinitions extracts all UserDefinedValueTypes nodes from a given node.
#[derive(Default)]
pub struct ExtractUserDefinedValueTypeDefinitions {
pub extracted: Vec<UserDefinedValueTypeDefinition>,
}
impl ExtractUserDefinedValueTypeDefinitions {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractUserDefinedValueTypeDefinitions = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}
impl ASTConstVisitor for ExtractUserDefinedValueTypeDefinitions {
fn visit_user_defined_value_type_definition(
&mut self,
node: &UserDefinedValueTypeDefinition,
) -> Result<bool> {
self.extracted.push(node.clone());
Ok(true)
}
}
// ExtractUsingForDirectives extracts all UsingForDirective nodes from a given node.
#[derive(Default)]
pub struct ExtractUsingForDirectives {
pub extracted: Vec<UsingForDirective>,
}
impl ExtractUsingForDirectives {
pub fn from<T: Node + ?Sized>(node: &T) -> Self {
let mut extractor: ExtractUsingForDirectives = Self::default();
node.accept(&mut extractor).unwrap_or_default();
extractor
}
}