-
Notifications
You must be signed in to change notification settings - Fork 7
/
frontend.c
executable file
·8318 lines (6975 loc) · 203 KB
/
frontend.c
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
#
//
// jff_a2c
// a simple translator from Algol 60 to plain C
// just for fun, but with educational value
//
// This file contains the complete front end source.
//
// This front end translates an ALGOL program
// into an equivalent C program and a header file
// with prototypes.
// This front end will be called by a driver program
// passing all required parameters, but can be called separately
//
//
// Version 2.1
// Copyright:
// Jan van Katwijk
// TU Delft
// The Netherlands
// July 2002
//
//
//
// Copyright (C) 2002, 2003 J. van Katwijk
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, you can either send email to this
// program's maintainer or write to: The Free Software Foundation,
// Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
//
//
//
#include <time.h>
#include "frontend.h"
#include <string.h>
#ifndef VERSION
#define VERSION "2.4"
#endif
char *compile_time = "no time specified";
char *infile = NULL;
char *c_file = NULL;
char *include_file = NULL;
char *header_file = HEADER;
char *op_file = OPERATOR_E;
char *prelude = PRELUDE_E;
int languageFlag = 0;
FILE *f_out;
int errors = 0;
int sem_errors = 0;
struct glob_list aa;
struct glob_list *globals = &aa;
struct symbol s;
void compile (char *);
int main (int argc, char **argv) {
int i;
for (i = 1; i < argc; i ++) {
if (argv [i][0] == '-') { // it is an option
switch (argv [i][1]) {
case 'c': c_file = argv [i + 1]; i ++;
break;
case 'F': languageFlag = atoi (argv [i + 1]); i ++;
break;
case 'f': include_file = argv [i + 1]; i ++;
break;
case 'o': op_file = argv [i + 1]; i ++;
break;
case 'p': prelude = argv [i + 1]; i ++;
break;
case 'h': header_file = argv [i + 1]; i ++;
break;
case 't': compile_time = argv [i + 1]; i ++;
break;
default: break;
}
}
else {
// it is the name of the file to be compiled
infile = argv [i];
}
}
if (infile == (char *)0) {
fprintf (stderr, "No input file given\n");
exit (EXIT_FAILURE);
}
compile (infile);
exit (EXIT_SUCCESS);
}
// tree handling
// in this version of jff-a2c, we made a stupid tree
// in an array like fashion.
// reason: I want to be able to translate this into
// algol itself
//class treenode {
//public:
// int nodeid;
// treenode *nextnode;
// int line_no, char_no;
// unsigned int node_flag;
//};
#define NODEID 0
#define NEXTNODE 1
#define LINE_NO 2
#define CHAR_NO 3
#define NODE_FLAGS 4
int get_nodeid (treenode *t) {
return (int)(t [NODEID]. f);
}
treenode *get_nextnode (treenode *t) {
return (treenode *)(t [NEXTNODE]. f);
}
void set_nextnode (treenode *x, treenode *y) {
x [NEXTNODE]. f = y;
}
int get_lineno (treenode *t) {
return (int)(t [LINE_NO]. f);
}
void set_lineno (treenode *t, int l) {
t [LINE_NO]. f = (treenode *)l;
}
int get_charno (treenode *t) {
return (int)(t [CHAR_NO]. f);
}
void set_charno (treenode *t, int cn) {
t [CHAR_NO]. f = (treenode *)cn;
}
unsigned int get_flags (treenode *t) {
return (unsigned int)(t [NODE_FLAGS]. f);
}
void set_flags (treenode *t, unsigned int f) {
t [NODE_FLAGS]. f = (treenode *)f;
}
//class declaration: public treenode {
//public:
// char *decl_ident;
// treenode *decl_env;
// treenode *next_dec;
// char *c_name;
//};
#define DECL_IDENT NODE_FLAGS+1
#define DECL_ENV NODE_FLAGS+2
#define NEXT_DEC NODE_FLAGS+3
#define C_NAME NODE_FLAGS+4
#define SIZEOF_DECLARATION C_NAME+1
//class type_def: public treenode {
//public:
// char *type_id;
// char *internal_name;
// char *c_type;
//};
//
//class simple_type: public type_def {
//public:
//};
//
//
//class label_type: public type_def {
//public:
//};
//
//class anytype: public type_def {
//public:
//};
//
//class stringtype: public type_def {
//public:
//};
//
//class errortype: public type_def {
//public:
//};
#define TYPE_ID NODE_FLAGS+1
#define INTERNAL_NAME NODE_FLAGS+2
#define C_TYPE NODE_FLAGS+3
#define SIZEOF_TYPE_DEF C_TYPE+1
#define SIZEOF_SIMPLE_TYPE SIZEOF_TYPE_DEF
#define SIZEOF_LABEL_TYPE SIZEOF_TYPE_DEF
#define SIZEOF_ANY_TYPE SIZEOF_TYPE_DEF
#define SIZEOF_STRING_TYPE SIZEOF_TYPE_DEF
#define SIZEOF_ERROR_TYPE SIZEOF_TYPE_DEF
char *get_decl_ident (treenode *t) {
return (char *)(t [DECL_IDENT]. f);
}
void set_decl_ident (treenode *t, char *s) {
t [DECL_IDENT]. f = (treenode *)s;
}
treenode *get_decl_env (treenode *t) {
return t [DECL_ENV]. f;
}
void set_decl_env (treenode *t, treenode *e) {
t [DECL_ENV]. f = e;
}
treenode *get_next_dec (treenode *t) {
return t [NEXT_DEC]. f;
}
void set_next_dec (treenode *t, treenode *n) {
t [NEXT_DEC]. f = n;
}
char *get_c_name (treenode *t) {
return (char *)(t [C_NAME]. f);
}
void set_c_name (treenode *t, char *s) {
t [C_NAME]. f = (treenode *)s;
}
char *get_type_id (treenode *t) {
return (char *)(t [TYPE_ID]. f);
}
void set_type_id (treenode *t, char *id) {
t [TYPE_ID]. f = (treenode *)id;
}
char *get_internal_name (treenode *t) {
return (char *)(t [INTERNAL_NAME]. f);
}
void set_internal_name (treenode *t, char *in) {
t [INTERNAL_NAME]. f = (treenode *)in;
}
char *get_c_type (treenode *t) {
return (char *)(t [C_TYPE]. f);
}
void set_c_type (treenode *t, char *ct) {
t [C_TYPE]. f = (treenode *)ct;
}
//class array_type: public type_def {
//public:
// treenode *element_type;
//};
#define ELEMENT_TYPE C_TYPE+1
#define SIZEOF_ARRAY_TYPE ELEMENT_TYPE+1
treenode *get_element_type (treenode *t) {
return t [ELEMENT_TYPE]. f;
}
void set_element_type (treenode *t, treenode *et) {
t [ELEMENT_TYPE]. f = et;
}
//class proc_type: public type_def {
//public:
// treenode *proctype_returntype;
//};
#define PROCTYPE_RETURNTYPE C_TYPE+1
#define SIZEOF_PROC_TYPE PROCTYPE_RETURNTYPE+1
treenode *get_proctype_returntype (treenode *t) {
return t [PROCTYPE_RETURNTYPE]. f;
}
void set_proctype_returntype (treenode *t, treenode *rt) {
t [PROCTYPE_RETURNTYPE]. f = rt;
}
//class bin_param: public treenode {
//public:
// treenode *left_operand_for_bin;
// treenode *right_operand_for_bin;
// treenode *return_type_for_bin;
// char * c_string_for_bin;
//};
#define LEFT_OPERAND_FOR_BIN NODE_FLAGS+1
#define RIGHT_OPERAND_FOR_BIN NODE_FLAGS+2
#define RETURN_TYPE_FOR_BIN NODE_FLAGS+3
#define C_STRING_FOR_BIN NODE_FLAGS+4
#define SIZEOF_BINPARAM C_STRING_FOR_BIN+1
treenode *get_left_operand_for_bin (treenode *t) {
return t [LEFT_OPERAND_FOR_BIN]. f;
}
void set_left_operand_for_bin (treenode *t, treenode *lo) {
t [LEFT_OPERAND_FOR_BIN]. f = lo;
}
treenode *get_right_operand_for_bin (treenode *t) {
return t [RIGHT_OPERAND_FOR_BIN]. f;
}
void set_right_operand_for_bin (treenode *t, treenode *ro) {
t [RIGHT_OPERAND_FOR_BIN]. f = ro;
}
treenode *get_return_type_for_bin (treenode *t) {
return t [RETURN_TYPE_FOR_BIN]. f;
}
void set_return_type_for_bin (treenode *t, treenode *rt) {
t [RETURN_TYPE_FOR_BIN]. f = rt;
}
char *get_c_string_for_bin (treenode *t) {
return (char *)(t [C_STRING_FOR_BIN]. f);
}
void set_c_string_for_bin (treenode *t, char *cs) {
t [C_STRING_FOR_BIN]. f = (treenode *)cs;
}
//class binop: public treenode {
//public:
// char *opsym_for_bin;
// int binary_prio;
// treenode *binary_params;
//};
#define OPSYM_FOR_BIN NODE_FLAGS+1
#define BINARY_PRIO NODE_FLAGS+2
#define BINARY_PARAMS NODE_FLAGS+3
#define SIZEOF_BINOP BINARY_PARAMS+1
char *get_opsym_for_bin (treenode *t) {
return (char *)(t [OPSYM_FOR_BIN]. f);
}
void set_opsym_for_bin (treenode *t, char *op) {
t [OPSYM_FOR_BIN]. f = (treenode *)op;
}
int get_binary_prio (treenode *t) {
return (int)(t [BINARY_PRIO]. f);
}
void set_binary_prio (treenode *t, int prio) {
t [BINARY_PRIO]. f = (treenode *)prio;
}
treenode *get_binary_params (treenode *t) {
return t [BINARY_PARAMS]. f;
}
void set_binary_params (treenode *t, treenode *par) {
t [BINARY_PARAMS]. f = par;
}
//class un_param: public treenode {
//public:
// treenode *left_for_un;
// treenode *return_type_for_un;
// char *c_string_for_un;
//};
#define LEFT_FOR_UN NODE_FLAGS+1
#define RETURN_TYPE_FOR_UN NODE_FLAGS+2
#define C_STRING_FOR_UN NODE_FLAGS+3
#define SIZEOF_UNPARAM C_STRING_FOR_UN+1
treenode *get_left_for_un (treenode *t) {
return t [LEFT_FOR_UN]. f;
}
treenode set_left_for_un (treenode *t, treenode *left) {
t [LEFT_FOR_UN]. f = left;
}
treenode *get_return_type_for_un (treenode *t) {
return t [RETURN_TYPE_FOR_UN]. f;
}
void set_return_type_for_un (treenode *t, treenode *rt) {
t [RETURN_TYPE_FOR_UN]. f = rt;
}
char *get_c_string_for_un (treenode *t) {
return (char *)(t [C_STRING_FOR_UN]. f);
}
void set_c_string_for_un (treenode *t, char *cs) {
t [C_STRING_FOR_UN]. f = (treenode *)cs;
}
//class unop: public treenode {
//public:
// char *opsym_for_un;
// int unary_prio;
// treenode *unary_params;
//};
#define OPSYM_FOR_UN NODE_FLAGS+1
#define UNARY_PRIO NODE_FLAGS+2
#define UNARY_PARAMS NODE_FLAGS+3
#define SIZEOF_UNOP UNARY_PARAMS+1
char *get_opsym_for_un (treenode *t) {
return (char *)(t [OPSYM_FOR_UN]. f);
}
void set_opsym_for_un (treenode *t, char *op) {
t [OPSYM_FOR_UN]. f = (treenode *)op;
}
int get_unary_prio (treenode *t) {
return (int)(t [UNARY_PRIO]. f);
}
void set_unary_prio (treenode *t, int prio) {
t [UNARY_PRIO]. f = (treenode *)prio;
}
treenode *get_unary_params (treenode *t) {
return t [UNARY_PARAMS]. f;
}
void set_unary_params (treenode *t, treenode *un) {
t [UNARY_PARAMS]. f = un;
}
//class statement : public treenode {
//public:
// treenode *label;
//};
#define LABEL NODE_FLAGS+1
#define SIZEOF_STATEMENT LABEL+1
treenode *get_label (treenode *t) {
return t [LABEL]. f;
}
void set_label (treenode *t, treenode *lab) {
t [LABEL]. f = lab;
}
//class env: public statement {
//public:
// treenode *surr;
// treenode *statements;
// treenode *last_statement;
//};
#define SURR LABEL+1
#define STATEMENTS LABEL+2
#define LAST_STATEMENT LABEL+3
#define SIZEOF_ENV LAST_STATEMENT+1
treenode *get_surrounding (treenode *t) {
return t [SURR]. f;
}
void set_surrounding (treenode *t, treenode *sur) {
t [SURR]. f = sur;
}
treenode *get_statements (treenode *t) {
return t [STATEMENTS]. f;
}
void set_statements (treenode *t, treenode *st) {
t [STATEMENTS]. f = st;
}
treenode *get_last_statement (treenode *t) {
return t [LAST_STATEMENT]. f;
}
void set_last_statement (treenode *t, treenode *lt) {
t [LAST_STATEMENT]. f = lt;
}
//class for_element: public treenode {
//public:;
//};
//class expression: public treenode {
//public:
// treenode *expr_type;
//};
#define EXPR_TYPE NODE_FLAGS+1
#define SIZEOF_EXPRESSION EXPR_TYPE+1
treenode *get_expr_type (treenode *t) {
return t [EXPR_TYPE]. f;
}
void set_expr_type (treenode *t, treenode *typ) {
t [EXPR_TYPE]. f = typ;
}
//class bounds: public expression {
//public:
// treenode *first_bound;
// treenode *second_bound;
//};
#define FIRST_BOUND EXPR_TYPE+1
#define SECOND_BOUND EXPR_TYPE+2
#define SIZEOF_BOUNDS SECOND_BOUND+1
treenode *get_first_bound (treenode *t) {
return t [FIRST_BOUND]. f;
}
treenode *get_second_bound (treenode *t) {
return t [SECOND_BOUND]. f;
}
void set_first_bound (treenode *t, treenode *fb) {
t [FIRST_BOUND]. f = fb;
}
void set_second_bound (treenode *t, treenode *sb) {
t [SECOND_BOUND]. f = sb;
}
//class if_stat: public statement {
//public:
// treenode *ifcondition;
// treenode *ifthenpart;
// treenode *ifelsepart;
//};
#define IFCONDITION LABEL+1
#define IFTHENPART LABEL+2
#define IFELSEPART LABEL+3
#define SIZEOF_IF_STAT IFELSEPART+1
treenode *get_ifcondition (treenode *t) {
return t [IFCONDITION]. f;
}
treenode *get_ifthenpart (treenode *t) {
return t [IFTHENPART]. f;
}
treenode *get_ifelsepart (treenode *t) {
return t [IFELSEPART]. f;
}
void set_ifcondition (treenode *t, treenode *ifc) {
t [IFCONDITION]. f = ifc;
}
void set_ifthenpart (treenode *t, treenode *ift) {
t [IFTHENPART]. f = ift;
}
void set_ifelsepart (treenode *t, treenode *ife){
t [IFELSEPART]. f = ife;
}
//class assignment: public statement {
//public:
// treenode *lhs_expression;
// treenode *rhs_expression;
//};
#define LHS_EXPRESSION LABEL+1
#define RHS_EXPRESSION LABEL+2
#define SIZEOF_ASSIGNMENT RHS_EXPRESSION+1
treenode *get_lhs_expression (treenode *t) {
return t [LHS_EXPRESSION]. f;
}
void set_lhs_expression (treenode *t, treenode *lhs) {
t [LHS_EXPRESSION]. f = lhs;
}
treenode *get_rhs_expression (treenode *t) {
return t [RHS_EXPRESSION]. f;
}
void set_rhs_expression (treenode *t, treenode *rhs) {
t [RHS_EXPRESSION]. f = rhs;
}
//class goto_stat: public statement {
//public:
// treenode *goto_target;
//};
#define GOTO_TARGET LABEL+1
#define SIZEOF_GOTO_STAT GOTO_TARGET+1
treenode *get_target (treenode *t) {
return t [GOTO_TARGET]. f;
}
void set_target (treenode *t, treenode *targ) {
t [GOTO_TARGET]. f = targ;
}
//class null_statement : public statement {
//public:
//};
#define SIZEOF_NULL_STAT SIZEOF_STATEMENT
//class for_stat: public statement {
//public:
//;
//};
#define SIZEOF_FOR_STAT LABEL+1
//class binary_expression: public expression {
//public:
// treenode *bin_operator;
// treenode *binary_left_operand, *binary_right_operand;
// treenode *bin_opdef;
//};
//
#define BIN_OPERATOR EXPR_TYPE+1
#define BINARY_LEFT_OPERAND EXPR_TYPE+2
#define BINARY_RIGHT_OPERAND EXPR_TYPE+3
#define BIN_OPDEF EXPR_TYPE+4
#define SIZEOF_BINARY_EXPRESSION BIN_OPDEF+1
treenode *get_bin_operator (treenode *t) {
return t [BIN_OPERATOR]. f;
}
void set_bin_operator (treenode *t, treenode *binop) {
t [BIN_OPERATOR]. f = binop;
}
treenode *get_binary_left_operand (treenode *t) {
return t [BINARY_LEFT_OPERAND]. f;
}
void set_binary_left_operand (treenode *t, treenode *lo) {
t [BINARY_LEFT_OPERAND]. f = lo;
}
treenode *get_binary_right_operand (treenode *t) {
return t [BINARY_RIGHT_OPERAND]. f;
}
void set_binary_right_operand (treenode *t, treenode *ro) {
t [BINARY_RIGHT_OPERAND]. f = ro;
}
treenode *get_bin_opdef (treenode *t) {
return t [BIN_OPDEF]. f;
}
void set_bin_opdef (treenode *t, treenode *opdef) {
t [BIN_OPDEF]. f = opdef;
}
//class unary_expression: public expression {
//public:
// treenode *un_operator;
// treenode *un_opdef;
// treenode *unary_operand;
//};
#define UN_OPERATOR EXPR_TYPE+1
#define UN_OPDEF EXPR_TYPE+2
#define UNARY_OPERAND EXPR_TYPE+3
#define SIZEOF_UNARY_EXPRESSION UNARY_OPERAND+1
treenode *get_un_operator (treenode *t) {
return t [UN_OPERATOR]. f;
}
void set_un_operator (treenode *t, treenode *unop) {
t [UN_OPERATOR]. f = unop;
}
treenode *get_unary_operand (treenode *t) {
return t [UNARY_OPERAND]. f;
}
void set_unary_operand (treenode *t, treenode *uo) {
t [UNARY_OPERAND]. f = uo;
}
treenode *get_un_opdef (treenode *t) {
return t [UN_OPDEF]. f;
}
void set_un_opdef (treenode *t, treenode *un) {
t [UN_OPDEF]. f = un;
}
//class inumber: public expression {
//public:
// char *i_value;
//};
//class fnumber: public expression {
//public:
// char *f_value;
//};
//
//class bnumber : public expression {
//public:
// char *b_value;
//};
//
//class string_constant : public expression {
//public:
// char *s_value;
//};
#define X_VALUE EXPR_TYPE+1
#define SIZEOF_NUMBER X_VALUE+1
char *get_x_value (treenode *t) {
return (char *)(t [X_VALUE]. f);
}
void set_x_value (treenode *t, char *s) {
t [X_VALUE]. f = (treenode *)s;
}
//class id_as_prim: public expression {
//public:
// char *resolve_ident;
// treenode *id_def;
//};
#define RESOLVE_IDENT EXPR_TYPE+1
#define ID_DEF RESOLVE_IDENT+1
#define SIZEOF_ID_AS_PRIM ID_DEF+1
char *get_resolve_ident (treenode *t) {
return (char *)(t [RESOLVE_IDENT]. f);
}
void set_resolve_ident (treenode *t, char *id) {
t [RESOLVE_IDENT]. f = (treenode *)id;
}
treenode *get_id_def (treenode *t) {
return t [ID_DEF]. f;
}
void set_id_def (treenode *t, treenode *def) {
t [ID_DEF]. f = def;
}
//class act_par: public expression {
//public:
// treenode *act_exp;
//};
#define ACT_EXP EXPR_TYPE+1
#define SIZEOF_ACT_PAR ACT_EXP+1
treenode *get_act_exp (treenode *t) {
return t [ACT_EXP]. f;
}
void set_act_exp (treenode *t, treenode *exp) {
t [ACT_EXP]. f = exp;
}
//class function_call: public expression {
//public:
// char *function_ident;
// treenode *called_function;
// treenode *actuals;
// int num_of_actuals;
//};
#define FUNCTION_IDENT EXPR_TYPE+1
#define CALLED_FUNCTION FUNCTION_IDENT+1
#define ACTUALS CALLED_FUNCTION+1
#define NUM_OF_ACTUALS ACTUALS+1
#define SIZEOF_FUNCTION_CALL NUM_OF_ACTUALS+1
char *get_function_ident (treenode *t) {
return (char *)(t [FUNCTION_IDENT]. f);
}
void set_function_ident (treenode *t, char *id) {
t [FUNCTION_IDENT]. f = (treenode *)id;
}
treenode *get_called_function (treenode *t) {
return t [CALLED_FUNCTION]. f;
}
void set_called_function (treenode *t, treenode *f) {
t [CALLED_FUNCTION]. f = f;
}
treenode *get_actuals (treenode *t) {
return t [ACTUALS]. f;
}
void set_actuals (treenode *t, treenode *a) {
t [ACTUALS]. f = a;
}
int get_num_of_actuals (treenode *t) {
return (int)(t [NUM_OF_ACTUALS]. f);
}
void set_num_of_actuals (treenode *t, int n) {
t [NUM_OF_ACTUALS]. f = (treenode *)n;
}
//class indexing: public expression {
//public:
// char *array_ident;
// treenode *array_def;
// treenode *subscripts;
// int num_of_subscripts;
//};
#define ARRAY_IDENT EXPR_TYPE+1
#define ARRAY_DEF ARRAY_IDENT+1
#define SUBSCRIPTS ARRAY_DEF+1
#define NUM_OF_SUBSCRIPTS SUBSCRIPTS+1
#define SIZEOF_INDEXING NUM_OF_SUBSCRIPTS+1
char *get_array_ident (treenode *t) {
return (char *)(t [ARRAY_IDENT]. f);
}
void set_array_ident (treenode *t, char *id) {
t [ARRAY_IDENT]. f = (treenode *)id;
}
treenode *get_array_def (treenode *t) {
return t [ARRAY_DEF]. f;
}
void set_array_def (treenode *t, treenode *def) {
t [ARRAY_DEF]. f = def;
}
treenode *get_subscripts (treenode *t) {
return t [SUBSCRIPTS]. f;
}
void set_subscripts (treenode *t, treenode *subs) {
t [SUBSCRIPTS]. f = subs;
}
int get_num_of_subscripts (treenode *t) {
return (int)(t [NUM_OF_SUBSCRIPTS]. f);
}
void set_num_of_subscripts (treenode *t, int num) {
t [NUM_OF_SUBSCRIPTS]. f = (treenode *)num;
}
//class conditional: public expression {
//public:
// treenode *cond_of_condition;
// treenode *condition_thenpart;
// treenode *condition_elsepart;
//};
#define COND_OF_CONDITION EXPR_TYPE+1
#define CONDITION_THENPART COND_OF_CONDITION+1
#define CONDITION_ELSEPART COND_OF_CONDITION+2
#define SIZEOF_CONDITIONAL CONDITION_ELSEPART+1
treenode *get_cond_of_condition (treenode *t) {
return t [COND_OF_CONDITION]. f;
}
void set_cond_of_condition (treenode *t, treenode *c) {
t [COND_OF_CONDITION]. f = c;
}
treenode *get_condition_thenpart (treenode *t) {
return t [CONDITION_THENPART]. f;
}
void set_condition_thenpart (treenode *t, treenode *tp) {
t [CONDITION_THENPART]. f = tp;
}
treenode *get_condition_elsepart (treenode *t) {
return t [CONDITION_ELSEPART]. f;
}
void set_condition_elsepart (treenode *t, treenode *ep) {
t [CONDITION_ELSEPART]. f = ep;
}
//class thunk: public declaration {
//public:
// treenode *type_of_thunk;
// treenode *thunk_expr;
//};
#define TYPE_OF_THUNK C_NAME+1
#define THUNK_EXPR C_NAME+2
#define SIZEOF_THUNK THUNK_EXPR+1
treenode *get_type_of_thunk (treenode *t) {
return t [TYPE_OF_THUNK]. f;
}
void set_type_of_thunk (treenode *t, treenode *typ) {
t [TYPE_OF_THUNK]. f = typ;
}
treenode *get_thunk_expr (treenode *t) {
return t [THUNK_EXPR]. f;
}
void set_thunk_expr (treenode *t, treenode *te) {
t [THUNK_EXPR] .f = te;
}
//class variable: public declaration {
//public:
// treenode *type_of_var;
//};
#define TYPE_OF_VAR C_NAME+1
#define SIZEOF_VARIABLE TYPE_OF_VAR+1
treenode *get_type_of_var (treenode *t) {
return t [TYPE_OF_VAR]. f;
}
void set_type_of_var (treenode *t, treenode *tt) {
t [TYPE_OF_VAR]. f = tt;
}
//class label_decl: public declaration {
//public:
// treenode *value_of_label;
//};
#define VALUE_OF_LABEL C_NAME+1
#define SIZEOF_LABEL_DECL VALUE_OF_LABEL+1
treenode *get_value_of_label (treenode *t) {
return t [VALUE_OF_LABEL]. f;
}
void set_value_of_label (treenode *t, treenode *v) {
t [VALUE_OF_LABEL]. f = v;
}
//class param_decl: public declaration {
//public:
// treenode *param_type;
//};
#define PARAM_TYPE C_NAME+1
#define SIZEOF_PARAM_DECL PARAM_TYPE+1
treenode *get_param_type (treenode *t) {
return t [PARAM_TYPE]. f;