|
|
1.1 root 1: /* ident "@(#)ctrans:src/tree_dump.c 1.2" */
2: /* -*- Mode:C++ -*- */
3: /* tree_dump.C -- utilities for displaying the cfront tree. */
4: /* BIM 890530 */
5: /* rewritten 890712 to use the tree-walking facilities */
6:
7: /*
8: $Source: /usr3/lang/benson/work/stripped_cfront/RCS/tree_dump.c,v $ $RCSfile: tree_dump.c,v $
9: $Revision: 1.1 $ $Date: 89/11/20 08:50:22 $
10: $Author: benson $ $Locker: $
11: $State: Exp $
12:
13:
14: */
15:
16: #include "tree_dump.h"
17: #include <stdio.h>
18: #include <malloc.h>
19: #include "template.h"
20: #include "token_names.h"
21:
22: const int Indent_Increment = 4;
23: static char badnamebuf[100];
24:
25: char *
26: token_name(TOK t)
27: {
28: char * bnb = badnamebuf;
29:
30: if((int) t == -1) return "-1";
31: if(t > DUMMY_LAST_NODE) {
32: bad:
33: printf_to_string(bnb, sizeof(badnamebuf),
34: "<unknown token %d>", (int) t);
35: return bnb;
36: }
37: int x;
38: for (x = 0; x < DUMMY_LAST_NODE; x++) {
39: if(token_names[x].val == t) return token_names[x].string;
40: }
41: goto bad;
42: }
43:
44: class displayer{
45: public:
46: dcn_arg * arg;
47: Pnode node;
48: Pnode node_address;
49: displayer (dcn_arg& d) { arg = &d; indent = 0; print_null_values = 0; };
50: void do_node (Pnode& node, node_class cl, tree_node_action& action, int depth, Pnode);
51: private:
52: enum ppc {print_ptr_copy = 0, print_ptr_copied = 1};
53: int indent;
54: int err;
55: int print_null_values;
56: void printf (const char *, ...);
57: void catprintf (const char *, ...);
58: void print_ptr (const char *, Pnode);
59: void print_ptr (Pnode, ppc = print_ptr_copy);
60: void minimal ();
61: void a_basetype ();
62: void a_basecl() ;
63: void a_type() ;
64: void a_node() ;
65: void a_name ();
66: void a_expr (int from_name = 0);
67: void a_fct ();
68: void a_stmt ();
69: void a_enumdef ();
70: void a_table();
71: void a_classdef ();
72: void a_gen ();
73: void a_vec ();
74: void a_ptr ();
75: void a_virt ();
76: void a_nlist ();
77: void a_iline ();
78: void a_elist ();
79: void a_ia ();
80: void a_by_name ();
81: void print_loc(loc&);
82: void * display_address () { return node_address; }
83: void fetch (void * addr, unsigned long length, void *& taddr);
84: void fetch_string (void * addr, unsigned long length, void *& taddr);
85: void free_fetched(void *);
86: void flag (int, const char *);
87: void print_string (const char *, void *);
88: void print_string_brief (void *);
89: void null_field (const char *);
90: void nz_printf(const char *format, const int i) ;
91: void nz_printf(const char *format, const char *p) ;
92: void nz_printf(const char *format, const long l) ;
93: void ind();
94: };
95:
96: const char many_spaces[] = " ";
97:
98: inline void
99: displayer::ind()
100: {
101: arg->output_stream->write(many_spaces, indent);
102: }
103:
104: /* call me for full lines */
105:
106: void
107: displayer::printf (const char * format, ...)
108: {
109: va_list args;
110: va_start(args, format);
111:
112: ind();
113: vostream_printf (format, args, *arg->output_stream);
114: arg->output_stream->write("\n", 1);
115: va_end (args);
116: }
117:
118: void
119: displayer::catprintf (const char * format, ...)
120: {
121: va_list args;
122: va_start(args, format);
123:
124: vostream_printf (format, args, *arg->output_stream);
125: va_end (args);
126: }
127:
128: void
129: displayer::minimal ()
130: {
131: print_ptr(node, print_ptr_copied);
132: }
133:
134: void
135: displayer::print_ptr(const char * label, Pnode node)
136: {
137: if(node || print_null_values) {
138: ind();
139: catprintf("%s:\t", label);
140: print_ptr(node);
141: catprintf("\n");
142: }
143: }
144:
145:
146: void
147: displayer::print_ptr(Pnode node, ppc copy_ptr)
148: {
149: void * string = 0;
150: void * ncopy;
151: void * na = (void *)node;
152:
153: if(node) {
154:
155: if(copy_ptr == print_ptr_copy) {
156: fetch(na, sizeof(node), ncopy);
157: node = Pnode(ncopy);
158: } else ncopy = node;
159:
160: switch(node->base) {
161: case CLASS:
162: free_fetched(ncopy);
163: fetch(na, sizeof(classdef),ncopy);
164: node = Pnode(ncopy);
165: string = Pclass(node)->string;
166: break;
167: case ENUM:
168: free_fetched(ncopy);
169: fetch(na, sizeof(enumdef),ncopy);
170: node = Pnode(ncopy);
171: string = Penum(node)->string;
172: break;
173: case NAME:
174: case TNAME:
175: case PUBLIC:
176: case PROTECTED:
177: if(!node->baseclass) {
178: free_fetched(ncopy);
179: fetch(na, sizeof(name),ncopy);
180: node = Pnode(ncopy);
181: string = Pname(node)->string;
182: }
183: break;
184: }
185: if(string) {
186: catprintf("<%s |0x%p ", token_name(node->base), na);
187: print_string_brief(string);
188: catprintf(">");
189: }
190: else catprintf("<%s |0x%p>", token_name(node->base), na);
191: free_fetched (ncopy);
192: }
193: else catprintf("Null");
194: }
195:
196: void
197: displayer::do_node (Pnode& n, node_class cl, tree_node_action& action,
198: int depth, Pnode na)
199: {
200: int forced_min = 0;
201: int printed_min = 0;
202: int prune = 0;
203:
204: switch(cl) {
205: case nc_table:
206: if(depth > 0 && !arg->walk_tables)prune = 1;
207: case nc_fct:
208: case nc_classdef:
209: case nc_enumdef:
210: if(arg->stop_at_top && depth > 1) prune = 1;
211: break;
212: }
213:
214: if((arg->max_depth > 0) && (depth >= arg->max_depth))
215: prune = 1;
216:
217: if(prune || arg->max_depth == 0)
218: action = tna_stop;
219: else action = tna_continue;
220:
221: node = n;
222: node_address = na;
223:
224: if(arg->verbose == dt_brief || prune) {
225: printed_min = 1;
226: minimal();
227: }
228: else {
229: switch(cl)
230: {
231: default:
232: case nc_unused:
233: ostream_printf(*arg->error_stream, "Unknown node %d\n", node->base);
234: forced_min = 1;
235:
236: case nc_eof:
237: minimal();
238: printed_min = 1;
239: break;
240:
241: case nc_virt:
242: a_virt ();
243: break;
244:
245: case nc_nlist:
246: a_nlist();
247: break;
248:
249: case nc_gen:
250: a_gen();
251: break;
252:
253: case nc_vec:
254: a_vec();
255: break;
256:
257: case nc_ptr:
258: a_ptr();
259: break;
260:
261: case nc_fct:
262: a_fct();
263: break;
264:
265: case nc_table:
266: a_table();
267: break;
268:
269: case nc_basetype:
270: a_basetype();
271: break;
272:
273: case nc_name:
274: a_name();
275: break;
276:
277: case nc_expr:
278: a_expr();
279: break;
280:
281: case nc_stmt:
282: a_stmt();
283: break;
284:
285: case nc_enumdef:
286: a_enumdef();
287: break;
288:
289: case nc_classdef:
290: a_classdef();
291: break;
292:
293: case nc_baseclass:
294: a_basecl ();
295: break;
296:
297: case nc_iline:
298: a_iline();
299: break;
300:
301: case nc_ia:
302: a_ia();
303: break;
304:
305: }
306: if(printed_min) catprintf(">");
307: }
308: }
309:
310:
311: void
312: displayer::flag(int f, const char * n)
313: {
314: if(f)catprintf("%s", n);
315: }
316:
317: void
318: displayer::free_fetched (void * addr)
319: {
320: if (arg->fetcher != null_tfp) /* not in the same address space. */
321: free ((char *)addr);
322: }
323:
324:
325: void
326: displayer::fetch (void * addr, unsigned long length, void *& taddr)
327: {
328: if (arg->fetcher == null_tfp) { /* in the same address space. */
329: taddr = addr;
330: err = 0;
331: } else {
332: taddr = (void *)malloc ((unsigned int)length);
333: err = arg->fetcher (arg->fetcher_info,
334: addr,
335: length,
336: 0,
337: taddr);
338: }
339: }
340:
341: void
342: displayer::fetch_string (void * addr, unsigned long length, void *& taddr)
343: {
344: if (arg->fetcher == null_tfp) { /* in the same address space. */
345: taddr = addr;
346: err = 0;
347: } else {
348: taddr = (void *)malloc ((unsigned int)length);
349: err = arg->fetcher (arg->fetcher_info,
350: addr,
351: length,
352: 1,
353: taddr);
354: }
355: }
356:
357: /* Print the field, only if it has a non_zero value, or requested to print */
358: /* always */
359: void
360: displayer::nz_printf(const char *format, const int i)
361: {
362: if (i || print_null_values) {
363: printf(format, i) ;
364: }
365: }
366:
367: void
368: displayer::nz_printf(const char *format, const char *p)
369: {
370: if (p || print_null_values) {
371: printf(format, (p ? p : "0")) ;
372: }
373: }
374:
375:
376: void
377: displayer::nz_printf(const char *format, const long i)
378: {
379: if (i || print_null_values) {
380: printf(format, i) ;
381: }
382: }
383:
384: void
385: displayer::a_node()
386: {
387: struct node &n = *node ;
388:
389: nz_printf("$node", n.permanent);
390: // nz_printf("n_key:\t%d", (int)n.n_key) ;
391: nz_printf("permanent:\t%d", n.permanent) ;
392: nz_printf("baseclass:\t%d", n.baseclass) ;
393: }
394:
395:
396:
397: void
398: displayer::a_type()
399: {
400: struct type& t = *Ptype(node);
401: int show_up = t.defined /* || t.inline_temp_index != 0 */;
402:
403: if(show_up) {
404: printf("$type") ;
405: nz_printf("defined:\t%d", t.defined) ;
406: // nz_printf("inline_temp_index:\t%d", t.inline_temp_index);
407: indent += Indent_Increment;
408: }
409: a_node();
410: if(show_up) indent -= Indent_Increment;
411: }
412:
413:
414:
415:
416:
417: void
418: displayer::null_field(const char * name)
419: {
420: nz_printf( "%s:\t0", name);
421: }
422:
423:
424: void
425: displayer::a_basecl()
426: {
427: struct basecl& bc = *Pbcl(node);
428:
429: printf("$basecl %s |0x%p",
430: token_name(node->base),
431: node_address);
432:
433: nz_printf ("ppp:\t%s", token_name(bc.ppp)) ;
434: nz_printf ("allocated:\t%d", bc.allocated) ;
435: nz_printf ("promoted:\t%d", bc.promoted) ;
436: print_ptr("bclass", bc.bclass);
437: nz_printf ("ptr_offset:\t%d", bc.ptr_offset) ;
438: nz_printf ("obj_offset:\t%d", bc.obj_offset) ;
439: indent += Indent_Increment;
440: a_node(); /* do the supertype. */
441: indent -= Indent_Increment;
442: }
443:
444:
445:
446:
447: void
448: displayer::a_basetype ()
449: {
450: struct basetype& bt = *Pbase(node);
451:
452: printf("$basetype %s |0x%p",
453: token_name(node->base),
454: node_address);
455:
456: ind();
457: catprintf("Flags:\t");
458: flag(bt.b_unsigned, "unsigned ");
459: flag(bt.b_signed, "signed ");
460: flag(bt.b_volatile, "volatile ");
461: flag(bt.b_const, "const ");
462: flag(bt.b_typedef, "typedef ");
463: flag(bt.b_virtual, "virtual ");
464: flag(bt.b_short, "short ");
465: flag(bt.b_long, "long ");
466: catprintf("\n");
467: nz_printf( "b_bits:\t%d", bt.b_bits);
468: nz_printf( "b_offset:\t%d", bt.b_offset);
469: nz_printf( "b_sto:\t%s", bt.b_sto ? token_name(bt.b_sto) : 0);
470: switch(bt.discriminator(0)) {
471: case 1:
472: print_ptr("b_fieldtype", bt.b_fieldtype);
473: break;
474: case 2:
475: nz_printf( "b_linkage:\t%s", bt.b_linkage ? "C" : "0(C++)");
476: }
477:
478: print_ptr("b_name", bt.b_name);
479: print_ptr("b_table", bt.b_table);
480: // print_ptr("b_field", bt.b_field);
481: print_ptr("b_xname", bt.b_xname);
482:
483: indent += Indent_Increment;
484: a_type(); /* do the supertype. */
485: indent -= Indent_Increment;
486:
487: }
488:
489: void
490: displayer::print_loc(loc& loc)
491: {
492: catprintf("file %d line %d", (int)loc.file, (int)loc.line);
493: }
494:
495:
496: void
497: displayer::print_string_brief(void * addr)
498: {
499: void * tmp;
500:
501: fetch_string (addr, 1000, tmp);
502: *arg->output_stream << (char *)tmp;
503: free_fetched (tmp);
504: }
505:
506: void
507: displayer::print_string(const char * label, void * addr)
508: {
509: ind();
510: catprintf("%s:\t", label);
511: print_string_brief(addr);
512: *arg->output_stream << "\n";
513: }
514:
515: void
516: displayer::a_expr(int from_name)
517: {
518: struct expr& e = *Pexpr(node);
519:
520: if(from_name) printf("$expr");
521: else printf("$expr %s |0x%p",
522: token_name(node->base),
523: node_address);
524:
525: print_ptr("tp", e.tp);
526:
527: switch(e.discriminator(1)) {
528: case 0: break;
529: case 1:
530: print_ptr("e1", e.e1);
531: break;
532: case 2:
533: printf("i1:\t%ld", e.i1);
534: break;
535: case 3:
536: print_string("string", (void *)e.string);
537: }
538:
539: switch(e.discriminator(2)) {
540: case 0: break;
541: case 1:
542: print_ptr("e2", e.e2);
543: break;
544: case 2:
545: printf("i2:\t%ld", e.i2);
546: break;
547: case 3:
548: print_string("string2", (void *)e.string2);
549: break;
550: case 4:
551: print_ptr("n_initializer", e.n_initializer);
552: }
553:
554: switch(e.discriminator(3)) {
555: case 0:
556: break;
557: case 1: print_ptr ("tp2", e.tp2); break;
558: case 2: print_ptr ("fct_name", e.fct_name); break;
559: case 3: print_ptr ("cond", e.cond); break;
560: case 4: print_ptr ("mem", e.mem); break;
561: case 5: print_ptr ("as_type", e.as_type); break;
562: case 6: print_ptr ("n_table", e.n_table); break;
563: case 7: print_ptr ("il", e.il); break;
564: case 8: print_ptr ("query_this", e.query_this); break;
565: }
566:
567: indent += Indent_Increment;
568: a_node();
569: indent -= Indent_Increment;
570:
571: }
572:
573: void
574: displayer::a_name()
575: {
576: struct name& n = *Pname(node);
577:
578:
579: ind();
580: catprintf("$name %s |0x%p ",
581: token_name(node->base),
582: node_address);
583: print_string_brief((void *)n.string);
584: *arg->output_stream << "\n";
585:
586: nz_printf("n_key:\t%d", (int)n.n_key) ;
587: nz_printf( "n_oper:\t\t%s", n.n_oper ?
588: token_name(n.n_oper) : 0);
589: nz_printf( "n_sto:\t\t%s", n.n_sto ?
590: token_name(n.n_sto) : 0);
591: nz_printf( "n_stclass:\t%s", n.n_stclass ?
592: token_name(n.n_stclass) : 0);
593: nz_printf( "n_scope:\t%s", n.n_scope ?
594: token_name(n.n_scope) : 0);
595: nz_printf( "n_union:\t%d", n.n_union);
596: nz_printf( "n_evaluated:\t%d", n.n_evaluated);
597: nz_printf( "n_xref:\t\t%d", n.n_xref);
598: nz_printf( "lex_level:\t%d", n.lex_level);
599: nz_printf( "n_protect:\t%s", n.n_protect ?
600: token_name(n.n_protect) : 0);
601: if (n.n_dcl_printed || print_null_values) {
602: ind();
603: catprintf("n_dcl_printed:\t%d", n.n_dcl_printed);
604:
605: switch(n.n_dcl_printed)
606: {
607: case 0:
608: catprintf("(not)\n");
609: break;
610: case 1:
611: printf("(declaration)\n");
612: break;
613: case 2:
614: printf("(definition)\n");
615: break;
616: }
617:
618: }
619: if(n.n_template_arg) {
620: ind();
621: catprintf( "n_template_arg:\t");
622: switch(n.n_template_arg)
623: {
624: case template_type_formal:
625: catprintf("template_type_formal\n");
626: break;
627: case template_expr_formal:
628: catprintf("template_expr_formal\n");
629: break;
630: case template_stmt_tree_formal:
631: catprintf("template_stmt_formal\n");
632: break;
633: case template_expr_tree_formal:
634: catprintf("template_expr_tree_formal\n");
635: break;
636: case template_actual_arg_dummy:
637: catprintf("template_actual_arg_dummy\n");
638: break;
639: } ;
640: }
641: nz_printf( "n_addr_taken:\t%d", n.n_addr_taken);
642: nz_printf( "n_used:\t\t%d", n.n_used);
643: nz_printf( "n_assigned_to:\t%d", n.n_assigned_to);
644: ind();
645: catprintf("loc:\t\t");
646: print_loc(n.where);
647: catprintf("\n");
648: nz_printf( "n_offset:\t%d", n.n_offset);
649: // if(n.output_string) { print_string("output_string", (void *)n.output_string); }
650: nz_printf( "n_val:\t\t%ld", n.n_val);
651:
652: print_ptr("n_list", n.n_list);
653: print_ptr("n_tbl_list", n.n_tbl_list);
654: if(n.n_gen_fct_name)
655: print_string("n_gen_fct_name", n.n_gen_fct_name);
656: if(n.n_template_arg_string) {
657: print_string("n_template_arg_string",
658: n.n_template_arg_string);
659: }
660: switch(n.discriminator(0)) {
661: case 2: print_ptr("n_realscope", n.n_realscope); break;
662: case 1: print_ptr("n_qualifier", n.n_qualifier); break;
663: }
664: nz_printf("n_val:\t%ld", n.n_val);
665:
666: indent += Indent_Increment;
667: a_expr(1); /* do the supertype. */
668: indent -= Indent_Increment;
669: }
670:
671: void
672: displayer::a_fct()
673: {
674: struct fct& f = *Pfct(node);
675:
676: printf("$fct %s |0x%p",
677: token_name(node->base),
678: node_address);
679:
680:
681: printf("nargs:\t\t%d", f.nargs);
682: printf("nargs_known:\t%d%s", f.nargs_known,
683: f.nargs_known == 0 ? " UNKNOWN" :
684: (f.nargs_known == 1 ? " KNOWN" :
685: (f.nargs_known == ELLIPSIS ? "ELLIPSIS" : "" )));
686: nz_printf( "f_vdef:\t\t%d", f.f_vdef);
687: printf("f_inline:\t%d%s", f.f_inline,
688: f.f_inline == 0 ? "" :
689: f.f_inline == 1 ? " inline" :
690: f.f_inline == 2 ? " inline in expansion" : "");
691: nz_printf( "f_const:\t\t%d", f.f_const);
692: nz_printf( "f_static:\t\t%d", f.f_static);
693: nz_printf( "f_virtual:\t%d", f.f_virtual);
694: nz_printf( "f_imeasure:\t%d", f.f_imeasure);
695: print_string("f_signature", (void *)f.f_signature);
696:
697: print_ptr("returns", f.returns);
698: print_ptr("argtype", f.argtype);
699: print_ptr("s_returns", f.s_returns);
700: print_ptr("f_this", f.f_this);
701: print_ptr("memof", f.memof);
702: print_ptr("body", f.body);
703: print_ptr("f_init", f.f_init);
704: print_ptr("f_expr", f.f_expr);
705: print_ptr("last_expanded", f.last_expanded);
706: print_ptr("f_result", f.f_result);
707: print_ptr("f_args", f.f_args);
708: print_ptr("local_classes", f.local_class);
709:
710: indent += Indent_Increment;
711: a_type(); /* do the supertype. */
712: indent -= Indent_Increment;
713: }
714:
715: void
716: displayer::a_stmt ()
717: {
718: struct stmt& s = *Pstmt(node);
719:
720: ind();
721: catprintf("$stmt %s |0x%p ",
722: token_name(node->base),
723: node_address);
724: print_loc(s.where);
725: *arg->output_stream << "\n";
726:
727: ind();
728: *arg->output_stream << "where:\t";
729: print_loc(s.where);
730: *arg->output_stream << "\n";
731:
732: print_ptr("s", s.s);
733: print_ptr("s_list", s.s_list);
734: print_ptr("memtbl", s.memtbl);
735: switch(s.discriminator(0)) {
736: case 1: print_ptr("d", s.d); break;
737: case 2: print_ptr("e2", s.e2); break;
738: case 3: print_ptr("has_default", s.has_default); break;
739: case 4: nz_printf("case_value:\t0x%x", s.case_value);
740: case 5: print_ptr("ret_tp", s.ret_tp); break;
741: }
742: switch(s.discriminator(1)) {
743: case 1: print_ptr("e", s.e); break;
744: case 2: nz_printf("own_tbl:\t%d", s.own_tbl); break;
745: case 3: print_ptr("s2", s.s2); break;
746: }
747:
748: switch(s.discriminator(2)) {
749: case 1: print_ptr("for_init", s.for_init); break;
750: case 2: print_ptr("else_stmt",s.for_init); break;
751: case 3: print_ptr("case_list", s.case_list); break;
752: }
753: }
754:
755: void
756: displayer::a_enumdef ()
757: {
758: struct enumdef& e = *Penum(node);
759:
760: printf("$enumdef %s |0x%p",
761: token_name(node->base),
762: node_address);
763:
764: nz_printf( "e_body:\t\t%d", e.e_body);
765: nz_printf( "no_of_enumerators: %d",
766: e.no_of_enumerators);
767: nz_printf( "strlen:\t%d", e.strlen);
768: print_string ("string", (void *)e.string);
769:
770: print_ptr("mem", e.mem);
771: print_ptr("e_type", e.e_type);
772: indent += Indent_Increment;
773: a_type(); /* do the supertype. */
774: indent -= Indent_Increment;
775: }
776:
777: void
778: displayer::a_classdef ()
779: {
780: struct classdef& c = *Pclass(node);
781:
782: ind();
783: catprintf("$classdef %s |0x%p ",
784: token_name(node->base),
785: node_address);
786: print_string_brief(c.string);
787: *arg->output_stream << "\n";
788: ind();
789: catprintf("class_base:\t");
790: switch(c.class_base)
791: {
792: case vanilla_class:
793: *arg->output_stream << "vanilla_class\n";
794: break;
795: case template_class:
796: *arg->output_stream << "template_class\n";
797: Template_Class:
798: nz_printf("inst:\t\t%p", (int)Ptclass(&c)->inst);
799: break;
800: case instantiated_template_class:
801: *arg->output_stream << "instantiated_template_class\n";
802: goto Template_Class;
803: case uninstantiated_template_class:
804: *arg->output_stream << "uninstantiated_template_class\n";
805: goto Template_Class;
806: case relationship_class:
807: *arg->output_stream << "relationship_class\n";
808: break;
809: case defining_class:
810: *arg->output_stream << "defining_class\n";
811: break;
812: }
813:
814: nz_printf( "c_body:\t\t%d", c.c_body);
815: printf("csu:\t\t%s",
816: token_name(c.csu));
817: nz_printf( "obj_align:\t%d", c.obj_align);
818: if(c.c_xref) {
819: ind();
820: catprintf( "c_xref:\t%x", c.c_xref);
821: flag(c.c_xref & 1, "has-vptr ");
822: flag(c.c_xref & 2, "X(X&)-defined ");
823: flag(c.c_xref & 4, "operator=(X&)-defined ");
824: flag(c.c_xref & 8, "has-vbaseptr(s) ");
825: *arg->output_stream << "\n";
826: }
827: nz_printf( "virt_count:\t%d", c.virt_count);
828: nz_printf( "virt_merge:\t%d", c.virt_merge);
829: nz_printf( "c_abstract:\t%d", c.c_abstract);
830: nz_printf( "has_vvtab:\t%d", c.has_vvtab);
831: nz_printf( "strlen:\t%d", c.strlen);
832: print_string ("string", (void *)c.string);
833: nz_printf( "obj_size:\t%d", c.obj_size);
834: nz_printf( "real_size:\t%d", c.real_size);
835: nz_printf("lex_level:\t%d", c.lex_level);
836: if(c.lcl)print_string("lcl", c.lcl);
837:
838: print_ptr("baselist", c.baselist);
839: print_ptr("mem_list", c.mem_list);
840: print_ptr("memtbl", c.memtbl);
841: print_ptr("friend_list", c.friend_list);
842: print_ptr("pubdef", c.pubdef);
843: print_ptr("tn_list", c.tn_list); /* not brief */
844: print_ptr("in_class", c.in_class);
845: print_ptr("in_fct", c.in_fct);
846: print_ptr("this_type", c.this_type);
847: print_ptr("virt_list", c.virt_list);
848: print_ptr("c_ctor", c.c_ctor);
849: print_ptr("c_dtor", c.c_dtor);
850: print_ptr("c_itor", c.c_itor);
851: print_ptr("conv", c.conv);
852: indent += Indent_Increment;
853: a_type(); /* do the supertype. */
854: indent -= Indent_Increment;
855: }
856:
857:
858: void
859: displayer::a_virt()
860: {
861: virt& v = *Pvirt(node);
862: void * vna;
863: void * vna_e;
864: int vx;
865:
866: printf("$virt %s |0x%p ",
867: token_name(node->base),
868: node_address);
869:
870: print_ptr("next", v.next);
871: if(v.n_init) {
872: printf("n_init:\t%d", v.n_init);
873: printf("virt_init:");
874: for (vna = v.virt_init, vx = 0; vx < (v.n_init - 1);
875: vna = (char *)vna + sizeof (velem), vx++)
876: {
877: fetch(vna, sizeof (velem), vna_e);
878: struct velem * ve = (struct velem *) vna_e;
879: ind();
880: catprintf("%d offset %d\t", vx, ve->offset);
881: print_ptr(ve->n);
882: free_fetched(vna_e);
883: }
884: }
885: print_ptr("vclass", v.vclass);
886: nz_printf( "\nis_vbase:\t %d", v.is_vbase);
887: nz_printf( "\nprinted:\t %d", v.printed);
888: }
889:
890: void
891: displayer::a_table ()
892: {
893: struct table& t = *Ptable(node);
894: int x;
895: int y;
896: void * nlist;
897: void * slist;
898:
899: printf("$table %s |0x%p",
900: token_name(node->base),
901: node_address);
902:
903: printf("init_stat:\t%d%s", t.init_stat,
904: t.init_stat == 0 ? " not simplified" :
905: t.init_stat == 1 ? " simplified, no inits" :
906: t.init_stat == 2 ? " simplified, inits" :
907: "");
908: printf("size:\t%d", t.size);
909: printf("hashsize:\t%d", t.hashsize);
910: printf("free_slot:\t%d", t.free_slot);
911:
912: /* it looks like there is an array of Pnames here ... */
913: *arg->output_stream << "\n";
914: ind();
915: *arg->output_stream << "entries:\n";
916: fetch((void *)t.entries, t.size * sizeof(Pname), nlist);
917: Pname * tmp_nlist = (Pname *)nlist;
918: for(x = 0; x < t.size; x ++) {
919: if(tmp_nlist[x]) {
920: ind();
921: *arg->output_stream << x;
922: *arg->output_stream << "\t";
923: print_ptr(tmp_nlist[x]);
924: unsigned char tmp_name_s[sizeof(name)];
925: void * tmp_name;
926: tmp_name = (void *)&tmp_name_s[0];
927: fetch(tmp_nlist[x], sizeof(name), tmp_name);
928: catprintf(" key %d\n", Pname(tmp_name)->n_key);
929: }
930: }
931: free_fetched(nlist);
932: /* and then an array of shorts for the hash table. */
933: /* we really need a tabular format here, alright. */
934: ind();
935: *arg->output_stream << "hashtbl:\n";
936: fetch(t.hashtbl, t.hashsize * sizeof(short), slist);
937: short * tmp_slist = (short *)slist;
938: for(x = 0;; x++ ) {
939: for (y = 0; y < 11; y ++) {
940: if(((x * 12) + y) > t.hashsize) break;
941: catprintf("%6d ", tmp_slist[(x*12)+y]);
942: }
943: *arg->output_stream << "\n";
944: if(((x * 12) + y) > t.hashsize) break;
945: }
946:
947: free_fetched (slist);
948:
949: print_ptr("t_name", t.t_name);
950: print_ptr("real_block", t.real_block);
951: print_ptr("name", t.t_name);
952: print_ptr("next", t.next);
953: }
954:
955: void
956: displayer::a_gen ()
957: {
958: struct gen& g = *Pgen(node);
959:
960: printf("$gen %s |0x%p",
961: token_name(node->base),
962: node_address);
963:
964: print_ptr ("fct_list", g.fct_list);
965: indent += Indent_Increment;
966: a_type(); /* do the supertype. */
967: indent -= Indent_Increment;
968: }
969:
970: void
971: displayer::a_vec ()
972: {
973: struct vec& v = *Pvec(node);
974:
975: printf("$vec %s |0x%p",
976: token_name(node->base),
977: node_address);
978: printf("size:\t\t%d", v.size);
979: print_ptr ("typ", v.typ);
980: print_ptr ("dim", v.dim);
981: }
982:
983: void
984: displayer::a_ptr ()
985: {
986: struct ptr& p = *Pptr(node);
987:
988: printf("$ptr %s |0x%p",
989: token_name(node->base),
990: node_address);
991: ind();
992: printf("rdo:\t\t%d", p.rdo);
993: ind();
994:
995: print_ptr ("typ", p.typ);
996: print_ptr ("memof", p.memof);
997: }
998:
999:
1000: void
1001: displayer::a_nlist()
1002: {
1003: name_list& n = *Plist(node);
1004:
1005: printf("$name_list %s |0x%p ",
1006: token_name(node->base),
1007: node_address);
1008:
1009: print_ptr("f", n.f);
1010: print_ptr("l", n.l);
1011: }
1012:
1013: void
1014: displayer::a_iline()
1015: {
1016: struct iline& i = *(struct iline *)node;
1017:
1018: printf("$iline %s |0x%p ",
1019: token_name(node->base),
1020: node_address);
1021:
1022: print_ptr("fct_name", i.fct_name);
1023: print_ptr("i_next", i.i_next);
1024: print_ptr("i_table", i.i_table);
1025: nz_printf("i_slots:\t%d", i.i_slots);
1026: print_ptr("i_args", i.i_args);
1027: }
1028:
1029: void
1030: displayer::a_ia()
1031: {
1032: struct ia& i = *(struct ia *)node;
1033:
1034: printf("$ia %s |0x%p ",
1035: token_name(node->base),
1036: node_address);
1037:
1038: print_ptr("local", i.local);
1039: print_ptr("arg", i.arg);
1040: print_ptr("tp", i.tp);
1041: }
1042:
1043: static int fetcher (void * info,
1044: void * pointer,
1045: unsigned long length,
1046: int zero_stop, /* for character strings.*/
1047: void * target)
1048: {
1049: displayer * d = (displayer *)info;
1050: if(d->arg->fetcher)
1051: return d->arg->fetcher(d->arg->fetcher_info, pointer, length,
1052: zero_stop, target);
1053: }
1054:
1055: static void
1056: do_node (Pnode& node, node_class cl, void * info, tree_node_action& action,
1057: int depth, Pnode na, tree_walk_tree&, int&)
1058: {
1059: displayer * d = (displayer *)info;
1060: d->do_node(node, cl, action, depth, na);
1061: d->arg->output_stream->write("\n", 1);
1062: }
1063:
1064:
1065: /* Note -- declared extern "C" in tree_dump.h. */
1066:
1067: void
1068: display_cfront_node (dcn_arg& arg, Pnode n)
1069: {
1070: tree_walk_control twc;
1071: displayer d (arg);
1072:
1073: if(arg.verbose == dt_normal)arg.max_depth = 0;
1074: twc.callback_info = (void *)&d;
1075: if(arg.fetcher) twc.fetcher = fetcher;
1076: twc.action_proc = do_node;
1077: twc.error_stream = arg.error_stream;
1078: twc.nodes_seen_hash = arg.nodes_seen_hash;
1079: twc.resolve_by_name = 0; /* we want to display the by_name nodes */
1080: twc.dont_chase_lists_top = 1; /* don't display n_list or s_list peers
1081: at the top level. */
1082:
1083: walk_tree(twc, n);
1084:
1085: arg.error_stream->flush();
1086: arg.output_stream->flush();
1087: }
1088:
1089:
1090: extern "C" void _fcout();
1091: void _fcout () { cout.flush(); }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.