forked from farisawan-2000/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_walk.c
1308 lines (1068 loc) · 35 KB
/
tree_walk.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
/*ident "@(#)cls4:src/tree_walk.c 1.14" */
/*******************************************************************************
C++ source for the C++ Language System, Release 3.0. This product
is a new release of the original cfront developed in the computer
science research center of AT&T Bell Laboratories.
Copyright (c) 1993 UNIX System Laboratories, Inc.
Copyright (c) 1991, 1992 AT&T and UNIX System Laboratories, Inc.
Copyright (c) 1984, 1989, 1990 AT&T. All Rights Reserved.
THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE of AT&T and UNIX System
Laboratories, Inc. The copyright notice above does not evidence
any actual or intended publication of such source code.
*******************************************************************************/
/******************************************************************************
* Copyright (c) 1989 by Object Design, Inc., Burlington, Mass.
* All rights reserved.
*******************************************************************************/
/*
tree_walk.c
Utilities for tree-walking
*/
#include "cfront.h"
#include "tree_walk.h"
#include "hash.h"
/*
// #include <alloca.h>
// ************ need to add an explicit call of free
// ************ make it an ifdef
// ??? #include <streamdefs.h>
*/
class walker {
tree_walk_control control;
Pnode orig_addr;
Hash *nodes_seen_hash;
int depth;
int made_ht;
tree_walk_tree *cur_tree;
public:
walker(const tree_walk_control &c);
~walker() {
if (made_ht)
delete nodes_seen_hash;
}
tree_node_action walk(Pnode &);
tree_node_action walk_(Pnode &);
tree_node_action walk(Pgen &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pvec &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pptr &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Ptype &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pfct &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Ptable &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pktab &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pbase &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pname &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pexpr &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pstmt &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pblock &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Penum &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pclass &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pvirt &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Plist &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pin &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pia &n) {
return walk_((struct node *&) n);
};
tree_node_action walk(Pbcl &n) {
return walk_((struct node *&) n);
};
private:
int fetching() {
return (control.fetcher != null_tfp);
};
void free_fetched(void *);
int fetch(void *, unsigned long, void *&);
int fetch(void *a, unsigned long l, Pnode &p) {
int ret;
void *t; /* this is an output argument */
ret = fetch(a, l, t);
if (!ret) {
p = Pnode(t);
}
return ret;
};
void error(char *, unsigned long = 0);
tree_node_action pre_act_on_node(Pnode node, node_class nc, Pnode node_copy, Pnode &replacement);
tree_node_action a_gen(Pnode, Pgen, Pnode &);
tree_node_action a_tpdef(Pnode, Ptype, Pnode &);
tree_node_action a_vec(Pnode, Pvec, Pnode &);
tree_node_action a_ptr(Pnode, Pptr, Pnode &);
tree_node_action a_fct(Pnode, Pfct, Pnode &);
tree_node_action a_table(Pnode, Ptable, Pnode &);
tree_node_action a_ktable(Pnode, Pktab, Pnode &);
tree_node_action a_basetype(Pnode, Pbase, Pnode &);
tree_node_action a_name(Pnode, Pname, Pnode &);
tree_node_action a_expr(Pnode, Pexpr, Pnode &);
tree_node_action a_stmt(Pnode, Pstmt, Pnode &);
tree_node_action a_enumdef(Pnode, Penum, Pnode &);
tree_node_action a_classdef(Pnode, Pclass, Pnode &);
tree_node_action a_virt(Pnode, Pvirt, Pnode &);
tree_node_action a_name_list(Pnode, Plist, Pnode &);
tree_node_action a_iline(Pnode, Pin, Pnode &);
tree_node_action a_ia(Pnode, struct ia *, Pnode &);
tree_node_action a_baseclass(Pnode, Pbcl, Pnode &);
tree_node_action a_expr_guts(Pexpr);
};
tree_node_action walker::walk_(Pnode &n) {
if (n) {
int save_depth = depth;
tree_walk_tree *save_cur_tree = cur_tree;
depth++;
if (control.alloc_stack_bytes) {
cur_tree = (tree_walk_tree *)
// alloca (control.alloc_stack_bytes + sizeof (tree_walk_tree));
new char[control.alloc_stack_bytes + sizeof(tree_walk_tree)];
cur_tree->parent = save_cur_tree;
}
tree_node_action r = walk(n);
depth = save_depth;
return r;
} else
return tna_continue;
}
walker::walker(const tree_walk_control &c) {
control = c;
made_ht = 0;
if (c.nodes_seen_hash)
nodes_seen_hash = c.nodes_seen_hash;
else {
nodes_seen_hash = new pointer_hash(100);
made_ht = 1;
}
depth = 0;
cur_tree = 0;
}
Ppatch_tree patch_tree::head = 0;
Hash *patch_tree::ht = 0;
Pnode patch_tree::probe(Pnode n) {
int found = 0, replacement = 0;
ht->action((int) n, 0, Hash::probe, found, replacement);
return found ? (Pnode) replacement : n;
}
void patch_tree::patch_a_ktable(Pktab tbl) {
tbl->k_next = (Pktab) patch_tree::probe(tbl->k_next);
}
void patch_tree::patch_a_table(Ptable tbl) {
for (int i = 0; i < tbl->size; i++) {
if (tbl->entries[i]) {
tbl->entries[i] = (Pname) patch_tree::probe(tbl->entries[i]);
}
}
tbl->next = (Ptable) patch_tree::probe(tbl->next);
}
void patch_tree::patch_a_name(Pname n) {
n->n_ktable = (Pktab) patch_tree::probe(n->n_ktable);
}
void patch_tree::patch() {
while (head) {
if (head->node->base == KTABLE) {
patch_a_ktable(Pktab(head->node));
} else if (head->node->base == TABLE) {
patch_a_table(Ptable(head->node));
} else {
patch_a_name(Pname(head->node));
}
Ppatch_tree p = head->next;
delete head;
head = p;
}
}
tree_node_action walk_tree(tree_walk_control &c, Pnode &n) {
walker w(c);
patch_tree::init(c.nodes_seen_hash);
tree_node_action action = w.walk(n);
patch_tree::patch();
return action;
}
/* error messages are of finite length, so no need to run
around mallocing strings */
void walker::error(char *format, unsigned long v) {
if (control.call_i_error) {
char buf[1000];
// vsprintf(buf, format, args);
// vsprintf not universal: by inspection
// all calls are currently of 1 or 0 arguments
sprintf(buf, format, v);
(*control.i_error)('i', buf);
}
}
void walker::free_fetched(void *addr) {
if (control.fetcher != null_tfp) /* null indicates no cross-address-space */
delete addr;
}
int walker::fetch(void *addr, unsigned long length, void *&taddr) {
int err;
if (control.fetcher == null_tfp) {
taddr = addr;
return 0;
} else {
taddr = (void *) new char[length];
if (taddr == 0) {
error("walker::fetch: failed to malloc %d bytes.", length);
return 1;
}
err = (*control.fetcher)(control.callback_info, addr, length, 0, taddr);
if (err) {
error("walker::fetch: fetcher returned %d.", err);
return 1;
}
}
::error('i', "fall off end of walker::fetch()");
return 0;
}
/* ::walk is called with a node pointer and a reference to
a replacement node pointer. When it returns,
replacement will be set if the action procedure
called on the node decided to copy it or replace it.
There are two possible modularities.
In case there is cross-address-space action,
::walk can't call the action procedure until it has
entered the case on node bases. Once it has,
it calls the per-structure-type procedure,
which calls the action proc. If the action
proc supplies a replacement, then that replacement
will be returned up via the reference parameters to
the per-structure procedures.
It the action procedure returns tna_continue,
then the walk continues against the new copy of the node
so that further replacements are reflected in the new copies.
This prevents replacement from being meaningful cross-address-space,
since the new copy will presumably be in the current
(and not the cross) address space. That is, if the node
is replaced by the action proc, the pointers in the new
node will drive the subsequent tree walk. Usually one
would just bitcopy, and then they would be replaced in turn.
*/
tree_node_action walker::walk(Pnode &top) {
Pnode replacement = 0;
tree_node_action err;
int class_err;
node_class nclass;
Pnode node = 0; /* assign to shut up compiler,
which dosen't recognize pass-by-reference as a set */
orig_addr = top;
if (fetching()) {
if (fetch((void *) top, sizeof(struct node), node))
return tna_error;
} else
node = top;
/* This has a complete catalog of bases, rather than just a list
of those associated with data structures. Its important
to detect the errs.
*/
nclass = classify_node(node, class_err);
if (class_err) {
error("walker::walk: unknown node type %d.", node->base);
free_fetched((void *) node);
err = tna_error;
goto Return;
}
switch (nclass) {
default:
case nc_unused:
error("walker::walk: unused node type %d.", node->base);
err = tna_error;
goto Return;
case nc_eof:
break;
case nc_virt:
fetch((void *) top, sizeof(struct virt), node);
err = a_virt(top, Pvirt(node), replacement);
break;
case nc_nlist:
fetch((void *) top, sizeof(struct name_list), node);
err = a_name_list(top, (struct name_list *) node, replacement);
break;
case nc_iline:
fetch((void *) top, sizeof(struct iline), node);
err = a_iline(top, (struct iline *) node, replacement);
break;
case nc_gen:
fetch((void *) top, sizeof(struct gen), node);
err = a_gen(top, Pgen(node), replacement);
break;
case nc_tpdef:
fetch((void *) top, sizeof(struct type), node);
err = a_tpdef(top, Ptype(node), replacement);
break;
case nc_vec:
fetch((void *) top, sizeof(struct vec), node);
err = a_vec(top, Pvec(node), replacement);
break;
case nc_ptr:
fetch((void *) top, sizeof(struct ptr), node);
err = a_ptr(top, Pptr(node), replacement);
break;
case nc_fct:
fetch((void *) top, sizeof(struct fct), node);
err = a_fct(top, Pfct(node), replacement);
break;
case nc_table:
fetch((void *) top, sizeof(struct table), node);
err = a_table(top, Ptable(node), replacement);
break;
case nc_ktable:
fetch((void *) top, sizeof(struct ktable), node);
err = a_ktable(top, Pktab(node), replacement);
break;
case nc_basetype:
fetch((void *) top, sizeof(struct basetype), node);
err = a_basetype(top, Pbase(node), replacement);
break;
case nc_name:
fetch((void *) top, sizeof(struct name), node);
err = a_name(top, Pname(node), replacement);
break;
case nc_expr:
fetch((void *) top, sizeof(struct expr), node);
err = a_expr(top, Pexpr(node), replacement);
break;
case nc_stmt:
fetch((void *) top, sizeof(struct stmt), node);
err = a_stmt(top, Pstmt(node), replacement);
break;
case nc_enumdef:
fetch((void *) top, sizeof(struct enumdef), node);
err = a_enumdef(top, Penum(node), replacement);
break;
case nc_classdef:
fetch((void *) top, sizeof(struct classdef), node);
err = a_classdef(top, Pclass(node), replacement);
break;
case nc_ia:
fetch((void *) top, sizeof(struct ia), node);
err = a_ia(top, (struct ia *) node, replacement);
break;
case nc_baseclass:
fetch((void *) top, sizeof(struct basecl), node);
err = a_baseclass(top, Pbcl(node), replacement);
break;
}
if (replacement) {
if (fetching()) {
error("walker::walk: Attempt to replace tree in cross-address space mode.");
err = tna_error;
} else
top = replacement;
}
if (control.post_action_proc && err != tna_error) {
tree_node_action post_err;
Pnode &post_repl = node;
(*control.post_action_proc)(post_repl, nclass, control.callback_info, post_err, depth,
orig_addr, *cur_tree);
if (post_err != tna_continue)
err = post_err;
if (post_repl != node) {
if (fetching()) {
error("walker::walk: Attempt to replace tree in cross-address space mode.");
err = tna_error;
} else
top = post_repl;
}
}
free_fetched((void *) node);
Return:
return err;
}
/* This is called in pre-order for each node. Then
post_act_on_node is called after whatever recursive
processing ensues.
This is called from each of the structure-specific procedures
to give the action procedure an opportunity to act.
It can return a replacement pointer and control
whether to examine the insides of the node.
*/
tree_node_action walker::pre_act_on_node(Pnode node, node_class nc, Pnode node_copy,
Pnode &replacement) {
/* If we have been here before, then we never proceed */
/* node_copy is != node when a fetcher is in use */
int found;
int old_node;
tree_node_action action;
Pnode new_node;
int register_in_hash = 1;
nodes_seen_hash->action((int) node, 0, Hash::probe, found, old_node);
if (found) {
new_node = Pnode(old_node);
if (new_node != node)
replacement = new_node;
return tna_stop; /* no need to proceed */
}
/* OK, we don't know from a previous pass. Call our actor */
new_node = fetching() && node_copy ? node_copy : node;
(*control.action_proc)(new_node, nc, control.callback_info, action, depth, orig_addr, *cur_tree,
register_in_hash);
int zero1 = 0, zero2 = 0;
if (action != tna_error && !fetching() && new_node != node) {
replacement = new_node;
if (register_in_hash)
nodes_seen_hash->action((int) node, (int) new_node, Hash::insert, zero1, zero2);
} else {
if (register_in_hash)
nodes_seen_hash->action((int) node, (int) node, Hash::insert, zero1, zero2);
}
return action;
}
tree_node_action walker::a_ktable(Pnode ta, Pktab t, Pnode &replacement) {
tree_node_action action;
action = pre_act_on_node(ta, nc_ktable, Pnode(t), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
t = Pktab(replacement);
action = walk(t->k_t);
if (action == tna_error)
return action;
action = walk(t->k_name);
if (action == tna_error)
return action;
// k_next is patched up after tree is fully walked
return tna_continue;
}
tree_node_action walker::a_table(Pnode ta, Ptable t, Pnode &replacement) {
/* no unions */
tree_node_action action;
action = pre_act_on_node(ta, nc_table, Pnode(t), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
t = Ptable(replacement);
for (int i = 0; i < t->size; i++) {
if (t->entries[i] && t->entries[i]->base == TNAME) {
action = walk(t->entries[i]);
if (action == tna_error)
return action;
}
}
action = walk(t->real_block);
if (action == tna_error)
return action;
action = walk(t->t_name);
if (action == tna_error)
return action;
// t_next is patched up after tree is fully walked
return tna_continue;
}
tree_node_action walker::a_enumdef(Pnode ta, Penum e, Pnode &replacement) {
tree_node_action action = pre_act_on_node(ta, nc_enumdef, Pnode(e), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
e = Penum(replacement);
action = walk(e->in_class);
if (action == tna_error)
return action;
action = walk(e->mem);
if (action == tna_error)
return action;
action = walk(e->e_type);
return tna_continue;
}
tree_node_action walker::a_virt(Pnode ta, Pvirt v, Pnode &replacement) {
/* no unions */
int nx;
tree_node_action action = pre_act_on_node(ta, nc_enumdef, Pnode(v), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
v = Pvirt(replacement);
/* an array of velem structures. */
velem *v_virt_init;
if (fetching()) {
void *t;
fetch((void *) v->virt_init, v->n_init * sizeof(velem), t);
v_virt_init = (velem *) t;
} else
v_virt_init = v->virt_init;
for (nx = 0; nx < v->n_init; nx++) {
action = walk(v_virt_init[nx].n);
if (action == tna_error)
return action;
}
if (fetching())
free_fetched((void *) v_virt_init);
action = walk(v->vclass);
return tna_continue;
}
tree_node_action walker::a_classdef(Pnode ta, Pclass c, Pnode &replacement) {
// ::error('d',"walker::a_classdef: %t beginning ", c);
tree_node_action action = pre_act_on_node(ta, nc_classdef, Pnode(c), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
c = Pclass(replacement);
action = walk(c->baselist);
if (action == tna_error)
return action;
action = walk(c->mem_list);
if (action == tna_error)
return action;
action = walk(c->memtbl);
if (action == tna_error)
return action;
action = walk(c->k_tbl);
if (action == tna_error)
return action;
action = walk(c->friend_list);
if (action == tna_error)
return action;
action = walk(c->pubdef);
if (action == tna_error)
return action;
// SYM action=walk(c->tn_list);
// SYM if(action == tna_error) return action;
action = walk(c->in_class);
if (action == tna_error)
return action;
action = walk(c->this_type);
if (action == tna_error)
return action;
action = walk(c->virt_list);
if (action == tna_error)
return action;
action = walk(c->c_ctor);
if (action == tna_error)
return action;
action = walk(c->c_dtor);
if (action == tna_error)
return action;
action = walk(c->c_itor);
if (action == tna_error)
return action;
action = walk(c->conv);
if (action == tna_error)
return action;
// ::error('d',"walker::a_classdef: %t ending ", c);
return tna_continue;
}
tree_node_action walker::a_basetype(Pnode ta, Pbase b, Pnode &replacement) {
int derr;
tree_node_action action = pre_act_on_node(ta, nc_basetype, Pnode(b), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
b = Pbase(replacement);
action = walk(b->b_name);
if (action == tna_error)
return action;
action = walk(b->b_table);
if (action == tna_error)
return action;
// action = walk(b->b_field);
// if(action == tna_error) return action;
action = walk(b->b_xname);
if (action == tna_error)
return action;
switch (derr = b->discriminator(0)) {
case 0:
break;
case 1:
action = walk(b->b_fieldtype);
if (action == tna_error)
return action;
break;
case 2:
break;
default:
error("a_basetype: discrim error %d.", derr);
return tna_error;
}
return tna_continue;
}
tree_node_action walker::a_fct(Pnode ta, Pfct f, Pnode &replacement) {
tree_node_action action = pre_act_on_node(ta, nc_fct, Pnode(f), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
f = Pfct(replacement);
action = walk(f->returns);
if (action == tna_error)
return action;
action = walk(f->argtype);
if (action == tna_error)
return action;
action = walk(f->s_returns);
if (action == tna_error)
return action;
action = walk(f->f_this);
if (action == tna_error)
return action;
action = walk(f->memof);
if (action == tna_error)
return action;
action = walk(f->body);
if (action == tna_error)
return action;
action = walk(f->f_init);
if (action == tna_error)
return action;
action = walk(f->f_expr);
if (action == tna_error)
return action;
// action = walk(f->last_expanded);
// if(action == tna_error) return action;
action = walk(f->f_result);
if (action == tna_error)
return action;
action = walk(f->f_args);
if (action == tna_error)
return action;
return tna_continue;
}
tree_node_action walker::a_name_list(Pnode ta, Plist l, Pnode &replacement) {
int cl_error;
tree_node_action action = pre_act_on_node(ta, nc_nlist, Pnode(l), replacement);
if (action == tna_stop) {
if (!fetching() && replacement)
l = Plist(replacement);
cl_error = 0;
if ((classify_node(Pnode(l), cl_error) == nc_nlist) && !cl_error) {
action = walk(l->l);
if (action == tna_error)
return action;
}
}
if (action != tna_continue)
return action;
if (!fetching() && replacement)
l = Plist(replacement);
action = walk(l->f);
if (action == tna_error)
return action;
action = walk(l->l);
if (action == tna_error)
return action;
return tna_continue;
}
tree_node_action walker::a_tpdef(Pnode ta, Ptype t, Pnode &replacement) {
tree_node_action action = pre_act_on_node(ta, nc_tpdef, Pnode(t), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
t = Ptype(replacement);
action = walk(t->in_class);
if (action == tna_error)
return action;
return tna_continue;
}
tree_node_action walker::a_gen(Pnode ta, Pgen g, Pnode &replacement) {
tree_node_action action = pre_act_on_node(ta, nc_gen, Pnode(g), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
g = Pgen(replacement);
action = walk(g->fct_list);
if (action == tna_error)
return action;
return tna_continue;
}
tree_node_action walker::a_vec(Pnode ta, Pvec v, Pnode &replacement) {
tree_node_action action = pre_act_on_node(ta, nc_vec, Pnode(v), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
v = Pvec(replacement);
action = walk(v->typ);
if (action == tna_error)
return action;
action = walk(v->dim);
if (action == tna_error)
return action;
return tna_continue;
}
tree_node_action walker::a_ptr(Pnode ta, Pptr p, Pnode &replacement) {
tree_node_action action = pre_act_on_node(ta, nc_ptr, Pnode(p), replacement);
if (action != tna_continue)
return action;
if (!fetching() && replacement)
p = Pptr(replacement);
action = walk(p->typ);
if (action == tna_error)
return action;
action = walk(p->memof);
if (action == tna_error)
return action;
action = walk(p->ptname);
if (action == tna_error)
return action;
return tna_continue;
}
tree_node_action walker::a_expr_guts(Pexpr e) {
int derr;
tree_node_action action;
switch (derr = e->discriminator(0)) {
case 1:
action = walk(e->tp);
if (action == tna_error)
return action;
break;
case 0:
break;
default:
error("a_expr: discrim error %d on union 0.", derr);
return tna_error;
}
switch (derr = e->discriminator(1)) {
case 0:
break;
default:
error("a_expr: discrim error %d on union 1.", derr);
return tna_error;
case 1:
action = walk(e->e1);
if (action == tna_error)
return action;
break;
case 2:
break;
case 3:
break;
}
switch (derr = e->discriminator(2)) {
case 0:
break;
default:
error("a_expr: discrim error %d on union 2.", derr);
return tna_error;
case 1:
/* elists are special. e2 for an elist is a peer, not
a child. */
if (e->base != ELIST) {
action = walk(e->e2);
if (action == tna_error)
return action;
}
break;
case 2:
break;
case 3:
break;
case 4:
action = walk(e->n_initializer);
if (action == tna_error)
return action;
break;
case 5: // nested typedef
action = walk(e->tpdef);
if (action == tna_error)
return action;
break;
}
switch (derr = e->discriminator(3)) {
case 0:
break;
default:
error("a_expr: discrim error %d on union 3.", derr);
return tna_error;
case 1:
action = walk(e->tp2);
if (action == tna_error)
return action;
break;
case 2:
action = walk(e->fct_name);
if (action == tna_error)
return action;
break;
case 3:
action = walk(e->cond);
if (action == tna_error)
return action;
break;
case 4:
action = walk(e->mem);
if (action == tna_error)
return action;
break;
case 5:
action = walk(e->as_type);