home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / cp / error.c < prev    next >
C/C++ Source or Header  |  1996-12-12  |  33KB  |  1,498 lines

  1. /* Call-backs for C++ error reporting.
  2.    This code is non-reentrant.
  3.    Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22. #include "config.h"
  23. #include "tree.h"
  24. #include "cp-tree.h"
  25. #include "obstack.h"
  26. #include <ctype.h>
  27. #ifdef OBJCPLUS
  28. #include "objc-act.h"
  29. #endif
  30.  
  31. typedef char* cp_printer ();
  32.  
  33. #define A args_as_string
  34. #define C code_as_string
  35. #define D decl_as_string
  36. #define E expr_as_string
  37. #define L language_as_string
  38. #define O op_as_string
  39. #define P parm_as_string
  40. #define T type_as_string
  41. #define V cv_as_string
  42.  
  43. #define _ (cp_printer *) 0
  44. cp_printer * cp_printers[256] =
  45. /*0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F */
  46.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x00 */
  47.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x10 */
  48.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x20 */
  49.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x30 */
  50.   _, A, _, C, D, E, _, _, _, _, _, _, L, _, _, O, /* 0x40 */
  51.   P, _, _, _, T, _, V, _, _, _, _, _, _, _, _, _, /* 0x50 */
  52.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */
  53.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */
  54. };
  55. #undef C
  56. #undef D
  57. #undef E
  58. #undef L
  59. #undef O
  60. #undef P
  61. #undef T
  62. #undef V
  63. #undef _
  64.  
  65. #define obstack_chunk_alloc xmalloc
  66. #define obstack_chunk_free free
  67.  
  68. /* Obstack where we build text strings for overloading, etc.  */
  69. static struct obstack scratch_obstack;
  70. static char *scratch_firstobj;
  71.  
  72. # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
  73. # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
  74. # define OB_PUTC2(C1,C2)    \
  75.   (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
  76. # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
  77. # define OB_PUTID(ID)  \
  78.   (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID),    \
  79.          IDENTIFIER_LENGTH (ID)))
  80. # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
  81. # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
  82. # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
  83.                OB_PUTCP (digit_buffer); } while (0)
  84. # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
  85.  
  86. # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
  87.  
  88. static void dump_type (), dump_decl (), dump_function_decl ();
  89. static void dump_expr (), dump_unary_op (), dump_binary_op ();
  90. static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix ();
  91. static void dump_function_name ();
  92.  
  93. void
  94. init_error ()
  95. {
  96.   gcc_obstack_init (&scratch_obstack);
  97.   scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
  98. }
  99.  
  100. enum pad { none, before, after };
  101.  
  102. static void
  103. dump_readonly_or_volatile (t, p)
  104.      tree t;
  105.      enum pad p;
  106. {
  107.   if (TYPE_READONLY (t) || TYPE_VOLATILE (t))
  108.     {
  109.       if (p == before) OB_PUTC (' ');
  110.       if (TYPE_READONLY (t))
  111.     OB_PUTS ("const");
  112.       if (TYPE_READONLY (t) && TYPE_VOLATILE (t))
  113.     OB_PUTC (' ');
  114.       if (TYPE_VOLATILE (t))
  115.     OB_PUTS ("volatile");
  116.       if (p == after) OB_PUTC (' ');
  117.     }
  118. }
  119.  
  120. /* This must be large enough to hold any printed integer or floating-point
  121.    value.  */
  122. static char digit_buffer[128];
  123.  
  124. /* Dump into the obstack a human-readable equivalent of TYPE. */
  125. static void
  126. dump_type (t, v)
  127.      tree t;
  128.      int v;            /* verbose? */
  129. {
  130.   if (t == NULL_TREE)
  131.     return;
  132.   
  133.   if (TYPE_PTRMEMFUNC_P (t))
  134.     goto offset_type;
  135.  
  136.   switch (TREE_CODE (t))
  137.     {
  138.     case ERROR_MARK:
  139.       OB_PUTS ("{error}");
  140.       break;
  141.  
  142.     case UNKNOWN_TYPE:
  143.       OB_PUTS ("{unknown type}");
  144.       break;
  145.  
  146.     case TREE_LIST:
  147.       /* i.e. function taking no arguments */
  148.       if (t != void_list_node)
  149.     {
  150.       dump_type (TREE_VALUE (t), v);
  151.       /* Can this happen other than for default arguments? */
  152.       if (TREE_PURPOSE (t) && v)
  153.         {
  154.           OB_PUTS (" = ");
  155.           dump_expr (TREE_PURPOSE (t));
  156.         }
  157.       if (TREE_CHAIN (t))
  158.         {
  159.           if (TREE_CHAIN (t) != void_list_node)
  160.         {
  161.           OB_PUTC2 (',', ' ');
  162.           dump_type (TREE_CHAIN (t), v);
  163.         }
  164.         }
  165.       else OB_PUTS (" ...");
  166.     }
  167.       break;
  168.  
  169.     case IDENTIFIER_NODE:
  170.       OB_PUTID (t);
  171.       break;
  172.  
  173.     case TREE_VEC:
  174.       dump_type (BINFO_TYPE (t), v);
  175.       break;
  176.  
  177.     case RECORD_TYPE:
  178.     case UNION_TYPE:
  179.     case ENUMERAL_TYPE:
  180.       if (TYPE_LANG_SPECIFIC (t)
  181.       && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
  182.     {
  183.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  184.         dump_readonly_or_volatile (t);
  185.       dump_type (SIGNATURE_TYPE (t), v);
  186.       if (IS_SIGNATURE_POINTER (t))
  187.         OB_PUTC ('*');
  188.       else
  189.         OB_PUTC ('&');
  190.     }
  191.       else
  192.     dump_aggr_type (t, v);
  193.       break;
  194.  
  195.     case TYPE_DECL:
  196.       dump_decl (t, v);
  197.       break;
  198.  
  199.     case INTEGER_TYPE:
  200.       if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
  201.     OB_PUTS ("unsigned ");
  202.       else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
  203.     OB_PUTS ("signed ");
  204.  
  205.       /* fall through.  */
  206.     case REAL_TYPE:
  207.     case VOID_TYPE:
  208.     case BOOLEAN_TYPE:
  209.       dump_readonly_or_volatile (t, after);
  210.       OB_PUTID (TYPE_IDENTIFIER (t));
  211.       break;
  212.  
  213.     case TEMPLATE_TYPE_PARM:
  214.       OB_PUTID (TYPE_IDENTIFIER (t));
  215.       break;
  216.  
  217.     case UNINSTANTIATED_P_TYPE:
  218.       OB_PUTID (DECL_NAME (UPT_TEMPLATE (t)));
  219.       OB_PUTS ("<...>");
  220.       break;
  221.  
  222.       /* This is not always necessary for pointers and such, but doing this
  223.      reduces code size.  */
  224.     case ARRAY_TYPE:
  225.     case POINTER_TYPE:
  226.     case REFERENCE_TYPE:
  227.     case OFFSET_TYPE:
  228.     offset_type:
  229.     case FUNCTION_TYPE:
  230.     case METHOD_TYPE:
  231.       dump_type_prefix (t, v);
  232.       dump_type_suffix (t, v);
  233.       break;
  234.  
  235.     default:
  236.       sorry ("`%s' not supported by dump_type",
  237.          tree_code_name[(int) TREE_CODE (t)]);
  238.     }
  239. }
  240.  
  241. static char *
  242. aggr_variety (t)
  243.      tree t;
  244. {
  245.   if (TREE_CODE (t) == ENUMERAL_TYPE)
  246.     return "enum";
  247.   else if (TREE_CODE (t) == UNION_TYPE)
  248.     return "union";
  249.   else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
  250.     return "class";
  251.   else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
  252.     return "signature";
  253.   else
  254.     return "struct";
  255. }
  256.  
  257. /* Print out a class declaration, in the form `class foo'. */
  258. static void
  259. dump_aggr_type (t, v)
  260.      tree t;
  261.      int v;            /* verbose? */
  262. {
  263.   tree name;
  264.   char *variety = aggr_variety (t);
  265.  
  266.   dump_readonly_or_volatile (t, after);
  267.  
  268.   if (v > 0)
  269.     {
  270.       OB_PUTCP (variety);
  271.       OB_PUTC (' ');
  272.     }
  273.   
  274.   name = TYPE_NAME (t);
  275.  
  276.   if (name && DECL_CONTEXT (name))
  277.     {
  278.       /* FUNCTION_DECL or RECORD_TYPE */
  279.       dump_decl (DECL_CONTEXT (name), 0);
  280.       OB_PUTC2 (':', ':');
  281.     }
  282.  
  283.   /* kludge around weird behavior on g++.brendan/line1.C */
  284.   if (name && TREE_CODE (name) != IDENTIFIER_NODE)
  285.     name = DECL_NAME (name);
  286.  
  287.   if (name == 0 || ANON_AGGRNAME_P (name))
  288.     {
  289.       OB_PUTS ("{anonymous");
  290.       if (!v)
  291.     {
  292.       OB_PUTC (' ');
  293.       OB_PUTCP (variety);
  294.     }
  295.       OB_PUTC ('}');
  296.     }
  297.   else
  298.     OB_PUTID (name);
  299. }
  300.  
  301. /* Dump into the obstack the initial part of the output for a given type.
  302.    This is necessary when dealing with things like functions returning
  303.    functions.  Examples:
  304.  
  305.    return type of `int (* fee ())()': pointer -> function -> int.  Both
  306.    pointer (and reference and offset) and function (and member) types must
  307.    deal with prefix and suffix.
  308.  
  309.    Arrays must also do this for DECL nodes, like int a[], and for things like
  310.    int *[]&.  */
  311.  
  312. static void
  313. dump_type_prefix (t, v)
  314.      tree t;
  315.      int v;            /* verbosity */
  316. {
  317.   if (TYPE_PTRMEMFUNC_P (t))
  318.     {
  319.       t = TYPE_PTRMEMFUNC_FN_TYPE (t);
  320.       goto offset_type;
  321.     }
  322.   
  323.   switch (TREE_CODE (t))
  324.     {
  325.     case POINTER_TYPE:
  326.       {
  327.     tree sub = TREE_TYPE (t);
  328.     
  329.     dump_type_prefix (sub, v);
  330.     /* A tree for a member pointer looks like pointer to offset,
  331.        so let the OFFSET_TYPE case handle it.  */
  332.     if (TREE_CODE (sub) != OFFSET_TYPE)
  333.       {
  334.         switch (TREE_CODE (sub))
  335.           {
  336.         /* We don't want int ( *)() */
  337.           case FUNCTION_TYPE:
  338.           case METHOD_TYPE:
  339.         break;
  340.         
  341.           case ARRAY_TYPE:
  342.         OB_PUTC2 (' ', '(');
  343.         break;
  344.  
  345.           case POINTER_TYPE:
  346.         /* We don't want "char * *" */
  347.         if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
  348.           break;
  349.         /* But we do want "char *const *" */
  350.         
  351.           default:
  352.         OB_PUTC (' ');
  353.           }
  354.         OB_PUTC ('*');
  355.         dump_readonly_or_volatile (t, none);
  356.       }
  357.       }
  358.       break;
  359.  
  360.     case REFERENCE_TYPE:
  361.       {
  362.     tree sub = TREE_TYPE (t);
  363.     dump_type_prefix (sub, v);
  364.  
  365.     switch (TREE_CODE (sub))
  366.       {
  367.       case ARRAY_TYPE:
  368.         OB_PUTC2 (' ', '(');
  369.         break;
  370.  
  371.       case POINTER_TYPE:
  372.         /* We don't want "char * &" */
  373.         if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
  374.           break;
  375.         /* But we do want "char *const &" */
  376.  
  377.       default:
  378.         OB_PUTC (' ');
  379.       }
  380.       }
  381.       OB_PUTC ('&');
  382.       dump_readonly_or_volatile (t, none);
  383.       break;
  384.  
  385.     case OFFSET_TYPE:
  386.     offset_type:
  387.       dump_type_prefix (TREE_TYPE (t), v);
  388.       if (TREE_CODE (t) == OFFSET_TYPE)    /* pmfs deal with this in d_t_p */
  389.     {
  390.       OB_PUTC (' ');
  391.       dump_type (TYPE_OFFSET_BASETYPE (t), 0);
  392.       OB_PUTC2 (':', ':');
  393.     }
  394.       OB_PUTC ('*');
  395.       dump_readonly_or_volatile (t, none);
  396.       break;
  397.  
  398.       /* Can only be reached through function pointer -- this would not be
  399.          correct if FUNCTION_DECLs used it.  */
  400.     case FUNCTION_TYPE:
  401.       dump_type_prefix (TREE_TYPE (t), v);
  402.       OB_PUTC2 (' ', '(');
  403.       break;
  404.  
  405.     case METHOD_TYPE:
  406.       dump_type_prefix (TREE_TYPE (t), v);
  407.       OB_PUTC2 (' ', '(');
  408.       dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0);
  409.       OB_PUTC2 (':', ':');
  410.       break;
  411.  
  412.     case ARRAY_TYPE:
  413.       dump_type_prefix (TREE_TYPE (t), v);
  414.       break;
  415.  
  416.     case ENUMERAL_TYPE:
  417.     case ERROR_MARK:
  418.     case IDENTIFIER_NODE:
  419.     case INTEGER_TYPE:
  420.     case BOOLEAN_TYPE:
  421.     case REAL_TYPE:
  422.     case RECORD_TYPE:
  423.     case TEMPLATE_TYPE_PARM:
  424.     case TREE_LIST:
  425.     case TYPE_DECL:
  426.     case TREE_VEC:
  427.     case UNINSTANTIATED_P_TYPE:
  428.     case UNION_TYPE:
  429.     case UNKNOWN_TYPE:
  430.     case VOID_TYPE:
  431.       dump_type (t, v);
  432.       break;
  433.       
  434.     default:
  435.       sorry ("`%s' not supported by dump_type_prefix",
  436.          tree_code_name[(int) TREE_CODE (t)]);
  437.     }
  438. }
  439.  
  440. static void
  441. dump_type_suffix (t, v)
  442.      tree t;
  443.      int v;            /* verbose? */
  444. {
  445.   if (TYPE_PTRMEMFUNC_P (t))
  446.     t = TYPE_PTRMEMFUNC_FN_TYPE (t);
  447.  
  448.   switch (TREE_CODE (t))
  449.     {
  450.     case POINTER_TYPE:
  451.     case REFERENCE_TYPE:
  452.     case OFFSET_TYPE:
  453.       if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
  454.     OB_PUTC (')');
  455.       dump_type_suffix (TREE_TYPE (t), v);
  456.       break;
  457.  
  458.       /* Can only be reached through function pointer */
  459.     case FUNCTION_TYPE:
  460.     case METHOD_TYPE:
  461.       {
  462.     tree arg;
  463.     OB_PUTC2 (')', '(');
  464.     arg = TYPE_ARG_TYPES (t);
  465.     if (TREE_CODE (t) == METHOD_TYPE)
  466.       arg = TREE_CHAIN (arg);
  467.  
  468.     if (arg)
  469.       dump_type (arg, v);
  470.     else
  471.       OB_PUTS ("...");
  472.     OB_PUTC (')');
  473.     if (TREE_CODE (t) == METHOD_TYPE)
  474.       dump_readonly_or_volatile
  475.         (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
  476.     dump_type_suffix (TREE_TYPE (t), v);
  477.     break;
  478.       }
  479.  
  480.     case ARRAY_TYPE:
  481.       OB_PUTC ('[');
  482.       if (TYPE_DOMAIN (t))
  483.     OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
  484.       OB_PUTC (']');
  485.       dump_type_suffix (TREE_TYPE (t), v);
  486.       break;
  487.       
  488.     case ENUMERAL_TYPE:
  489.     case ERROR_MARK:
  490.     case IDENTIFIER_NODE:
  491.     case INTEGER_TYPE:
  492.     case BOOLEAN_TYPE:
  493.     case REAL_TYPE:
  494.     case RECORD_TYPE:
  495.     case TEMPLATE_TYPE_PARM:
  496.     case TREE_LIST:
  497.     case TYPE_DECL:
  498.     case TREE_VEC:
  499.     case UNINSTANTIATED_P_TYPE:
  500.     case UNION_TYPE:
  501.     case UNKNOWN_TYPE:
  502.     case VOID_TYPE:
  503.       break;
  504.  
  505.     default:
  506.       sorry ("`%s' not supported by dump_type_suffix",
  507.          tree_code_name[(int) TREE_CODE (t)]);
  508.     }
  509. }
  510.  
  511. /* Return a function declaration which corresponds to the IDENTIFIER_NODE
  512.    argument.  */
  513. tree
  514. ident_fndecl (t)
  515.      tree t;
  516. {
  517.   tree n = lookup_name (t, 0);
  518.  
  519.   if (n == NULL_TREE)
  520.     return NULL_TREE;
  521.  
  522.   if (TREE_CODE (n) == FUNCTION_DECL)
  523.     return n;
  524.   else if (TREE_CODE (n) == TREE_LIST
  525.        && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
  526.     return TREE_VALUE (n);
  527.  
  528.   my_friendly_abort (66);
  529.   return NULL_TREE;
  530. }
  531.  
  532. #ifndef NO_DOLLAR_IN_LABEL
  533. #  define GLOBAL_THING "_GLOBAL_$"
  534. #else
  535. #  ifndef NO_DOT_IN_LABEL
  536. #    define GLOBAL_THING "_GLOBAL_."
  537. #  else
  538. #    define GLOBAL_THING "_GLOBAL__"
  539. #  endif
  540. #endif
  541.  
  542. #define GLOBAL_IORD_P(NODE) \
  543.   !strncmp(IDENTIFIER_POINTER(NODE),GLOBAL_THING,sizeof(GLOBAL_THING)-1)
  544.  
  545. void
  546. dump_global_iord (t)
  547.      tree t;
  548. {
  549.   char *name = IDENTIFIER_POINTER (t);
  550.  
  551.   OB_PUTS ("(static ");
  552.   if (name [sizeof (GLOBAL_THING) - 1] == 'I')
  553.     OB_PUTS ("initializers");
  554.   else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
  555.     OB_PUTS ("destructors");
  556.   else
  557.     my_friendly_abort (352);
  558.   
  559.   OB_PUTS (" for ");
  560.   OB_PUTCP (input_filename);
  561.   OB_PUTC (')');
  562. }
  563.  
  564. static void
  565. dump_decl (t, v)
  566.      tree t;
  567.      int v;            /* verbosity */
  568. {
  569.   if (t == NULL_TREE)
  570.     return;
  571.  
  572.   switch (TREE_CODE (t))
  573.     {
  574.     case ERROR_MARK:
  575.       OB_PUTS (" /* decl error */ ");
  576.       break;
  577.  
  578.     case TYPE_DECL:
  579.       {
  580.     /* Don't say 'typedef class A' */
  581.     tree type = TREE_TYPE (t);
  582.         if (((IS_AGGR_TYPE (type) && ! TYPE_PTRMEMFUNC_P (type))
  583.          || TREE_CODE (type) == ENUMERAL_TYPE)
  584.         && type == TYPE_MAIN_VARIANT (type))
  585.       {
  586.         dump_type (type, v);
  587.         break;
  588.       }
  589.       }
  590.       if (v > 0)
  591.     OB_PUTS ("typedef ");
  592.       goto general;
  593.       break;
  594.       
  595.     case VAR_DECL:
  596.       if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
  597.     {
  598.       OB_PUTS ("vtable for ");
  599.       dump_type (DECL_CONTEXT (t), v);
  600.       break;
  601.     }
  602.       /* else fall through */
  603.     case FIELD_DECL:
  604.     case PARM_DECL:
  605.     general:
  606.       if (v > 0)
  607.     {
  608.       dump_type_prefix (TREE_TYPE (t), v);
  609.       OB_PUTC (' ');
  610.       dump_readonly_or_volatile (t, after);
  611.     }
  612.       /* DECL_CLASS_CONTEXT isn't being set in some cases.  Hmm...  */
  613.       if (DECL_CONTEXT (t)
  614.       && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't')
  615.     {
  616.       dump_type (DECL_CONTEXT (t), 0);
  617.       OB_PUTC2 (':', ':');
  618.     }
  619.       if (DECL_NAME (t))
  620.     dump_decl (DECL_NAME (t), v);
  621.       else
  622.     OB_PUTS ("{anon}");
  623.       if (v > 0)
  624.     dump_type_suffix (TREE_TYPE (t), v);
  625.       break;
  626.  
  627.     case NAMESPACE_DECL:
  628.       OB_PUTID (DECL_NAME (t));
  629.       break;
  630.  
  631.     case ARRAY_REF:
  632.       dump_decl (TREE_OPERAND (t, 0), v);
  633.       OB_PUTC ('[');
  634.       dump_decl (TREE_OPERAND (t, 1), v);
  635.       OB_PUTC (']');
  636.       break;
  637.  
  638.       /* So that we can do dump_decl in dump_aggr_type and have it work for
  639.      both class and function scope.  */
  640.     case RECORD_TYPE:
  641.     case UNION_TYPE:
  642.     case ENUMERAL_TYPE:
  643.       dump_type (t, v);
  644.       break;
  645.  
  646.     case TYPE_EXPR:
  647.       my_friendly_abort (69);
  648.       break;
  649.  
  650.       /* These special cases are duplicated here so that other functions
  651.      can feed identifiers to cp_error and get them demangled properly. */
  652.     case IDENTIFIER_NODE:
  653.       { tree f;
  654.     if (DESTRUCTOR_NAME_P (t)
  655.         && (f = ident_fndecl (t))
  656.         && DECL_LANGUAGE (f) == lang_cplusplus)
  657.       {
  658.         OB_PUTC ('~');
  659.         dump_decl (DECL_NAME (f), 0);
  660.       }
  661.     else if (IDENTIFIER_TYPENAME_P (t))
  662.       {
  663.         OB_PUTS ("operator ");
  664.         /* Not exactly IDENTIFIER_TYPE_VALUE.  */
  665.         dump_type (TREE_TYPE (t), 0);
  666.         break;
  667.       }
  668.     else if (IDENTIFIER_OPNAME_P (t))
  669.       {
  670.         char *name_string = operator_name_string (t);
  671.         OB_PUTS ("operator ");
  672.         OB_PUTCP (name_string);
  673.       }
  674.     else
  675.       OB_PUTID (t);
  676.       }
  677.       break;
  678.  
  679.     case FUNCTION_DECL:
  680.       if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
  681.     dump_global_iord (DECL_ASSEMBLER_NAME (t));
  682.       else
  683.     dump_function_decl (t, v);
  684.       break;
  685.  
  686.     case TEMPLATE_DECL:
  687.       {
  688.     tree args = DECL_TEMPLATE_PARMS (t);
  689.     int i, len = args ? TREE_VEC_LENGTH (args) : 0;
  690.     OB_PUTS ("template <");
  691.     for (i = 0; i < len; i++)
  692.       {
  693.         tree arg = TREE_VEC_ELT (args, i);
  694.         tree defval = TREE_PURPOSE (arg);
  695.         arg = TREE_VALUE (arg);
  696.         if (TREE_CODE (arg) == TYPE_DECL)
  697.           {
  698.         OB_PUTS ("class ");
  699.         OB_PUTID (DECL_NAME (arg));
  700.           }
  701.         else
  702.           dump_decl (arg, 1);
  703.  
  704.         if (defval)
  705.           {
  706.         OB_PUTS (" = ");
  707.         dump_decl (defval, 1);
  708.           }
  709.         
  710.         OB_PUTC2 (',', ' ');
  711.       }
  712.     if (len != 0)
  713.       OB_UNPUT (2);
  714.     OB_PUTC2 ('>', ' ');
  715.  
  716.     if (DECL_TEMPLATE_IS_CLASS (t))
  717.       {
  718.         OB_PUTS ("class ");
  719.         OB_PUTID (DECL_NAME (t));
  720.       }
  721.     else switch (NEXT_CODE (t))
  722.       {
  723.       case METHOD_TYPE:
  724.       case FUNCTION_TYPE:
  725.         dump_function_decl (t, v);
  726.         break;
  727.  
  728.       default:
  729.         my_friendly_abort (353);
  730.       }
  731.       }
  732.       break;
  733.  
  734.     case LABEL_DECL:
  735.       OB_PUTID (DECL_NAME (t));
  736.       break;
  737.  
  738.     case CONST_DECL:
  739.       if (NEXT_CODE (t) == ENUMERAL_TYPE)
  740.     goto general;
  741.       else
  742.     dump_expr (DECL_INITIAL (t), 0);
  743.       break;
  744.  
  745. #ifdef OBJCPLUS
  746.     case INSTANCE_METHOD_DECL:
  747.     case CLASS_METHOD_DECL:
  748.     dump_decl (METHOD_DEFINITION (t), v);
  749.     break;
  750. #endif
  751.  
  752.     default:
  753.       sorry ("`%s' not supported by dump_decl",
  754.          tree_code_name[(int) TREE_CODE (t)]);
  755.     }
  756. }
  757.  
  758. /* Pretty printing for announce_function.  T is the declaration of the
  759.    function we are interested in seeing.  V is non-zero if we should print
  760.    the type that this function returns.  */
  761.  
  762. static void
  763. dump_function_decl (t, v)
  764.      tree t;
  765.      int v;
  766. {
  767.   tree name = DECL_ASSEMBLER_NAME (t);
  768.   tree fntype = TREE_TYPE (t);
  769.   tree parmtypes = TYPE_ARG_TYPES (fntype);
  770.   tree cname = NULL_TREE;
  771.  
  772.   /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT.  */
  773.   if (DECL_CONTEXT (t))
  774.     cname = DECL_CLASS_CONTEXT (t);
  775.   /* this is for partially instantiated template methods */
  776.   else if (TREE_CODE (fntype) == METHOD_TYPE)
  777.     cname = TREE_TYPE (TREE_VALUE (parmtypes));
  778.  
  779.   v = (v > 0);
  780.   
  781.   if (v)
  782.     {
  783.       if (DECL_STATIC_FUNCTION_P (t))
  784.     OB_PUTS ("static ");
  785.     
  786.       if (! IDENTIFIER_TYPENAME_P (name)
  787.       && ! DECL_CONSTRUCTOR_P (t)
  788.       && ! DESTRUCTOR_NAME_P (name))
  789.     {
  790.       dump_type_prefix (TREE_TYPE (fntype), 1);
  791.       OB_PUTC (' ');
  792.     }
  793.     }
  794.  
  795.   if (cname)
  796.     {
  797.       dump_type (cname, 0);
  798.       OB_PUTC2 (':', ':');
  799.       if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
  800.     parmtypes = TREE_CHAIN (parmtypes);
  801.       if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
  802.     /* Skip past "in_charge" identifier.  */
  803.     parmtypes = TREE_CHAIN (parmtypes);
  804.     }
  805.  
  806.   if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
  807.     parmtypes = TREE_CHAIN (parmtypes);
  808.   
  809.   dump_function_name (t);
  810.   
  811.   OB_PUTC ('(');
  812.  
  813.   if (parmtypes)
  814.     dump_type (parmtypes, v);
  815.   else
  816.     OB_PUTS ("...");
  817.  
  818.   OB_PUTC (')');
  819.  
  820.   if (v && ! IDENTIFIER_TYPENAME_P (name))
  821.     dump_type_suffix (TREE_TYPE (fntype), 1);
  822.  
  823.   if (TREE_CODE (fntype) == METHOD_TYPE)
  824.     {
  825.       if (IS_SIGNATURE (cname))
  826.     /* We look at the type pointed to by the `optr' field of `this.'  */
  827.     dump_readonly_or_volatile
  828.       (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
  829.       else
  830.     dump_readonly_or_volatile
  831.       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
  832.     }
  833. }
  834.  
  835. /* Handle the function name for a FUNCTION_DECL node, grokking operators
  836.    and destructors properly.  */
  837. static void
  838. dump_function_name (t)
  839.      tree t;
  840. {
  841.   tree name = DECL_NAME (t);
  842.  
  843.   /* There ought to be a better way to find out whether or not something is
  844.      a destructor.  */
  845.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
  846.       && DECL_LANGUAGE (t) == lang_cplusplus)
  847.     {
  848.       OB_PUTC ('~');
  849.       dump_decl (name, 0);
  850.     }
  851.   else if (IDENTIFIER_TYPENAME_P (name))
  852.     {
  853.       /* This cannot use the hack that the operator's return
  854.      type is stashed off of its name because it may be
  855.      used for error reporting.  In the case of conflicting
  856.      declarations, both will have the same name, yet
  857.      the types will be different, hence the TREE_TYPE field
  858.      of the first name will be clobbered by the second.  */
  859.       OB_PUTS ("operator ");
  860.       dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
  861.     }
  862.   else if (IDENTIFIER_OPNAME_P (name))
  863.     {
  864.       char *name_string = operator_name_string (name);
  865.       OB_PUTS ("operator ");
  866.       OB_PUTCP (name_string);
  867.     }
  868.   else
  869.     dump_decl (name, 0);
  870. }
  871.  
  872. static void
  873. dump_char (c)
  874.      char c;
  875. {
  876.   switch (c)
  877.     {
  878.     case TARGET_NEWLINE:
  879.       OB_PUTS ("\\n");
  880.       break;
  881.     case TARGET_TAB:
  882.       OB_PUTS ("\\t");
  883.       break;
  884.     case TARGET_VT:
  885.       OB_PUTS ("\\v");
  886.       break;
  887.     case TARGET_BS:
  888.       OB_PUTS ("\\b");
  889.       break;
  890.     case TARGET_CR:
  891.       OB_PUTS ("\\r");
  892.       break;
  893.     case TARGET_FF:
  894.       OB_PUTS ("\\f");
  895.       break;
  896.     case TARGET_BELL:
  897.       OB_PUTS ("\\a");
  898.       break;
  899.     case '\\':
  900.       OB_PUTS ("\\\\");
  901.       break;
  902.     case '\'':
  903.       OB_PUTS ("\\'");
  904.       break;
  905.     case '\"':
  906.       OB_PUTS ("\\\"");
  907.       break;
  908.     default:
  909.       if (isprint (c))
  910.     OB_PUTC (c);
  911.       else
  912.     {
  913.       sprintf (digit_buffer, "\\%03o", (int) c);
  914.       OB_PUTCP (digit_buffer);
  915.     }
  916.     }
  917. }
  918.  
  919. /* Print out a list of initializers (subr of dump_expr) */
  920. static void
  921. dump_expr_list (l)
  922.      tree l;
  923. {
  924.   while (l)
  925.     {
  926.       dump_expr (TREE_VALUE (l), 0);
  927.       if (TREE_CHAIN (l))
  928.     OB_PUTC2 (',', ' ');
  929.       l = TREE_CHAIN (l);
  930.     }
  931. }
  932.  
  933. /* Print out an expression */
  934. static void
  935. dump_expr (t, nop)
  936.      tree t;
  937.      int nop;            /* suppress parens */
  938. {
  939.   switch (TREE_CODE (t))
  940.     {
  941.     case VAR_DECL:
  942.     case PARM_DECL:
  943.     case FIELD_DECL:
  944.     case CONST_DECL:
  945.     case FUNCTION_DECL:
  946.       dump_decl (t, -1);
  947.       break;
  948.  
  949.     case INTEGER_CST:
  950.       {
  951.     tree type = TREE_TYPE (t);
  952.     my_friendly_assert (type != 0, 81);
  953.  
  954.     /* If it's an enum, output its tag, rather than its value.  */
  955.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  956.       {
  957.         char *p = enum_name_string (t, type);
  958.         OB_PUTCP (p);
  959.       }
  960.     else if (type == boolean_type_node)
  961.       {
  962.         if (t == boolean_false_node)
  963.           OB_PUTS ("false");
  964.         else if (t == boolean_true_node)
  965.           OB_PUTS ("true");
  966.         else
  967.           my_friendly_abort (366);
  968.       }
  969.     else if (type == char_type_node)
  970.       {
  971.         OB_PUTC ('\'');
  972.         dump_char (TREE_INT_CST_LOW (t));
  973.         OB_PUTC ('\'');
  974.       }
  975.     else if (TREE_INT_CST_HIGH (t)
  976.          != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
  977.       {
  978.         tree val = t;
  979.         if (TREE_INT_CST_HIGH (val) < 0)
  980.           {
  981.         OB_PUTC ('-');
  982.         val = build_int_2 (~TREE_INT_CST_LOW (val),
  983.                    -TREE_INT_CST_HIGH (val));
  984.           }
  985.         /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
  986.            systems?  */
  987.         {
  988.           static char format[10]; /* "%x%09999x\0" */
  989.           if (!format[0])
  990.         sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
  991.           sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
  992.                TREE_INT_CST_LOW (val));
  993.           OB_PUTCP (digit_buffer);
  994.         }
  995.       }
  996.     else
  997.       OB_PUTI (TREE_INT_CST_LOW (t));
  998.       }
  999.       break;
  1000.  
  1001.     case REAL_CST:
  1002. #ifndef REAL_IS_NOT_DOUBLE
  1003.       sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
  1004. #else
  1005.       {
  1006.     unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
  1007.     int i;
  1008.     strcpy (digit_buffer, "0x");
  1009.     for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
  1010.       sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
  1011.       }
  1012. #endif
  1013.       OB_PUTCP (digit_buffer);
  1014.       break;
  1015.  
  1016.     case STRING_CST:
  1017.       {
  1018.     char *p = TREE_STRING_POINTER (t);
  1019.     int len = TREE_STRING_LENGTH (t) - 1;
  1020.     int i;
  1021.  
  1022.     OB_PUTC ('\"');
  1023.     for (i = 0; i < len; i++)
  1024.       dump_char (p[i]);
  1025.     OB_PUTC ('\"');
  1026.       }
  1027.       break;
  1028.  
  1029.     case COMPOUND_EXPR:
  1030.       dump_binary_op (",", t);
  1031.       break;
  1032.  
  1033.     case COND_EXPR:
  1034.       OB_PUTC ('(');
  1035.       dump_expr (TREE_OPERAND (t, 0), 0);
  1036.       OB_PUTS (" ? ");
  1037.       dump_expr (TREE_OPERAND (t, 1), 0);
  1038.       OB_PUTS (" : ");
  1039.       dump_expr (TREE_OPERAND (t, 2), 0);
  1040.       OB_PUTC (')');
  1041.       break;
  1042.  
  1043.     case SAVE_EXPR:
  1044.       if (TREE_HAS_CONSTRUCTOR (t))
  1045.     {
  1046.       OB_PUTS ("new ");
  1047.       dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
  1048.       PARM_DECL_EXPR (t) = 1;
  1049.     }
  1050.       else
  1051.     {
  1052.       dump_expr (TREE_OPERAND (t, 0), 0);
  1053.     }
  1054.       break;
  1055.  
  1056.     case NEW_EXPR:
  1057.       OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
  1058.       OB_PUTC ('(');
  1059.       dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  1060.       OB_PUTC (')');
  1061.       break;
  1062.  
  1063.     case CALL_EXPR:
  1064.       {
  1065.     tree fn = TREE_OPERAND (t, 0);
  1066.     tree args = TREE_OPERAND (t, 1);
  1067.     
  1068.     if (TREE_CODE (fn) == ADDR_EXPR)
  1069.       fn = TREE_OPERAND (fn, 0);
  1070.  
  1071.     if (NEXT_CODE (fn) == METHOD_TYPE)
  1072.       {
  1073.         tree ob = TREE_VALUE (args);
  1074.         if (TREE_CODE (ob) == ADDR_EXPR)
  1075.           {
  1076.         dump_expr (TREE_OPERAND (ob, 0), 0);
  1077.         OB_PUTC ('.');
  1078.           }
  1079.         else if (TREE_CODE (ob) != PARM_DECL
  1080.              || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
  1081.           {
  1082.         dump_expr (ob, 0);
  1083.         OB_PUTC2 ('-', '>');
  1084.           }
  1085.         args = TREE_CHAIN (args);
  1086.       }
  1087.     dump_expr (fn, 0);
  1088.     OB_PUTC('(');
  1089.     dump_expr_list (args);
  1090.     OB_PUTC (')');
  1091.       }
  1092.       break;
  1093.  
  1094.     case WITH_CLEANUP_EXPR:
  1095.       /* Note that this only works for G++ cleanups.  If somebody
  1096.      builds a general cleanup, there's no way to represent it.  */
  1097.       dump_expr (TREE_OPERAND (t, 0), 0);
  1098.       break;
  1099.  
  1100.     case TARGET_EXPR:
  1101.       /* Note that this only works for G++ target exprs.  If somebody
  1102.      builds a general TARGET_EXPR, there's no way to represent that
  1103.      it initializes anything other that the parameter slot for the
  1104.      default argument.  Note we may have cleared out the first
  1105.      operand in expand_expr, so don't go killing ourselves.  */
  1106.       if (TREE_OPERAND (t, 1))
  1107.     dump_expr (TREE_OPERAND (t, 1), 0);
  1108.       break;
  1109.  
  1110.     case MODIFY_EXPR:
  1111.     case PLUS_EXPR:
  1112.     case MINUS_EXPR:
  1113.     case MULT_EXPR:
  1114.     case TRUNC_DIV_EXPR:
  1115.     case TRUNC_MOD_EXPR:
  1116.     case MIN_EXPR:
  1117.     case MAX_EXPR:
  1118.     case LSHIFT_EXPR:
  1119.     case RSHIFT_EXPR:
  1120.     case BIT_IOR_EXPR:
  1121.     case BIT_XOR_EXPR:
  1122.     case BIT_AND_EXPR:
  1123.     case BIT_ANDTC_EXPR:
  1124.     case TRUTH_ANDIF_EXPR:
  1125.     case TRUTH_ORIF_EXPR:
  1126.     case LT_EXPR:
  1127.     case LE_EXPR:
  1128.     case GT_EXPR:
  1129.     case GE_EXPR:
  1130.     case EQ_EXPR:
  1131.     case NE_EXPR:
  1132.       dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
  1133.       break;
  1134.  
  1135.     case CEIL_DIV_EXPR:
  1136.     case FLOOR_DIV_EXPR:
  1137.     case ROUND_DIV_EXPR:
  1138.       dump_binary_op ("/", t);
  1139.       break;
  1140.  
  1141.     case CEIL_MOD_EXPR:
  1142.     case FLOOR_MOD_EXPR:
  1143.     case ROUND_MOD_EXPR:
  1144.       dump_binary_op ("%", t);
  1145.       break;
  1146.  
  1147.     case COMPONENT_REF:
  1148.       {
  1149.     tree ob = TREE_OPERAND (t, 0);
  1150.     if (TREE_CODE (ob) == INDIRECT_REF)
  1151.       {
  1152.         ob = TREE_OPERAND (ob, 0);
  1153.         if (TREE_CODE (ob) != PARM_DECL
  1154.         || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
  1155.           {
  1156.         dump_expr (ob, 0);
  1157.         OB_PUTC2 ('-', '>');
  1158.           }
  1159.       }
  1160.     else
  1161.       {
  1162.         dump_expr (ob, 0);
  1163.         OB_PUTC ('.');
  1164.       }
  1165.     dump_expr (TREE_OPERAND (t, 1), 1);
  1166.       }
  1167.       break;
  1168.  
  1169.     case ARRAY_REF:
  1170.       dump_expr (TREE_OPERAND (t, 0), 0);
  1171.       OB_PUTC ('[');
  1172.       dump_expr (TREE_OPERAND (t, 1), 0);
  1173.       OB_PUTC (']');
  1174.       break;
  1175.  
  1176.     case CONVERT_EXPR:
  1177.       dump_unary_op ("+", t, nop);
  1178.       break;
  1179.  
  1180.     case ADDR_EXPR:
  1181.       if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
  1182.       || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
  1183.     dump_expr (TREE_OPERAND (t, 0), 0);
  1184.       else
  1185.     dump_unary_op ("&", t, nop);
  1186.       break;
  1187.  
  1188.     case INDIRECT_REF:
  1189.       if (TREE_HAS_CONSTRUCTOR (t))
  1190.     {
  1191.       t = TREE_OPERAND (t, 0);
  1192.       my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
  1193.       dump_expr (TREE_OPERAND (t, 0), 0);
  1194.       OB_PUTC ('(');
  1195.       dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  1196.       OB_PUTC (')');
  1197.     }
  1198.       else
  1199.     {
  1200.       if (NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
  1201.         dump_expr (TREE_OPERAND (t, 0), nop);
  1202.       else
  1203.         dump_unary_op ("*", t, nop);
  1204.     }
  1205.       break;
  1206.  
  1207.     case NEGATE_EXPR:
  1208.     case BIT_NOT_EXPR:
  1209.     case TRUTH_NOT_EXPR:
  1210.     case PREDECREMENT_EXPR:
  1211.     case PREINCREMENT_EXPR:
  1212.       dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
  1213.       break;
  1214.  
  1215.     case POSTDECREMENT_EXPR:
  1216.     case POSTINCREMENT_EXPR:
  1217.       OB_PUTC ('(');
  1218.       dump_expr (TREE_OPERAND (t, 0), 0);
  1219.       OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
  1220.       OB_PUTC (')');
  1221.       break;
  1222.  
  1223.     case NON_LVALUE_EXPR:
  1224.       /* FIXME: This is a KLUDGE workaround for a parsing problem.  There
  1225.      should be another level of INDIRECT_REF so that I don't have to do
  1226.      this.  */
  1227.       if (NEXT_CODE (t) == POINTER_TYPE)
  1228.     {
  1229.       tree next = TREE_TYPE (TREE_TYPE (t));
  1230.  
  1231.       while (TREE_CODE (next) == POINTER_TYPE)
  1232.         next = TREE_TYPE (next);
  1233.       
  1234.       if (TREE_CODE (next) == FUNCTION_TYPE)
  1235.         {
  1236.           if (!nop) OB_PUTC ('(');
  1237.           OB_PUTC ('*');
  1238.           dump_expr (TREE_OPERAND (t, 0), 1);
  1239.           if (!nop) OB_PUTC (')');
  1240.           break;
  1241.         }
  1242.       /* else FALLTHRU */
  1243.     }
  1244.       dump_expr (TREE_OPERAND (t, 0), 0);
  1245.       break;
  1246.  
  1247.     case NOP_EXPR:
  1248.       dump_expr (TREE_OPERAND (t, 0), nop);
  1249.       break;
  1250.  
  1251.     case CONSTRUCTOR:
  1252.       OB_PUTC ('{');
  1253.       dump_expr_list (CONSTRUCTOR_ELTS (t), 0);
  1254.       OB_PUTC ('}');
  1255.       break;
  1256.  
  1257.     case OFFSET_REF:
  1258.       {
  1259.     tree ob = TREE_OPERAND (t, 0);
  1260.     if (TREE_CODE (ob) == NOP_EXPR
  1261.         && TREE_OPERAND (ob, 0) == error_mark_node
  1262.         && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
  1263.         /* A::f */
  1264.       dump_expr (TREE_OPERAND (t, 1), 0);
  1265.     else
  1266.       {
  1267.         sorry ("operand of OFFSET_REF not understood");
  1268.         goto error;
  1269.       }
  1270.     break;
  1271.       }
  1272.  
  1273.     case TREE_LIST:
  1274.       if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
  1275.     {
  1276.       OB_PUTID (DECL_NAME (TREE_VALUE (t)));
  1277.       break;
  1278.     }
  1279.       /* else fall through */    
  1280.  
  1281.       /*  This list is incomplete, but should suffice for now.
  1282.       It is very important that `sorry' does not call
  1283.       `report_error_function'.  That could cause an infinite loop.  */
  1284.     default:
  1285.       sorry ("`%s' not supported by dump_expr",
  1286.          tree_code_name[(int) TREE_CODE (t)]);
  1287.  
  1288.       /* fall through to ERROR_MARK...  */
  1289.     case ERROR_MARK:
  1290.     error:
  1291.       OB_PUTCP ("{error}");
  1292.       break;
  1293.     }
  1294. }
  1295.  
  1296. static void
  1297. dump_binary_op (opstring, t)
  1298.      char *opstring;
  1299.      tree t;
  1300. {
  1301.   OB_PUTC ('(');
  1302.   dump_expr (TREE_OPERAND (t, 0), 1);
  1303.   OB_PUTC (' ');
  1304.   OB_PUTCP (opstring);
  1305.   OB_PUTC (' ');
  1306.   dump_expr (TREE_OPERAND (t, 1), 1);
  1307.   OB_PUTC (')');
  1308. }
  1309.  
  1310. static void
  1311. dump_unary_op (opstring, t, nop)
  1312.      char *opstring;
  1313.      tree t;
  1314.      int nop;
  1315. {
  1316.   if (!nop) OB_PUTC ('(');
  1317.   OB_PUTCP (opstring);
  1318.   dump_expr (TREE_OPERAND (t, 0), 1);
  1319.   if (!nop) OB_PUTC (')');
  1320. }
  1321.  
  1322. char *
  1323. fndecl_as_string (cname, fndecl, print_ret_type_p)
  1324.      tree cname, fndecl;
  1325.      int print_ret_type_p;
  1326. {
  1327.   return decl_as_string (fndecl, print_ret_type_p);
  1328. }
  1329.  
  1330. /* Same, but handtype a _TYPE.
  1331.    Called from convert_to_reference, mangle_class_name_for_template,
  1332.    build_unary_op, and GNU_xref_decl.  */
  1333. char *
  1334. type_as_string (typ, v)
  1335.      tree typ;
  1336.      int v;
  1337. {
  1338.   OB_INIT ();
  1339.  
  1340.   dump_type (typ, v);
  1341.  
  1342.   OB_FINISH ();
  1343.  
  1344.   return (char *)obstack_base (&scratch_obstack);
  1345. }
  1346.  
  1347. char *
  1348. expr_as_string (decl, v)
  1349.      tree decl;
  1350.      int v;
  1351. {
  1352.   OB_INIT ();
  1353.  
  1354.   dump_expr (decl, 1);
  1355.  
  1356.   OB_FINISH ();
  1357.  
  1358.   return (char *)obstack_base (&scratch_obstack);
  1359. }
  1360.  
  1361. /* A cross between type_as_string and fndecl_as_string.
  1362.    Only called from substitute_nice_name.  */
  1363. char *
  1364. decl_as_string (decl, v)
  1365.      tree decl;
  1366.      int v;
  1367. {
  1368.   OB_INIT ();
  1369.  
  1370.   dump_decl (decl, v);
  1371.  
  1372.   OB_FINISH ();
  1373.  
  1374.   return (char *)obstack_base (&scratch_obstack);
  1375. }
  1376.  
  1377. char *
  1378. cp_file_of (t)
  1379.      tree t;
  1380. {
  1381.   if (TREE_CODE (t) == PARM_DECL)
  1382.     return DECL_SOURCE_FILE (DECL_CONTEXT (t));
  1383.   else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
  1384.     return DECL_SOURCE_FILE (TYPE_NAME (t));
  1385.   else
  1386.     return DECL_SOURCE_FILE (t);
  1387. }
  1388.  
  1389. int
  1390. cp_line_of (t)
  1391.      tree t;
  1392. {
  1393.   int line = 0;
  1394.   if (TREE_CODE (t) == PARM_DECL)
  1395.     line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
  1396.   if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
  1397.     t = TREE_TYPE (t);
  1398.  
  1399.   if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
  1400.     {
  1401.       if (IS_AGGR_TYPE (t))
  1402.     line = CLASSTYPE_SOURCE_LINE (t);
  1403.       else
  1404.     line = DECL_SOURCE_LINE (TYPE_NAME (t));
  1405.     }
  1406.   else
  1407.     line = DECL_SOURCE_LINE (t);
  1408.  
  1409.   if (line == 0)
  1410.     return lineno;
  1411.  
  1412.   return line;
  1413. }
  1414.  
  1415. char *
  1416. code_as_string (c, v)
  1417.      enum tree_code c;
  1418.      int v;
  1419. {
  1420.   return tree_code_name [c];
  1421. }
  1422.  
  1423. char *
  1424. language_as_string (c, v)
  1425.      enum languages c;
  1426.      int v;
  1427. {
  1428.   switch (c)
  1429.     {
  1430.     case lang_c:
  1431.       return "C";
  1432.  
  1433. #ifdef OBJCPLUS
  1434.     case lang_objc:
  1435.       return "Objective-C";
  1436. #endif
  1437.  
  1438.     case lang_cplusplus:
  1439.       return "C++";
  1440.  
  1441.     default:
  1442.       my_friendly_abort (355);
  1443.       return 0;
  1444.     }
  1445. }
  1446.  
  1447. /* Return the proper printed version of a parameter to a C++ function.  */
  1448. char *
  1449. parm_as_string (p, v)
  1450.      int p, v;
  1451. {
  1452.   if (p < 0)
  1453.     return "`this'";
  1454.  
  1455.   sprintf (digit_buffer, "%d", p+1);
  1456.   return digit_buffer;
  1457. }
  1458.  
  1459. char *
  1460. op_as_string (p, v)
  1461.      enum tree_code p;
  1462.      int v;
  1463. {
  1464.   static char buf[] = "operator                ";
  1465.  
  1466.   if (p == 0)
  1467.     return "{unknown}";
  1468.   
  1469.   strcpy (buf + 9, opname_tab [p]);
  1470.   return buf;
  1471. }
  1472.  
  1473. char *
  1474. args_as_string (p, v)
  1475.      tree p;
  1476.      int v;
  1477. {
  1478.   if (p == NULL_TREE)
  1479.     return "...";
  1480.  
  1481.   return type_as_string (p, v);
  1482. }
  1483.  
  1484. char *
  1485. cv_as_string (p, v)
  1486.      tree p;
  1487.      int v;
  1488. {
  1489.   OB_INIT ();
  1490.  
  1491.   dump_readonly_or_volatile (p, before);
  1492.  
  1493.   OB_FINISH ();
  1494.  
  1495.   return (char *)obstack_base (&scratch_obstack);
  1496. }
  1497.