|
|
1.1 ! root 1: /* -*- Mode:C++ -*- */ ! 2: /* dump_tree.C -- utilities for displaying the cfront tree. */ ! 3: /* BIM 890530 */ ! 4: /* rewritten 890712 to use the tree-walking facilities */ ! 5: ! 6: /* ! 7: $Source: /usr3/lang/benson/work/stripped_cfront/RCS/dump_tree.c,v $ $RCSfile: dump_tree.c,v $ ! 8: $Revision: 1.1 $ $Date: 89/11/20 08:50:22 $ ! 9: $Author: benson $ $Locker: $ ! 10: $State: Exp $ ! 11: ! 12: ! 13: */ ! 14: ! 15: ! 16: #include "dump_tree.H" ! 17: #include <stdio.h> /* turds and whey */ ! 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.n_key || 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_oper:\t\t%s", n.n_oper ? ! 587: token_name(n.n_oper) : 0); ! 588: nz_printf( "n_sto:\t\t%s", n.n_sto ? ! 589: token_name(n.n_sto) : 0); ! 590: nz_printf( "n_stclass:\t%s", n.n_stclass ? ! 591: token_name(n.n_stclass) : 0); ! 592: nz_printf( "n_scope:\t%s", n.n_scope ? ! 593: token_name(n.n_scope) : 0); ! 594: nz_printf( "n_union:\t%d", n.n_union); ! 595: nz_printf( "n_evaluated:\t%d", n.n_evaluated); ! 596: nz_printf( "n_xref:\t\t%d", n.n_xref); ! 597: nz_printf( "lex_level:\t%d", n.lex_level); ! 598: nz_printf( "n_protect:\t%s", n.n_protect ? ! 599: token_name(n.n_protect) : 0); ! 600: if (n.n_dcl_printed || print_null_values) { ! 601: ind(); ! 602: catprintf("n_dcl_printed:\t%d", n.n_dcl_printed); ! 603: ! 604: switch(n.n_dcl_printed) ! 605: { ! 606: case 0: ! 607: catprintf("(not)\n"); ! 608: break; ! 609: case 1: ! 610: printf("(declaration)\n"); ! 611: break; ! 612: case 2: ! 613: printf("(definition)\n"); ! 614: break; ! 615: } ! 616: ! 617: } ! 618: if(n.n_template_arg) { ! 619: ind(); ! 620: catprintf( "n_template_arg:\t"); ! 621: switch(n.n_template_arg) ! 622: { ! 623: case name::template_type_formal: ! 624: catprintf("template_type_formal\n"); ! 625: break; ! 626: case name::template_expr_formal: ! 627: catprintf("template_expr_formal\n"); ! 628: break; ! 629: case name::template_stmt_tree_formal: ! 630: catprintf("template_stmt_formal\n"); ! 631: break; ! 632: case name::template_expr_tree_formal: ! 633: catprintf("template_expr_tree_formal\n"); ! 634: break; ! 635: case name::template_actual_arg_dummy: ! 636: catprintf("template_actual_arg_dummy\n"); ! 637: break; ! 638: } ; ! 639: } ! 640: nz_printf( "n_addr_taken:\t%d", n.n_addr_taken); ! 641: nz_printf( "n_used:\t\t%d", n.n_used); ! 642: nz_printf( "n_assigned_to:\t%d", n.n_assigned_to); ! 643: ind(); ! 644: catprintf("loc:\t\t"); ! 645: print_loc(n.where); ! 646: catprintf("\n"); ! 647: nz_printf( "n_offset:\t%d", n.n_offset); ! 648: if(n.output_string) { ! 649: print_string("output_string", (void *)n.output_string); ! 650: } ! 651: nz_printf( "n_val:\t\t%ld", n.n_val); ! 652: ! 653: print_ptr("n_list", n.n_list); ! 654: print_ptr("n_tbl_list", n.n_tbl_list); ! 655: if(n.n_gen_fct_name) ! 656: print_string("n_gen_fct_name", n.n_gen_fct_name); ! 657: if(n.n_template_arg_string) { ! 658: print_string("n_template_arg_string", ! 659: n.n_template_arg_string); ! 660: } ! 661: switch(n.discriminator(0)) { ! 662: case 2: print_ptr("n_realscope", n.n_realscope); break; ! 663: case 1: print_ptr("n_qualifier", n.n_qualifier); break; ! 664: } ! 665: nz_printf("n_val:\t%ld", n.n_val); ! 666: ! 667: indent += Indent_Increment; ! 668: a_expr(1); /* do the supertype. */ ! 669: indent -= Indent_Increment; ! 670: } ! 671: ! 672: void ! 673: displayer::a_fct() ! 674: { ! 675: struct fct& f = *Pfct(node); ! 676: ! 677: printf("$fct %s |0x%p", ! 678: token_name(node->base), ! 679: node_address); ! 680: ! 681: ! 682: printf("nargs:\t\t%d", f.nargs); ! 683: printf("nargs_known:\t%d%s", f.nargs_known, ! 684: f.nargs_known == 0 ? " UNKNOWN" : ! 685: (f.nargs_known == 1 ? " KNOWN" : ! 686: (f.nargs_known == ELLIPSIS ? "ELLIPSIS" : "" ))); ! 687: nz_printf( "f_vdef:\t\t%d", f.f_vdef); ! 688: printf("f_inline:\t%d%s", f.f_inline, ! 689: f.f_inline == 0 ? "" : ! 690: f.f_inline == 1 ? " inline" : ! 691: f.f_inline == 2 ? " inline in expansion" : ""); ! 692: nz_printf( "f_const:\t\t%d", f.f_const); ! 693: nz_printf( "f_static:\t\t%d", f.f_static); ! 694: nz_printf( "f_virtual:\t%d", f.f_virtual); ! 695: nz_printf( "f_imeasure:\t%d", f.f_imeasure); ! 696: print_string("f_signature", (void *)f.f_signature); ! 697: ! 698: print_ptr("returns", f.returns); ! 699: print_ptr("argtype", f.argtype); ! 700: print_ptr("s_returns", f.s_returns); ! 701: print_ptr("f_this", f.f_this); ! 702: print_ptr("memof", f.memof); ! 703: print_ptr("body", f.body); ! 704: print_ptr("f_init", f.f_init); ! 705: print_ptr("f_expr", f.f_expr); ! 706: print_ptr("last_expanded", f.last_expanded); ! 707: print_ptr("f_result", f.f_result); ! 708: print_ptr("f_args", f.f_args); ! 709: print_ptr("local_classes", f.local_class); ! 710: ! 711: indent += Indent_Increment; ! 712: a_type(); /* do the supertype. */ ! 713: indent -= Indent_Increment; ! 714: } ! 715: ! 716: void ! 717: displayer::a_stmt () ! 718: { ! 719: struct stmt& s = *Pstmt(node); ! 720: ! 721: ind(); ! 722: catprintf("$stmt %s |0x%p ", ! 723: token_name(node->base), ! 724: node_address); ! 725: print_loc(s.where); ! 726: *arg->output_stream << "\n"; ! 727: ! 728: ind(); ! 729: *arg->output_stream << "where:\t"; ! 730: print_loc(s.where); ! 731: *arg->output_stream << "\n"; ! 732: ! 733: print_ptr("s", s.s); ! 734: print_ptr("s_list", s.s_list); ! 735: print_ptr("memtbl", s.memtbl); ! 736: switch(s.discriminator(0)) { ! 737: case 1: print_ptr("d", s.d); break; ! 738: case 2: print_ptr("e2", s.e2); break; ! 739: case 3: print_ptr("has_default", s.has_default); break; ! 740: case 4: nz_printf("case_value:\t0x%x", s.case_value); ! 741: case 5: print_ptr("ret_tp", s.ret_tp); break; ! 742: } ! 743: switch(s.discriminator(1)) { ! 744: case 1: print_ptr("e", s.e); break; ! 745: case 2: nz_printf("own_tbl:\t%d", s.own_tbl); break; ! 746: case 3: print_ptr("s2", s.s2); break; ! 747: } ! 748: ! 749: switch(s.discriminator(2)) { ! 750: case 1: print_ptr("for_init", s.for_init); break; ! 751: case 2: print_ptr("else_stmt",s.for_init); break; ! 752: case 3: print_ptr("case_list", s.case_list); break; ! 753: } ! 754: } ! 755: ! 756: void ! 757: displayer::a_enumdef () ! 758: { ! 759: struct enumdef& e = *Penum(node); ! 760: ! 761: printf("$enumdef %s |0x%p", ! 762: token_name(node->base), ! 763: node_address); ! 764: ! 765: nz_printf( "e_body:\t\t%d", e.e_body); ! 766: nz_printf( "no_of_enumerators: %d", ! 767: e.no_of_enumerators); ! 768: nz_printf( "strlen:\t%d", e.strlen); ! 769: print_string ("string", (void *)e.string); ! 770: ! 771: print_ptr("mem", e.mem); ! 772: print_ptr("e_type", e.e_type); ! 773: indent += Indent_Increment; ! 774: a_type(); /* do the supertype. */ ! 775: indent -= Indent_Increment; ! 776: } ! 777: ! 778: void ! 779: displayer::a_classdef () ! 780: { ! 781: struct classdef& c = *Pclass(node); ! 782: ! 783: ind(); ! 784: catprintf("$classdef %s |0x%p ", ! 785: token_name(node->base), ! 786: node_address); ! 787: print_string_brief(c.string); ! 788: *arg->output_stream << "\n"; ! 789: ind(); ! 790: catprintf("class_base:\t"); ! 791: switch(c.class_base) ! 792: { ! 793: case vanilla_class: ! 794: *arg->output_stream << "vanilla_class\n"; ! 795: break; ! 796: case template_class: ! 797: *arg->output_stream << "template_class\n"; ! 798: Template_Class: ! 799: nz_printf("inst:\t\t%p", (int)Ptclass(&c)->inst); ! 800: break; ! 801: case instantiated_template_class: ! 802: *arg->output_stream << "instantiated_template_class\n"; ! 803: goto Template_Class; ! 804: case uninstantiated_template_class: ! 805: *arg->output_stream << "uninstantiated_template_class\n"; ! 806: goto Template_Class; ! 807: case relationship_class: ! 808: *arg->output_stream << "relationship_class\n"; ! 809: break; ! 810: case defining_class: ! 811: *arg->output_stream << "defining_class\n"; ! 812: break; ! 813: } ! 814: ! 815: nz_printf( "c_body:\t\t%d", c.c_body); ! 816: printf("csu:\t\t%s", ! 817: token_name(c.csu)); ! 818: nz_printf( "obj_align:\t%d", c.obj_align); ! 819: if(c.c_xref) { ! 820: ind(); ! 821: catprintf( "c_xref:\t%x", c.c_xref); ! 822: flag(c.c_xref & 1, "has-vptr "); ! 823: flag(c.c_xref & 2, "X(X&)-defined "); ! 824: flag(c.c_xref & 4, "operator=(X&)-defined "); ! 825: flag(c.c_xref & 8, "has-vbaseptr(s) "); ! 826: *arg->output_stream << "\n"; ! 827: } ! 828: nz_printf( "virt_count:\t%d", c.virt_count); ! 829: nz_printf( "virt_merge:\t%d", c.virt_merge); ! 830: nz_printf( "c_abstract:\t%d", c.c_abstract); ! 831: nz_printf( "has_vvtab:\t%d", c.has_vvtab); ! 832: nz_printf( "strlen:\t%d", c.strlen); ! 833: print_string ("string", (void *)c.string); ! 834: nz_printf( "obj_size:\t%d", c.obj_size); ! 835: nz_printf( "real_size:\t%d", c.real_size); ! 836: nz_printf("lex_level:\t%d", c.lex_level); ! 837: if(c.lcl)print_string("lcl", c.lcl); ! 838: ! 839: print_ptr("baselist", c.baselist); ! 840: print_ptr("mem_list", c.mem_list); ! 841: print_ptr("memtbl", c.memtbl); ! 842: print_ptr("friend_list", c.friend_list); ! 843: print_ptr("pubdef", c.pubdef); ! 844: print_ptr("tn_list", c.tn_list); /* not brief */ ! 845: print_ptr("in_class", c.in_class); ! 846: print_ptr("in_fct", c.in_fct); ! 847: print_ptr("this_type", c.this_type); ! 848: print_ptr("virt_list", c.virt_list); ! 849: print_ptr("c_ctor", c.c_ctor); ! 850: print_ptr("c_dtor", c.c_dtor); ! 851: print_ptr("c_itor", c.c_itor); ! 852: print_ptr("conv", c.conv); ! 853: indent += Indent_Increment; ! 854: a_type(); /* do the supertype. */ ! 855: indent -= Indent_Increment; ! 856: } ! 857: ! 858: ! 859: void ! 860: displayer::a_virt() ! 861: { ! 862: virt& v = *Pvirt(node); ! 863: void * vna; ! 864: void * vna_e; ! 865: int vx; ! 866: ! 867: printf("$virt %s |0x%p ", ! 868: token_name(node->base), ! 869: node_address); ! 870: ! 871: print_ptr("next", v.next); ! 872: if(v.n_init) { ! 873: printf("n_init:\t%d", v.n_init); ! 874: printf("virt_init:"); ! 875: for (vna = v.virt_init, vx = 0; vx < (v.n_init - 1); ! 876: vna = (char *)vna + sizeof (velem), vx++) ! 877: { ! 878: fetch(vna, sizeof (velem), vna_e); ! 879: struct velem * ve = (struct velem *) vna_e; ! 880: ind(); ! 881: catprintf("%d offset %d\t", vx, ve->offset); ! 882: print_ptr(ve->n); ! 883: free_fetched(vna_e); ! 884: } ! 885: } ! 886: print_ptr("vclass", v.vclass); ! 887: nz_printf( "\nis_vbase:\t %d", v.is_vbase); ! 888: nz_printf( "\nprinted:\t %d", v.printed); ! 889: } ! 890: ! 891: void ! 892: displayer::a_table () ! 893: { ! 894: struct table& t = *Ptable(node); ! 895: int x; ! 896: int y; ! 897: void * nlist; ! 898: void * slist; ! 899: ! 900: printf("$table %s |0x%p", ! 901: token_name(node->base), ! 902: node_address); ! 903: ! 904: printf("init_stat:\t%d%s", t.init_stat, ! 905: t.init_stat == 0 ? " not simplified" : ! 906: t.init_stat == 1 ? " simplified, no inits" : ! 907: t.init_stat == 2 ? " simplified, inits" : ! 908: ""); ! 909: printf("size:\t%d", t.size); ! 910: printf("hashsize:\t%d", t.hashsize); ! 911: printf("free_slot:\t%d", t.free_slot); ! 912: ! 913: /* it looks like there is an array of Pnames here ... */ ! 914: *arg->output_stream << "\n"; ! 915: ind(); ! 916: *arg->output_stream << "entries:\n"; ! 917: fetch((void *)t.entries, t.size * sizeof(Pname), nlist); ! 918: Pname * tmp_nlist = (Pname *)nlist; ! 919: for(x = 0; x < t.size; x ++) { ! 920: if(tmp_nlist[x]) { ! 921: ind(); ! 922: *arg->output_stream << x; ! 923: *arg->output_stream << "\t"; ! 924: print_ptr(tmp_nlist[x]); ! 925: unsigned char tmp_name_s[sizeof(name)]; ! 926: void * tmp_name; ! 927: tmp_name = (void *)&tmp_name_s[0]; ! 928: fetch(tmp_nlist[x], sizeof(name), tmp_name); ! 929: catprintf(" key %d\n", Pname(tmp_name)->n_key); ! 930: } ! 931: } ! 932: free_fetched(nlist); ! 933: /* and then an array of shorts for the hash table. */ ! 934: /* we really need a tabular format here, alright. */ ! 935: ind(); ! 936: *arg->output_stream << "hashtbl:\n"; ! 937: fetch(t.hashtbl, t.hashsize * sizeof(short), slist); ! 938: short * tmp_slist = (short *)slist; ! 939: for(x = 0;; x++ ) { ! 940: for (y = 0; y < 11; y ++) { ! 941: if(((x * 12) + y) > t.hashsize) break; ! 942: catprintf("%6d ", tmp_slist[(x*12)+y]); ! 943: } ! 944: *arg->output_stream << "\n"; ! 945: if(((x * 12) + y) > t.hashsize) break; ! 946: } ! 947: ! 948: free_fetched (slist); ! 949: ! 950: print_ptr("t_name", t.t_name); ! 951: print_ptr("real_block", t.real_block); ! 952: print_ptr("name", t.t_name); ! 953: print_ptr("next", t.next); ! 954: } ! 955: ! 956: void ! 957: displayer::a_gen () ! 958: { ! 959: struct gen& g = *Pgen(node); ! 960: ! 961: printf("$gen %s |0x%p", ! 962: token_name(node->base), ! 963: node_address); ! 964: ! 965: print_ptr ("fct_list", g.fct_list); ! 966: indent += Indent_Increment; ! 967: a_type(); /* do the supertype. */ ! 968: indent -= Indent_Increment; ! 969: } ! 970: ! 971: void ! 972: displayer::a_vec () ! 973: { ! 974: struct vec& v = *Pvec(node); ! 975: ! 976: printf("$vec %s |0x%p", ! 977: token_name(node->base), ! 978: node_address); ! 979: printf("size:\t\t%d", v.size); ! 980: print_ptr ("typ", v.typ); ! 981: print_ptr ("dim", v.dim); ! 982: } ! 983: ! 984: void ! 985: displayer::a_ptr () ! 986: { ! 987: struct ptr& p = *Pptr(node); ! 988: ! 989: printf("$ptr %s |0x%p", ! 990: token_name(node->base), ! 991: node_address); ! 992: ind(); ! 993: printf("rdo:\t\t%d", p.rdo); ! 994: ind(); ! 995: ! 996: print_ptr ("typ", p.typ); ! 997: print_ptr ("memof", p.memof); ! 998: } ! 999: ! 1000: ! 1001: void ! 1002: displayer::a_nlist() ! 1003: { ! 1004: name_list& n = *Plist(node); ! 1005: ! 1006: printf("$name_list %s |0x%p ", ! 1007: token_name(node->base), ! 1008: node_address); ! 1009: ! 1010: print_ptr("f", n.f); ! 1011: print_ptr("l", n.l); ! 1012: } ! 1013: ! 1014: void ! 1015: displayer::a_iline() ! 1016: { ! 1017: struct iline& i = *(struct iline *)node; ! 1018: ! 1019: printf("$iline %s |0x%p ", ! 1020: token_name(node->base), ! 1021: node_address); ! 1022: ! 1023: print_ptr("fct_name", i.fct_name); ! 1024: print_ptr("i_next", i.i_next); ! 1025: print_ptr("i_table", i.i_table); ! 1026: nz_printf("i_slots:\t%d", i.i_slots); ! 1027: print_ptr("i_args", i.i_args); ! 1028: } ! 1029: ! 1030: void ! 1031: displayer::a_ia() ! 1032: { ! 1033: struct ia& i = *(struct ia *)node; ! 1034: ! 1035: printf("$ia %s |0x%p ", ! 1036: token_name(node->base), ! 1037: node_address); ! 1038: ! 1039: print_ptr("local", i.local); ! 1040: print_ptr("arg", i.arg); ! 1041: print_ptr("tp", i.tp); ! 1042: } ! 1043: ! 1044: static int fetcher (void * info, ! 1045: void * pointer, ! 1046: unsigned long length, ! 1047: int zero_stop, /* for character strings.*/ ! 1048: void * target) ! 1049: { ! 1050: displayer * d = (displayer *)info; ! 1051: if(d->arg->fetcher) ! 1052: return d->arg->fetcher(d->arg->fetcher_info, pointer, length, ! 1053: zero_stop, target); ! 1054: } ! 1055: ! 1056: static void ! 1057: do_node (Pnode& node, node_class cl, void * info, tree_node_action& action, ! 1058: int depth, Pnode na, tree_walk_tree&, int&) ! 1059: { ! 1060: displayer * d = (displayer *)info; ! 1061: d->do_node(node, cl, action, depth, na); ! 1062: d->arg->output_stream->write("\n", 1); ! 1063: } ! 1064: ! 1065: ! 1066: /* Note -- declared extern "C" in dump_tree.H. */ ! 1067: ! 1068: void ! 1069: display_cfront_node (dcn_arg& arg, Pnode n) ! 1070: { ! 1071: tree_walk_control twc; ! 1072: displayer d (arg); ! 1073: ! 1074: if(arg.verbose == dt_normal)arg.max_depth = 0; ! 1075: twc.callback_info = (void *)&d; ! 1076: if(arg.fetcher) twc.fetcher = fetcher; ! 1077: twc.action_proc = do_node; ! 1078: twc.error_stream = arg.error_stream; ! 1079: twc.nodes_seen_hash = arg.nodes_seen_hash; ! 1080: twc.resolve_by_name = 0; /* we want to display the by_name nodes */ ! 1081: twc.dont_chase_lists_top = 1; /* don't display n_list or s_list peers ! 1082: at the top level. */ ! 1083: ! 1084: walk_tree(twc, n); ! 1085: ! 1086: arg.error_stream->flush(); ! 1087: arg.output_stream->flush(); ! 1088: } ! 1089: ! 1090: ! 1091: extern "C" void _fcout(); ! 1092: ! 1093: void _fcout () { cout.flush(); } ! 1094: ! 1095: static char rcsinfo[] = "$Header: /usr3/lang/benson/work/stripped_cfront/RCS/dump_tree.c,v 1.1 89/11/20 08:50:22 benson Exp $"; ! 1096: ! 1097: ! 1098: /* $Log: dump_tree.c,v $ ! 1099: * Revision 1.1 89/11/20 08:50:22 benson ! 1100: * Initial revision ! 1101: * ! 1102: Revision 1.32 89/11/03 16:18:32 benson ! 1103: mind rot. ! 1104: ! 1105: Revision 1.31 89/11/03 16:10:04 benson ! 1106: Oh, don't try to use the name constructor inside dgb. ! 1107: ! 1108: Revision 1.30 89/11/03 15:28:39 benson ! 1109: fix cn for tables. ! 1110: ! 1111: Revision 1.29 89/10/31 14:47:24 benson ! 1112: new function flags. Bug in vector printing. ! 1113: ! 1114: Revision 1.28 89/10/20 14:33:06 benson ! 1115: print abnormal function flag, don't print n_list and s_list peers ! 1116: of top item dumped. ! 1117: ! 1118: Revision 1.27 89/10/06 14:44:28 benson ! 1119: use new token name array courtesy of byacc. ! 1120: ! 1121: Revision 1.26 89/10/04 18:54:21 dysak ! 1122: Add code to dump the let_address_of_deref_be_address_of and ! 1123: nonempty_converted_collection flags in an expression node. ! 1124: Add code to dump the n_persistent_db field of a name node. ! 1125: Fix failure to discriminate properly between the n_realscope ! 1126: and n_qualifier nodes properly when dumping. ! 1127: ! 1128: Revision 1.25 89/09/22 14:03:32 benson ! 1129: fixes for locs. ! 1130: ! 1131: Revision 1.24 89/09/14 15:25:47 benson ! 1132: display a table as the top level item, but not deeper in. ! 1133: ! 1134: Revision 1.23 89/09/13 09:17:10 benson ! 1135: rename aggregate to collection. ! 1136: ! 1137: Revision 1.22 89/09/08 13:49:52 benson ! 1138: fix handling for dt_normal to print something, ! 1139: and also stop printing a spurious >. ! 1140: ! 1141: Revision 1.21 89/09/02 22:08:10 benson ! 1142: deal with changes to tree copies. ! 1143: ! 1144: Revision 1.20 89/08/29 13:39:57 benson ! 1145: disentangle the character string name of a generic function ! 1146: from n_table_list. ! 1147: ! 1148: Revision 1.19 89/08/24 08:45:11 benson ! 1149: some support for queries and templates. ! 1150: ! 1151: Revision 1.17 89/07/27 13:30:33 benson ! 1152: agg changes. ! 1153: ! 1154: Revision 1.16 89/07/21 16:49:44 benson ! 1155: checked in with -k by benson at 89.07.24.15.48.50. ! 1156: ! 1157: Revision 1.16 89/07/21 16:49:44 benson ! 1158: support for by_name nodes. ! 1159: ! 1160: Revision 1.15 89/07/18 15:17:39 benson ! 1161: print local classes, not args, under label local_classes. ! 1162: other bugfixes. ! 1163: ! 1164: Revision 1.14 89/07/14 10:58:30 benson ! 1165: rewrite as a user of the new tree_walk facilities. Brief mode ! 1166: is most likely busted. ! 1167: ! 1168: Revision 1.13 89/07/10 10:51:32 benson ! 1169: add fields added in 2.0 or just plain missed before. ! 1170: ! 1171: Revision 1.13 89/07/09 14:37:21 benson ! 1172: print aggregate facts. Treat QUERIES as exprs. ! 1173: ! 1174: Revision 1.12 89/06/30 15:28:26 benson ! 1175: checked in with -k by benson at 89.07.07.08.32.34. ! 1176: ! 1177: Revision 1.12 89/06/30 15:28:26 benson ! 1178: add ZTYPE to the list of type nodes, whatever it is. ! 1179: ! 1180: Revision 1.11 89/06/30 14:34:07 benson ! 1181: run script to make token name list automatically from tokens ! 1182: in gram.y ! 1183: ! 1184: Revision 1.9 89/06/29 08:44:47 benson ! 1185: checked in with -k by benson at 89.06.29.20.54.47. ! 1186: ! 1187: Revision 1.9 89/06/29 08:44:47 benson ! 1188: token_name function useful in parse tracing. ! 1189: ! 1190: Revision 1.8 89/06/28 12:57:53 benson ! 1191: Port of changes from 2.0beta6 odi bugfixes ! 1192: ! 1193: end_log ! 1194: ! 1195: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.