-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.type.h
890 lines (780 loc) · 26.4 KB
/
ast.type.h
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
#ifndef AST_X_MACRO
#define AST_X_MACRO(X) \
X(AST_FUNCTION, ASTFunction, ast_function) \
X(AST_FUNCTION_POINTER_EXPR, ASTFunctionPointerExpr, ast_function_pointer_expr) \
X(AST_STRUCT_EXPR, ASTStructExpr, ast_struct_expr) \
X(AST_ARRAY_EXPR, ASTArrayExpr, ast_array_expr) \
X(AST_GROUP_EXPR, ASTGroupExpr, ast_group_expr) \
X(AST_ASSIGNMENT_EXPR, ASTAssignmentExpr, ast_assignment_expr) \
X(AST_BINARY_EXPR, ASTBinaryExpr, ast_binary_expr) \
X(AST_CALL_EXPR, ASTCallExpr, ast_call_expr) \
X(AST_CONDITIONAL_EXPR, ASTConditionalExpr, ast_conditional_expr) \
X(AST_FILE_REFERENCE, ASTFileReference, ast_file_reference) \
X(AST_IDENTIFIER, ASTIdentifier, ast_identifier) \
X(AST_SELF, ASTSelf, ast_self) \
X(AST_LITERAL, ASTLiteral, ast_literal) \
X(AST_MEMBER_EXPR, ASTMemberExpr, ast_member_expr) \
X(AST_UNARY_EXPR, ASTUnaryExpr, ast_unary_expr) \
X(AST_VECTOR_EXPR, ASTVectorExpr, ast_vector_expr) \
X(AST_BLOCK_STMT, ASTBlockStmt, ast_block_stmt) \
X(AST_BREAK_STMT, ASTBreakStmt, ast_break_stmt) \
X(AST_CONTINUE_STMT, ASTContinueStmt, ast_continue_stmt) \
X(AST_DO_WHILE_STMT, ASTDoWhileStmt, ast_do_while_stmt) \
X(AST_EMPTY_STMT, ASTEmptyStmt, ast_empty_stmt) \
X(AST_EXPR_STMT, ASTExprStmt, ast_expr_stmt) \
X(AST_FOR_STMT, ASTForStmt, ast_for_stmt) \
X(AST_IF_STMT, ASTIfStmt, ast_if_stmt) \
X(AST_RETURN_STMT, ASTReturnStmt, ast_return_stmt) \
X(AST_SWITCH_CASE, ASTSwitchCase, ast_switch_case) \
X(AST_SWITCH_STMT, ASTSwitchStmt, ast_switch_stmt) \
X(AST_WAIT_STMT, ASTWaitStmt, ast_wait_stmt) \
X(AST_WAIT_TILL_FRAME_END_STMT, ASTWaitTillFrameEndStmt, ast_wait_till_frame_end_stmt) \
X(AST_WHILE_STMT, ASTWhileStmt, ast_while_stmt)
#endif
#ifndef AST_TYPE_HEADER_INCLUDE_GUARD
#define AST_TYPE_HEADER_INCLUDE_GUARD
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef struct
{
char name[256];
ASTNodePtr body;
ASTNodePtr parameters;
int parameter_count;
} ASTFunction;
typedef struct
{
ASTNodePtr expression;
} ASTFunctionPointerExpr;
typedef struct
{
size_t numelements;
ASTNodePtr *elements;
} ASTStructExpr;
typedef struct
{
size_t numelements;
ASTNodePtr *elements;
} ASTArrayExpr;
typedef struct
{
ASTNodePtr expression;
} ASTGroupExpr;
typedef struct
{
ASTNodePtr lhs;
ASTNodePtr rhs;
uint32 op;
} ASTAssignmentExpr;
typedef struct
{
ASTNodePtr lhs;
ASTNodePtr rhs;
uint32 op;
} ASTBinaryExpr;
typedef struct
{
bool threaded;
bool pointer;
ASTNodePtr object;
ASTNodePtr callee;
size_t numarguments;
ASTNodePtr *arguments;
} ASTCallExpr;
typedef struct
{
ASTNodePtr condition;
ASTNodePtr consequent;
ASTNodePtr alternative;
} ASTConditionalExpr;
typedef struct
{
char file[256];
} ASTFileReference;
typedef struct
{
char name[256];
} ASTIdentifier;
typedef enum
{
AST_LITERAL_TYPE_STRING,
AST_LITERAL_TYPE_INTEGER,
AST_LITERAL_TYPE_BOOLEAN,
AST_LITERAL_TYPE_FLOAT,
AST_LITERAL_TYPE_FUNCTION,
AST_LITERAL_TYPE_LOCALIZED_STRING,
AST_LITERAL_TYPE_UNDEFINED
} ASTLiteralType;
typedef struct
{
int unused;
} ASTSelf;
typedef struct
{
uint32 type;
ASTLiteralValue value;
} ASTLiteral;
typedef struct
{
ASTNodePtr object;
ASTNodePtr prop;
uint32 op;
} ASTMemberExpr;
typedef struct
{
ASTNodePtr argument;
uint32 op;
bool prefix;
} ASTUnaryExpr;
typedef struct
{
size_t numelements;
ASTNodePtr *elements;
} ASTVectorExpr;
typedef struct
{
size_t numbody;
ASTNodePtr *body;
} ASTBlockStmt;
typedef struct
{
int unused;
} ASTBreakStmt;
typedef struct
{
int unused;
} ASTContinueStmt;
typedef struct
{
ASTNodePtr test;
ASTNodePtr body;
} ASTDoWhileStmt;
typedef struct
{
int unused;
} ASTEmptyStmt;
typedef struct
{
ASTNodePtr expression;
} ASTExprStmt;
typedef struct
{
ASTNodePtr init;
ASTNodePtr test;
ASTNodePtr update;
ASTNodePtr body;
} ASTForStmt;
typedef struct
{
ASTNodePtr test;
ASTNodePtr consequent;
ASTNodePtr alternative;
} ASTIfStmt;
typedef struct
{
ASTNodePtr argument;
} ASTReturnStmt;
typedef struct
{
ASTNodePtr test;
ASTNodePtr consequent;
} ASTSwitchCase;
typedef struct
{
ASTNodePtr discriminant;
size_t numcases;
ASTSwitchCase *cases;
} ASTSwitchStmt;
typedef struct
{
ASTNodePtr duration;
} ASTWaitStmt;
typedef struct
{
int unused;
} ASTWaitTillFrameEndStmt;
typedef struct
{
ASTNodePtr test;
ASTNodePtr body;
} ASTWhileStmt;
#ifdef AST_VISITOR_IMPLEMENTATION
#ifndef STRUCT_TYPE_INFO_DEFINED
#define STRUCT_TYPE_INFO_DEFINED
typedef struct
{
const char *name;
uint32_t hash;
size_t size;
size_t alignment;
void (*initialize)(void*);
void* (*clone)(void*);
size_t (*visitor)(void *visitor, const char *key, void *value, size_t nmemb, size_t size);
} StructTypeInfo;
#endif
// #include <stdalign.h>
#if __STDC_VERSION__ >= 202311L // C23
// Already supported
#elif __STDC_VERSION__ >= 201112L // C11
#define alignof _Alignof
#else
#define alignof(x) __alignof__(x) // Try GCC extension
#endif
typedef struct AstVisitor_s AstVisitor;
typedef size_t (*AstVisitorFn)(AstVisitor *visitor, const char *key, void *value, size_t nmemb, size_t size);
struct AstVisitor_s
{
void *ctx;
AstVisitorFn visit_char;
AstVisitorFn visit_uint32;
AstVisitorFn visit_ASTLiteralValue;
AstVisitorFn visit_ASTNodePtr;
AstVisitorFn visit_int;
AstVisitorFn visit_bool;
AstVisitorFn visit_ASTSwitchCase;
bool (*pre_visit)(AstVisitor *visitor, const char *key, uint32_t hashed_key, void **value, size_t *nmemb, size_t size);
};
// ============ VISITORS ==================
static size_t ASTFunction_visit(AstVisitor *visitor, const char *key, ASTFunction *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "name", 0x8e631b86, (void**)&inst->name, NULL, sizeof(inst->name[0])))
{
changed_count += visitor->visit_char(visitor, "name", (char*)&inst->name[0], 256, sizeof(inst->name[0]));
}
if(visitor->pre_visit(visitor, "body", 0xc6c93295, NULL, NULL, sizeof(inst->body)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "body", (ASTNodePtr*)&inst->body, 1, sizeof(inst->body));
}
if(visitor->pre_visit(visitor, "parameters", 0x3234cd99, NULL, NULL, sizeof(inst->parameters)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "parameters", (ASTNodePtr*)&inst->parameters, 1, sizeof(inst->parameters));
}
if(visitor->pre_visit(visitor, "parameter_count", 0xbe61e9fc, NULL, NULL, sizeof(inst->parameter_count)))
{
changed_count += visitor->visit_int(visitor, "parameter_count", (int*)&inst->parameter_count, 1, sizeof(inst->parameter_count));
}
return changed_count;
}
static size_t ASTFunctionPointerExpr_visit(AstVisitor *visitor, const char *key, ASTFunctionPointerExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "expression", 0x8a3083cb, NULL, NULL, sizeof(inst->expression)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "expression", (ASTNodePtr*)&inst->expression, 1, sizeof(inst->expression));
}
return changed_count;
}
static size_t ASTStructExpr_visit(AstVisitor *visitor, const char *key, ASTStructExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "elements", 0xf6da3a6c, (void**)&inst->elements, &inst->numelements, sizeof(inst->elements[0])) && inst->elements && inst->numelements > 0)
{
changed_count += visitor->visit_ASTNodePtr(visitor, "elements", (ASTNodePtr*)&inst->elements[0], inst->numelements, sizeof(inst->elements[0]));
}
return changed_count;
}
static size_t ASTArrayExpr_visit(AstVisitor *visitor, const char *key, ASTArrayExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "elements", 0xf6da3a6c, (void**)&inst->elements, &inst->numelements, sizeof(inst->elements[0])) && inst->elements && inst->numelements > 0)
{
changed_count += visitor->visit_ASTNodePtr(visitor, "elements", (ASTNodePtr*)&inst->elements[0], inst->numelements, sizeof(inst->elements[0]));
}
return changed_count;
}
static size_t ASTGroupExpr_visit(AstVisitor *visitor, const char *key, ASTGroupExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "expression", 0x8a3083cb, NULL, NULL, sizeof(inst->expression)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "expression", (ASTNodePtr*)&inst->expression, 1, sizeof(inst->expression));
}
return changed_count;
}
static size_t ASTAssignmentExpr_visit(AstVisitor *visitor, const char *key, ASTAssignmentExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "lhs", 0x1dad32be, NULL, NULL, sizeof(inst->lhs)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "lhs", (ASTNodePtr*)&inst->lhs, 1, sizeof(inst->lhs));
}
if(visitor->pre_visit(visitor, "rhs", 0x6119edbc, NULL, NULL, sizeof(inst->rhs)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "rhs", (ASTNodePtr*)&inst->rhs, 1, sizeof(inst->rhs));
}
if(visitor->pre_visit(visitor, "op", 0xb556600a, NULL, NULL, sizeof(inst->op)))
{
changed_count += visitor->visit_uint32(visitor, "op", (uint32*)&inst->op, 1, sizeof(inst->op));
}
return changed_count;
}
static size_t ASTBinaryExpr_visit(AstVisitor *visitor, const char *key, ASTBinaryExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "lhs", 0x1dad32be, NULL, NULL, sizeof(inst->lhs)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "lhs", (ASTNodePtr*)&inst->lhs, 1, sizeof(inst->lhs));
}
if(visitor->pre_visit(visitor, "rhs", 0x6119edbc, NULL, NULL, sizeof(inst->rhs)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "rhs", (ASTNodePtr*)&inst->rhs, 1, sizeof(inst->rhs));
}
if(visitor->pre_visit(visitor, "op", 0xb556600a, NULL, NULL, sizeof(inst->op)))
{
changed_count += visitor->visit_uint32(visitor, "op", (uint32*)&inst->op, 1, sizeof(inst->op));
}
return changed_count;
}
static size_t ASTCallExpr_visit(AstVisitor *visitor, const char *key, ASTCallExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "threaded", 0x3cd9f388, NULL, NULL, sizeof(inst->threaded)))
{
changed_count += visitor->visit_bool(visitor, "threaded", (bool*)&inst->threaded, 1, sizeof(inst->threaded));
}
if(visitor->pre_visit(visitor, "pointer", 0xb5d9498a, NULL, NULL, sizeof(inst->pointer)))
{
changed_count += visitor->visit_bool(visitor, "pointer", (bool*)&inst->pointer, 1, sizeof(inst->pointer));
}
if(visitor->pre_visit(visitor, "object", 0x50df0ffa, NULL, NULL, sizeof(inst->object)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "object", (ASTNodePtr*)&inst->object, 1, sizeof(inst->object));
}
if(visitor->pre_visit(visitor, "callee", 0x5e4679f3, NULL, NULL, sizeof(inst->callee)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "callee", (ASTNodePtr*)&inst->callee, 1, sizeof(inst->callee));
}
if(visitor->pre_visit(visitor, "arguments", 0x63a2219f, (void**)&inst->arguments, &inst->numarguments, sizeof(inst->arguments[0])) && inst->arguments && inst->numarguments > 0)
{
changed_count += visitor->visit_ASTNodePtr(visitor, "arguments", (ASTNodePtr*)&inst->arguments[0], inst->numarguments, sizeof(inst->arguments[0]));
}
return changed_count;
}
static size_t ASTConditionalExpr_visit(AstVisitor *visitor, const char *key, ASTConditionalExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "condition", 0x1750745e, NULL, NULL, sizeof(inst->condition)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "condition", (ASTNodePtr*)&inst->condition, 1, sizeof(inst->condition));
}
if(visitor->pre_visit(visitor, "consequent", 0x125347fa, NULL, NULL, sizeof(inst->consequent)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "consequent", (ASTNodePtr*)&inst->consequent, 1, sizeof(inst->consequent));
}
if(visitor->pre_visit(visitor, "alternative", 0x7ce8b368, NULL, NULL, sizeof(inst->alternative)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "alternative", (ASTNodePtr*)&inst->alternative, 1, sizeof(inst->alternative));
}
return changed_count;
}
static size_t ASTFileReference_visit(AstVisitor *visitor, const char *key, ASTFileReference *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "file", 0xf02a6a23, (void**)&inst->file, NULL, sizeof(inst->file[0])))
{
changed_count += visitor->visit_char(visitor, "file", (char*)&inst->file[0], 256, sizeof(inst->file[0]));
}
return changed_count;
}
static size_t ASTIdentifier_visit(AstVisitor *visitor, const char *key, ASTIdentifier *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "name", 0x8e631b86, (void**)&inst->name, NULL, sizeof(inst->name[0])))
{
changed_count += visitor->visit_char(visitor, "name", (char*)&inst->name[0], 256, sizeof(inst->name[0]));
}
return changed_count;
}
static size_t ASTSelf_visit(AstVisitor *visitor, const char *key, ASTSelf *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "unused", 0xd46e39db, NULL, NULL, sizeof(inst->unused)))
{
changed_count += visitor->visit_int(visitor, "unused", (int*)&inst->unused, 1, sizeof(inst->unused));
}
return changed_count;
}
static size_t ASTLiteral_visit(AstVisitor *visitor, const char *key, ASTLiteral *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "type", 0x7bfa9c2d, NULL, NULL, sizeof(inst->type)))
{
changed_count += visitor->visit_uint32(visitor, "type", (uint32*)&inst->type, 1, sizeof(inst->type));
}
if(visitor->pre_visit(visitor, "value", 0x30e80cea, NULL, NULL, sizeof(inst->value)))
{
changed_count += visitor->visit_ASTLiteralValue(visitor, "value", (ASTLiteralValue*)&inst->value, 1, sizeof(inst->value));
}
return changed_count;
}
static size_t ASTMemberExpr_visit(AstVisitor *visitor, const char *key, ASTMemberExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "object", 0x50df0ffa, NULL, NULL, sizeof(inst->object)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "object", (ASTNodePtr*)&inst->object, 1, sizeof(inst->object));
}
if(visitor->pre_visit(visitor, "prop", 0x35379c18, NULL, NULL, sizeof(inst->prop)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "prop", (ASTNodePtr*)&inst->prop, 1, sizeof(inst->prop));
}
if(visitor->pre_visit(visitor, "op", 0xb556600a, NULL, NULL, sizeof(inst->op)))
{
changed_count += visitor->visit_uint32(visitor, "op", (uint32*)&inst->op, 1, sizeof(inst->op));
}
return changed_count;
}
static size_t ASTUnaryExpr_visit(AstVisitor *visitor, const char *key, ASTUnaryExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "argument", 0x3c41b216, NULL, NULL, sizeof(inst->argument)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "argument", (ASTNodePtr*)&inst->argument, 1, sizeof(inst->argument));
}
if(visitor->pre_visit(visitor, "op", 0xb556600a, NULL, NULL, sizeof(inst->op)))
{
changed_count += visitor->visit_uint32(visitor, "op", (uint32*)&inst->op, 1, sizeof(inst->op));
}
if(visitor->pre_visit(visitor, "prefix", 0x72531e29, NULL, NULL, sizeof(inst->prefix)))
{
changed_count += visitor->visit_bool(visitor, "prefix", (bool*)&inst->prefix, 1, sizeof(inst->prefix));
}
return changed_count;
}
static size_t ASTVectorExpr_visit(AstVisitor *visitor, const char *key, ASTVectorExpr *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "elements", 0xf6da3a6c, (void**)&inst->elements, &inst->numelements, sizeof(inst->elements[0])) && inst->elements && inst->numelements > 0)
{
changed_count += visitor->visit_ASTNodePtr(visitor, "elements", (ASTNodePtr*)&inst->elements[0], inst->numelements, sizeof(inst->elements[0]));
}
return changed_count;
}
static size_t ASTBlockStmt_visit(AstVisitor *visitor, const char *key, ASTBlockStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "body", 0xc6c93295, (void**)&inst->body, &inst->numbody, sizeof(inst->body[0])) && inst->body && inst->numbody > 0)
{
changed_count += visitor->visit_ASTNodePtr(visitor, "body", (ASTNodePtr*)&inst->body[0], inst->numbody, sizeof(inst->body[0]));
}
return changed_count;
}
static size_t ASTBreakStmt_visit(AstVisitor *visitor, const char *key, ASTBreakStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "unused", 0xd46e39db, NULL, NULL, sizeof(inst->unused)))
{
changed_count += visitor->visit_int(visitor, "unused", (int*)&inst->unused, 1, sizeof(inst->unused));
}
return changed_count;
}
static size_t ASTContinueStmt_visit(AstVisitor *visitor, const char *key, ASTContinueStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "unused", 0xd46e39db, NULL, NULL, sizeof(inst->unused)))
{
changed_count += visitor->visit_int(visitor, "unused", (int*)&inst->unused, 1, sizeof(inst->unused));
}
return changed_count;
}
static size_t ASTDoWhileStmt_visit(AstVisitor *visitor, const char *key, ASTDoWhileStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "test", 0x197c2b25, NULL, NULL, sizeof(inst->test)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "test", (ASTNodePtr*)&inst->test, 1, sizeof(inst->test));
}
if(visitor->pre_visit(visitor, "body", 0xc6c93295, NULL, NULL, sizeof(inst->body)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "body", (ASTNodePtr*)&inst->body, 1, sizeof(inst->body));
}
return changed_count;
}
static size_t ASTEmptyStmt_visit(AstVisitor *visitor, const char *key, ASTEmptyStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "unused", 0xd46e39db, NULL, NULL, sizeof(inst->unused)))
{
changed_count += visitor->visit_int(visitor, "unused", (int*)&inst->unused, 1, sizeof(inst->unused));
}
return changed_count;
}
static size_t ASTExprStmt_visit(AstVisitor *visitor, const char *key, ASTExprStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "expression", 0x8a3083cb, NULL, NULL, sizeof(inst->expression)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "expression", (ASTNodePtr*)&inst->expression, 1, sizeof(inst->expression));
}
return changed_count;
}
static size_t ASTForStmt_visit(AstVisitor *visitor, const char *key, ASTForStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "init", 0x7ab57213, NULL, NULL, sizeof(inst->init)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "init", (ASTNodePtr*)&inst->init, 1, sizeof(inst->init));
}
if(visitor->pre_visit(visitor, "test", 0x197c2b25, NULL, NULL, sizeof(inst->test)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "test", (ASTNodePtr*)&inst->test, 1, sizeof(inst->test));
}
if(visitor->pre_visit(visitor, "update", 0x2a3d0454, NULL, NULL, sizeof(inst->update)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "update", (ASTNodePtr*)&inst->update, 1, sizeof(inst->update));
}
if(visitor->pre_visit(visitor, "body", 0xc6c93295, NULL, NULL, sizeof(inst->body)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "body", (ASTNodePtr*)&inst->body, 1, sizeof(inst->body));
}
return changed_count;
}
static size_t ASTIfStmt_visit(AstVisitor *visitor, const char *key, ASTIfStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "test", 0x197c2b25, NULL, NULL, sizeof(inst->test)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "test", (ASTNodePtr*)&inst->test, 1, sizeof(inst->test));
}
if(visitor->pre_visit(visitor, "consequent", 0x125347fa, NULL, NULL, sizeof(inst->consequent)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "consequent", (ASTNodePtr*)&inst->consequent, 1, sizeof(inst->consequent));
}
if(visitor->pre_visit(visitor, "alternative", 0x7ce8b368, NULL, NULL, sizeof(inst->alternative)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "alternative", (ASTNodePtr*)&inst->alternative, 1, sizeof(inst->alternative));
}
return changed_count;
}
static size_t ASTReturnStmt_visit(AstVisitor *visitor, const char *key, ASTReturnStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "argument", 0x3c41b216, NULL, NULL, sizeof(inst->argument)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "argument", (ASTNodePtr*)&inst->argument, 1, sizeof(inst->argument));
}
return changed_count;
}
static size_t ASTSwitchCase_visit(AstVisitor *visitor, const char *key, ASTSwitchCase *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "test", 0x197c2b25, NULL, NULL, sizeof(inst->test)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "test", (ASTNodePtr*)&inst->test, 1, sizeof(inst->test));
}
if(visitor->pre_visit(visitor, "consequent", 0x125347fa, NULL, NULL, sizeof(inst->consequent)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "consequent", (ASTNodePtr*)&inst->consequent, 1, sizeof(inst->consequent));
}
return changed_count;
}
static size_t ASTSwitchStmt_visit(AstVisitor *visitor, const char *key, ASTSwitchStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "discriminant", 0xdbdd9d44, NULL, NULL, sizeof(inst->discriminant)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "discriminant", (ASTNodePtr*)&inst->discriminant, 1, sizeof(inst->discriminant));
}
if(visitor->pre_visit(visitor, "cases", 0x5ebf046, (void**)&inst->cases, &inst->numcases, sizeof(inst->cases[0])) && inst->cases && inst->numcases > 0)
{
changed_count += visitor->visit_ASTSwitchCase(visitor, "cases", (ASTSwitchCase*)&inst->cases[0], inst->numcases, sizeof(inst->cases[0]));
}
return changed_count;
}
static size_t ASTWaitStmt_visit(AstVisitor *visitor, const char *key, ASTWaitStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "duration", 0x9dd3208d, NULL, NULL, sizeof(inst->duration)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "duration", (ASTNodePtr*)&inst->duration, 1, sizeof(inst->duration));
}
return changed_count;
}
static size_t ASTWaitTillFrameEndStmt_visit(AstVisitor *visitor, const char *key, ASTWaitTillFrameEndStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "unused", 0xd46e39db, NULL, NULL, sizeof(inst->unused)))
{
changed_count += visitor->visit_int(visitor, "unused", (int*)&inst->unused, 1, sizeof(inst->unused));
}
return changed_count;
}
static size_t ASTWhileStmt_visit(AstVisitor *visitor, const char *key, ASTWhileStmt *inst, size_t nmemb, size_t size)
{
size_t changed_count = 0;
size_t n = 0;
if(visitor->pre_visit(visitor, "test", 0x197c2b25, NULL, NULL, sizeof(inst->test)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "test", (ASTNodePtr*)&inst->test, 1, sizeof(inst->test));
}
if(visitor->pre_visit(visitor, "body", 0xc6c93295, NULL, NULL, sizeof(inst->body)))
{
changed_count += visitor->visit_ASTNodePtr(visitor, "body", (ASTNodePtr*)&inst->body, 1, sizeof(inst->body));
}
return changed_count;
}
// ================================================================
static size_t ast_visitor_dummy_(AstVisitor *visitor, const char *key, void *value, size_t nmemb, size_t size) { return 0; }
static bool ast_pre_visit_dummy_(AstVisitor *visitor, const char *key, uint32_t hashed_key, void **value, size_t *nmemb, size_t size) { return true; }
static void type_ast_visitor_init(AstVisitor *v, void *ctx)
{
v->ctx = ctx;
v->pre_visit = ast_pre_visit_dummy_;
v->visit_char = ast_visitor_dummy_;
v->visit_uint32 = ast_visitor_dummy_;
v->visit_ASTLiteralValue = ast_visitor_dummy_;
v->visit_ASTNodePtr = ast_visitor_dummy_;
v->visit_int = ast_visitor_dummy_;
v->visit_bool = ast_visitor_dummy_;
v->visit_ASTSwitchCase = (AstVisitorFn)ASTSwitchCase_visit;
}
// ============ INITIALIZATION ==================
static void ASTFunction_init(ASTFunction *inst)
{
}
static void ASTFunctionPointerExpr_init(ASTFunctionPointerExpr *inst)
{
}
static void ASTStructExpr_init(ASTStructExpr *inst)
{
}
static void ASTArrayExpr_init(ASTArrayExpr *inst)
{
}
static void ASTGroupExpr_init(ASTGroupExpr *inst)
{
}
static void ASTAssignmentExpr_init(ASTAssignmentExpr *inst)
{
}
static void ASTBinaryExpr_init(ASTBinaryExpr *inst)
{
}
static void ASTCallExpr_init(ASTCallExpr *inst)
{
inst->threaded = false;
inst->pointer = false;
}
static void ASTConditionalExpr_init(ASTConditionalExpr *inst)
{
}
static void ASTFileReference_init(ASTFileReference *inst)
{
}
static void ASTIdentifier_init(ASTIdentifier *inst)
{
}
static void ASTSelf_init(ASTSelf *inst)
{
}
static void ASTLiteral_init(ASTLiteral *inst)
{
}
static void ASTMemberExpr_init(ASTMemberExpr *inst)
{
}
static void ASTUnaryExpr_init(ASTUnaryExpr *inst)
{
}
static void ASTVectorExpr_init(ASTVectorExpr *inst)
{
}
static void ASTBlockStmt_init(ASTBlockStmt *inst)
{
}
static void ASTBreakStmt_init(ASTBreakStmt *inst)
{
}
static void ASTContinueStmt_init(ASTContinueStmt *inst)
{
}
static void ASTDoWhileStmt_init(ASTDoWhileStmt *inst)
{
}
static void ASTEmptyStmt_init(ASTEmptyStmt *inst)
{
}
static void ASTExprStmt_init(ASTExprStmt *inst)
{
}
static void ASTForStmt_init(ASTForStmt *inst)
{
}
static void ASTIfStmt_init(ASTIfStmt *inst)
{
}
static void ASTReturnStmt_init(ASTReturnStmt *inst)
{
}
static void ASTSwitchCase_init(ASTSwitchCase *inst)
{
}
static void ASTSwitchStmt_init(ASTSwitchStmt *inst)
{
inst->numcases = 0;
inst->cases = NULL;
}
static void ASTWaitStmt_init(ASTWaitStmt *inst)
{
}
static void ASTWaitTillFrameEndStmt_init(ASTWaitTillFrameEndStmt *inst)
{
}
static void ASTWhileStmt_init(ASTWhileStmt *inst)
{
}
// ================================================================
#ifndef type_info
static StructTypeInfo* type_info_(StructTypeInfo **ptr)
{
return *ptr;
}
#define type_info(ptr) type_info_((StructTypeInfo**)ptr)
#endif
#ifndef type_init
#define type_init(type, name) \
type name = (type){ 0 }; \
type##_init(&name)
#endif
#endif
#endif