home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / cplus-method.c < prev    next >
C/C++ Source or Header  |  1991-06-03  |  64KB  |  2,576 lines

  1. /* Handle the hair of processing (but not expanding) inline functions.
  2.    Also manage function and varaible name overloading.
  3.    Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  4.    Contributed by Michael Tiemann (tiemann@cygnus.com)
  5.  
  6.    This file is part of GNU CC.
  7.    
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. /* Handle method declarations.  */
  24. #include <stdio.h>
  25. #include "config.h"
  26. #include "tree.h"
  27. #include "cplus-tree.h"
  28. #include "assert.h"
  29.  
  30. /* TREE_LIST of the current inline functions that need to be
  31.    processed.  */
  32. struct pending_inline *pending_inlines;
  33.  
  34. # define MAX_INLINE_BUF_SIZE 8188
  35. # define OB_INIT() (inline_bufp = inline_buffer)
  36. # define OB_PUTC(C) (*inline_bufp++ = (C))
  37. # define OB_PUTC2(C1,C2) (OB_PUTC (C1), OB_PUTC (C2))
  38. # define OB_PUTS(S) (strcpy (inline_bufp, S), inline_bufp += sizeof (S) - 1)
  39. # define OB_PUTCP(S) (strcpy (inline_bufp, S), inline_bufp += strlen (S))
  40. # define OB_FINISH() (*inline_bufp++ = '\0')
  41.  
  42. /* Counter to help build parameter names in case they were omitted.  */
  43. static int dummy_name;
  44. static int in_parmlist;
  45. /* Just a pointer into INLINE_BUFFER.  */
  46. static char *inline_bufp;
  47. /* Also a pointer into INLINE_BUFFER.  This points to a safe place to
  48.    cut back to if we assign it 0, in case of error.  */
  49. static char *inline_errp;
  50. static char *inline_buffer;
  51. static void dump_type (), dump_decl ();
  52. static void dump_init (), dump_unary_op (), dump_binary_op ();
  53.  
  54. tree wrapper_name, wrapper_pred_name, anti_wrapper_name;
  55.  
  56. #ifdef NO_AUTO_OVERLOAD
  57. int is_overloaded ();
  58. #endif
  59.  
  60. void
  61. init_method ()
  62. {
  63.   char buf[sizeof (ANTI_WRAPPER_NAME_FORMAT) + 8];
  64.   sprintf (buf, WRAPPER_NAME_FORMAT, "");
  65.   wrapper_name = get_identifier (buf);
  66.   sprintf (buf, WRAPPER_PRED_NAME_FORMAT, "");
  67.   wrapper_pred_name = get_identifier (buf);
  68.   sprintf (buf, ANTI_WRAPPER_NAME_FORMAT, "");
  69.   anti_wrapper_name = get_identifier (buf);
  70. }
  71.  
  72. /* Check that we have not overflowed INLINE_BUFFER.
  73.    We cannot use `fatal' or `error' in here because that
  74.    might cause an infinite loop.  */
  75. static void
  76. check_text_len (s)
  77.      char *s;
  78. {
  79.   if (s >= inline_buffer + MAX_INLINE_BUF_SIZE)
  80.     {
  81.       fprintf (stderr,
  82.          "recompile cc1plus with larger MAX_INLINE_BUF_SIZE (at least %d)",
  83.            s - inline_buffer + 1);
  84.       abort ();
  85.     }
  86. }
  87.  
  88. /* Return a pointer to the end of the new text in INLINE_BUFFER.
  89.    We cannot use `fatal' or `error' in here because that
  90.    might cause an infinite loop.  */
  91. static char *
  92. new_text_len (s)
  93.      char *s;
  94. {
  95.   while (*s++) ;
  96.  
  97.   if (s >= inline_buffer + MAX_INLINE_BUF_SIZE)
  98.     {
  99.       fprintf (stderr, "recompile c++ with larger MAX_INLINE_BUF_SIZE (%d)", MAX_INLINE_BUF_SIZE);
  100.       abort ();
  101.     }
  102.   return s - 1;
  103. }
  104.  
  105. tree
  106. make_anon_parm_name ()
  107. {
  108.   char buf[32];
  109.  
  110.   sprintf (buf, ANON_PARMNAME_FORMAT, dummy_name++);
  111.   return get_identifier (buf);
  112. }
  113.  
  114. void
  115. clear_anon_parm_name ()
  116. {
  117.   /* recycle these names.  */
  118.   dummy_name = 0;
  119. }
  120.  
  121. static void
  122. dump_readonly_or_volatile (t)
  123.      tree t;
  124. {
  125.   if (TYPE_READONLY (t))
  126.     OB_PUTS ("const ");
  127.   if (TYPE_VOLATILE (t))
  128.     OB_PUTS ("volatile ");
  129. }
  130.  
  131. static void
  132. dump_type_prefix (t, p)
  133.      tree t;
  134.      int *p;
  135. {
  136.   int old_p = 0;
  137.   int print_struct = 1;
  138.   tree name;
  139.  
  140.   if (t == NULL_TREE)
  141.     return;
  142.  
  143.   switch (TREE_CODE (t))
  144.     {
  145.     case ERROR_MARK:
  146.       sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
  147.       break;
  148.  
  149.     case UNKNOWN_TYPE:
  150.       OB_PUTS ("<unknown type>");
  151.       return;
  152.  
  153.     case TREE_LIST:
  154.       dump_type (TREE_VALUE (t), &old_p);
  155.       if (TREE_CHAIN (t))
  156.     {
  157.       if (TREE_CHAIN (t) != void_list_node)
  158.         {
  159.           OB_PUTC (',');
  160.           dump_type (TREE_CHAIN (t), &old_p);
  161.         }
  162.     }
  163.       else OB_PUTS ("...");
  164.       return;
  165.  
  166.     case POINTER_TYPE:
  167.       *p += 1;
  168.       dump_type_prefix (TREE_TYPE (t), p);
  169.       while (*p)
  170.     {
  171.       OB_PUTC ('*');
  172.       *p -= 1;
  173.     }
  174.       if (TYPE_READONLY (t))
  175.     OB_PUTS ("const ");
  176.       if (TYPE_VOLATILE (t))
  177.     OB_PUTS ("volatile ");
  178.       return;
  179.  
  180.     case OFFSET_TYPE:
  181.       {
  182.     tree type = TREE_TYPE (t);
  183.     if (TREE_CODE (type) == FUNCTION_TYPE)
  184.       {
  185.         type = TREE_TYPE (type);
  186.         if (in_parmlist)
  187.           OB_PUTS ("auto ");
  188.       }
  189.  
  190.     dump_type_prefix (type, &old_p);
  191.  
  192.     OB_PUTC ('(');
  193.     dump_type (TYPE_OFFSET_BASETYPE (t), &old_p);
  194.     OB_PUTC2 (':', ':');
  195.     while (*p)
  196.       {
  197.         OB_PUTC ('*');
  198.         *p -= 1;
  199.       }
  200.     if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  201.       dump_readonly_or_volatile (t);
  202.     return;
  203.       }
  204.  
  205.     case METHOD_TYPE:
  206.       {
  207.     tree type = TREE_TYPE (t);
  208.     if (in_parmlist)
  209.       OB_PUTS ("auto ");
  210.  
  211.     dump_type_prefix (type, &old_p);
  212.  
  213.     OB_PUTC ('(');
  214.     dump_type (TYPE_METHOD_BASETYPE (t), &old_p);
  215.     OB_PUTC2 (':', ':');
  216.     while (*p)
  217.       {
  218.         OB_PUTC ('*');
  219.         *p -= 1;
  220.       }
  221.     if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  222.       dump_readonly_or_volatile (t);
  223.     return;
  224.       }
  225.  
  226.     case REFERENCE_TYPE:
  227.       dump_type_prefix (TREE_TYPE (t), p);
  228.       OB_PUTC ('&');
  229.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  230.     dump_readonly_or_volatile (t);
  231.       return;
  232.  
  233.     case ARRAY_TYPE:
  234.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  235.     dump_readonly_or_volatile (t);
  236.       dump_type_prefix (TREE_TYPE (t), p);
  237.       return;
  238.  
  239.     case FUNCTION_TYPE:
  240.       if (in_parmlist)
  241.     OB_PUTS ("auto ");
  242.       dump_type_prefix (TREE_TYPE (t), &old_p);
  243.       OB_PUTC ('(');
  244.       while (*p)
  245.     {
  246.       OB_PUTC ('*');
  247.       *p -= 1;
  248.     }
  249.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  250.     dump_readonly_or_volatile (t);
  251.       return;
  252.  
  253.     case IDENTIFIER_NODE:
  254.       sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (t));
  255.       break;
  256.  
  257.     case RECORD_TYPE:
  258.       if (TYPE_READONLY (t))
  259.     OB_PUTS ("const ");
  260.       if (TYPE_VOLATILE (t))
  261.     OB_PUTS ("volatile ");
  262.       if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
  263.     print_struct = 0;
  264.       name = TYPE_NAME (t);
  265.       if (TREE_CODE (name) == TYPE_DECL)
  266.     name = DECL_NAME (name);
  267.       if (print_struct)
  268.     sprintf (inline_bufp, "struct %s ", IDENTIFIER_POINTER (name));
  269.       else
  270.     sprintf (inline_bufp, "class %s ", IDENTIFIER_POINTER (name));
  271.       break;
  272.  
  273.     case UNION_TYPE:
  274.       if (TYPE_READONLY (t))
  275.     OB_PUTS ("const ");
  276.       if (TYPE_VOLATILE (t))
  277.     OB_PUTS ("volatile ");
  278.       name = TYPE_NAME (t);
  279.       if (TREE_CODE (name) == TYPE_DECL)
  280.     name = DECL_NAME (name);
  281.       sprintf (inline_bufp, "union %s ", IDENTIFIER_POINTER (name));
  282.       break;
  283.  
  284.     case ENUMERAL_TYPE:
  285.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  286.     dump_readonly_or_volatile (t);
  287.       name = TYPE_NAME (t);
  288.       if (TREE_CODE (name) == TYPE_DECL)
  289.     name = DECL_NAME (name);
  290.       sprintf (inline_bufp, "enum %s ", IDENTIFIER_POINTER (name));
  291.       break;
  292.  
  293.     case TYPE_DECL:
  294.       if (TYPE_READONLY (t))
  295.     OB_PUTS ("const ");
  296.       if (TYPE_VOLATILE (t))
  297.     OB_PUTS ("volatile ");
  298.       sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (DECL_NAME (t)));
  299.       break;
  300.  
  301.     case INTEGER_TYPE:
  302.       /* Normally, `unsigned' is part of the deal.  Not so if it comes
  303.      with `const' or `volatile'.  */
  304.       if (TREE_UNSIGNED (t)
  305.       && (TYPE_READONLY (t) || TYPE_VOLATILE (t)))
  306.     OB_PUTS ("unsigned ");
  307.       /* fall through.  */
  308.     case REAL_TYPE:
  309.     case VOID_TYPE:
  310.       if (TYPE_READONLY (t))
  311.     OB_PUTS ("const ");
  312.       if (TYPE_VOLATILE (t))
  313.     OB_PUTS ("volatile ");
  314.       sprintf (inline_bufp, "%s ", TYPE_NAME_STRING (t));
  315.       break;
  316.  
  317.     default:
  318.       abort ();
  319.     }
  320.   inline_bufp = new_text_len (inline_bufp);
  321. }
  322.  
  323. static void
  324. dump_type_suffix (t, p)
  325.      tree t;
  326.      int *p;
  327. {
  328.   int old_p = 0;
  329.  
  330.   if (t == NULL_TREE)
  331.     return;
  332.  
  333.   switch (TREE_CODE (t))
  334.     {
  335.     case ERROR_MARK:
  336.       sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
  337.       break;
  338.  
  339.     case UNKNOWN_TYPE:
  340.       return;
  341.  
  342.     case POINTER_TYPE:
  343.       dump_type_suffix (TREE_TYPE (t), p);
  344.       return;
  345.  
  346.     case OFFSET_TYPE:
  347.       {
  348.     tree type = TREE_TYPE (t);
  349.  
  350.     OB_PUTC (')');
  351.     if (TREE_CODE (type) == FUNCTION_TYPE)
  352.       {
  353. #if 0
  354.         tree next_arg = TREE_CHAIN (TYPE_ARG_TYPES (type));
  355.         OB_PUTC ('(');
  356.         if (next_arg)
  357.           {
  358.         if (next_arg != void_list_node)
  359.           {
  360.             in_parmlist++;
  361.             dump_type (next_arg, &old_p);
  362.             in_parmlist--;
  363.           }
  364.           }
  365.         else OB_PUTS ("...");
  366.         OB_PUTC (')');
  367.         dump_type_suffix (TREE_TYPE (type), p);
  368. #else
  369.         abort ();
  370. #endif
  371.       }
  372.     return;
  373.       }
  374.  
  375.     case METHOD_TYPE:
  376.       {
  377.     tree next_arg;
  378.     OB_PUTC (')');
  379.     next_arg = TREE_CHAIN (TYPE_ARG_TYPES (t));
  380.     OB_PUTC ('(');
  381.     if (next_arg)
  382.       {
  383.         if (next_arg != void_list_node)
  384.           {
  385.         in_parmlist++;
  386.         dump_type (next_arg, &old_p);
  387.         in_parmlist--;
  388.           }
  389.       }
  390.     else OB_PUTS ("...");
  391.     OB_PUTC (')');
  392.     dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
  393.     dump_type_suffix (TREE_TYPE (t), p);
  394.     return;
  395.       }
  396.  
  397.     case REFERENCE_TYPE:
  398.       dump_type_suffix (TREE_TYPE (t), p);
  399.       return;
  400.  
  401.     case ARRAY_TYPE:
  402.       dump_type_suffix (TREE_TYPE (t), p);
  403.       OB_PUTC2 ('[', ']');
  404.       return;
  405.  
  406.     case FUNCTION_TYPE:
  407.       OB_PUTC2 (')', '(');
  408.       if (TYPE_ARG_TYPES (t) && TYPE_ARG_TYPES (t) != void_list_node)
  409.     {
  410.       in_parmlist++;
  411.       dump_type (TYPE_ARG_TYPES (t), &old_p);
  412.       in_parmlist--;
  413.     }
  414.       OB_PUTC (')');
  415.       dump_type_suffix (TREE_TYPE (t), p);
  416.       return;
  417.  
  418.     case IDENTIFIER_NODE:
  419.     case RECORD_TYPE:
  420.     case UNION_TYPE:
  421.     case ENUMERAL_TYPE:
  422.     case TYPE_DECL:
  423.     case INTEGER_TYPE:
  424.     case REAL_TYPE:
  425.     case VOID_TYPE:
  426.       return;
  427.  
  428.     default:
  429.       abort ();
  430.     }
  431.   inline_bufp = new_text_len (inline_bufp);
  432. }
  433.  
  434. static void
  435. dump_type (t, p)
  436.      tree t;
  437.      int *p;
  438. {
  439.   int old_p = 0;
  440.   int print_struct = 1;
  441.  
  442.   if (t == NULL_TREE)
  443.     return;
  444.  
  445.   switch (TREE_CODE (t))
  446.     {
  447.     case ERROR_MARK:
  448.       sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
  449.       break;
  450.  
  451.     case UNKNOWN_TYPE:
  452.       OB_PUTS ("<unknown type>");
  453.       return;
  454.  
  455.     case TREE_LIST:
  456.       dump_type (TREE_VALUE (t), &old_p);
  457.       if (TREE_CHAIN (t))
  458.     {
  459.       if (TREE_CHAIN (t) != void_list_node)
  460.         {
  461.           OB_PUTC (',');
  462.           dump_type (TREE_CHAIN (t), &old_p);
  463.         }
  464.     }
  465.       else OB_PUTS ("...");
  466.       return;
  467.  
  468.     case POINTER_TYPE:
  469.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  470.     dump_readonly_or_volatile (t);
  471.       *p += 1;
  472.       dump_type (TREE_TYPE (t), p);
  473.       while (*p)
  474.     {
  475.       OB_PUTC ('*');
  476.       *p -= 1;
  477.     }
  478.       return;
  479.  
  480.     case REFERENCE_TYPE:
  481.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  482.     dump_readonly_or_volatile (t);
  483.       dump_type (TREE_TYPE (t), p);
  484.       OB_PUTC ('&');
  485.       return;
  486.  
  487.     case ARRAY_TYPE:
  488.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  489.     dump_readonly_or_volatile (t);
  490.       dump_type (TREE_TYPE (t), p);
  491.       OB_PUTC2 ('[', ']');
  492.       return;
  493.  
  494.     case OFFSET_TYPE:
  495.     case METHOD_TYPE:
  496.     case FUNCTION_TYPE:
  497.       dump_type_prefix (t, p);
  498.       dump_type_suffix (t, p);
  499.       return;
  500.  
  501.     case IDENTIFIER_NODE:
  502.       sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (t));
  503.       break;
  504.  
  505.     case RECORD_TYPE:
  506.       {
  507.     if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  508.       dump_readonly_or_volatile (t);
  509.     if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
  510.       print_struct = 0;
  511.     t = TYPE_NAME (t);
  512.     if (TREE_CODE (t) == TYPE_DECL)
  513.       t = DECL_NAME (t);
  514.     if (print_struct)
  515.       sprintf (inline_bufp, "struct %s ", IDENTIFIER_POINTER (t));
  516.     else
  517.       sprintf (inline_bufp, "class %s ", IDENTIFIER_POINTER (t));
  518.     break;
  519.       }
  520.  
  521.     case UNION_TYPE:
  522.       {
  523.     if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  524.       dump_readonly_or_volatile (t);
  525.     t = TYPE_NAME (t);
  526.     if (TREE_CODE (t) == TYPE_DECL)
  527.       t = DECL_NAME (t);
  528.     sprintf (inline_bufp, "union %s ", IDENTIFIER_POINTER (t));
  529.       }
  530.       break;
  531.  
  532.     case ENUMERAL_TYPE:
  533.       {
  534.     if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  535.       dump_readonly_or_volatile (t);
  536.     t = TYPE_NAME (t);
  537.     if (TREE_CODE (t) == TYPE_DECL)
  538.       t = DECL_NAME (t);
  539.     sprintf (inline_bufp, "enum %s ", IDENTIFIER_POINTER (t));
  540.       }
  541.       break;
  542.  
  543.     case TYPE_DECL:
  544.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  545.     dump_readonly_or_volatile (t);
  546.       sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (DECL_NAME (t)));
  547.       break;
  548.  
  549.     case INTEGER_TYPE:
  550.       /* Normally, `unsigned' is part of the deal.  Not so if it comes
  551.      with `const' or `volatile'.  */
  552.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  553.     dump_readonly_or_volatile (t);
  554.       if (TREE_UNSIGNED (t)
  555.       && (TYPE_READONLY (t) | TYPE_VOLATILE (t)))
  556.     OB_PUTS ("unsigned ");
  557.       /* fall through.  */
  558.     case REAL_TYPE:
  559.     case VOID_TYPE:
  560.       sprintf (inline_bufp, "%s ", TYPE_NAME_STRING (t));
  561.       break;
  562.  
  563.     default:
  564.       abort ();
  565.     }
  566.   inline_bufp = new_text_len (inline_bufp);
  567. }
  568.  
  569. static void
  570. dump_decl (t)
  571.      tree t;
  572. {
  573.   int p = 0;
  574.  
  575.   if (t == NULL_TREE)
  576.     return;
  577.  
  578.   switch (TREE_CODE (t))
  579.     {
  580.     case ERROR_MARK:
  581.       strcpy (inline_bufp, " /* decl error */ ");
  582.       break;
  583.  
  584.     case PARM_DECL:
  585.       dump_type_prefix (TREE_TYPE (t), &p);
  586.       if (DECL_NAME (t))
  587.     dump_decl (DECL_NAME (t));
  588.       else
  589.     {
  590.       sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
  591.       break;
  592.     }
  593.       dump_type_suffix (TREE_TYPE (t), &p);
  594.       return;
  595.  
  596.     case CALL_EXPR:
  597.       dump_decl (TREE_OPERAND (t, 0));
  598.       OB_PUTC ('(');
  599.       in_parmlist++;
  600.       dump_decl (TREE_OPERAND (t, 1));
  601.       in_parmlist--;
  602.       t = tree_last (TYPE_ARG_TYPES (TREE_TYPE (t)));
  603.       if (!t || t != void_list_node)
  604.     OB_PUTS ("...");
  605.       OB_PUTC (')');
  606.       return;
  607.  
  608.     case ARRAY_REF:
  609.       dump_decl (TREE_OPERAND (t, 0));
  610.       OB_PUTC ('[');
  611.       dump_decl (TREE_OPERAND (t, 1));
  612.       OB_PUTC (']');
  613.       return;
  614.  
  615.     case TYPE_DECL:
  616.       sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (DECL_NAME (t)));
  617.       break;
  618.  
  619.     case TYPE_EXPR:
  620.       abort ();
  621.       break;
  622.  
  623.     case IDENTIFIER_NODE:
  624.       if (OPERATOR_NAME_P (t))
  625.     sprintf (inline_bufp, "operator %s ", operator_name_string (t));
  626.       else if (OPERATOR_TYPENAME_P (t))
  627.     {
  628.       OB_PUTS ("operator ");
  629.       /* Not exactly IDENTIFIER_TYPE_VALUE.  */
  630.       dump_type (TREE_TYPE (t), &p);
  631.       return;
  632.     }
  633.       else
  634.     sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (t));
  635.       break;
  636.  
  637.     case BIT_NOT_EXPR:
  638.       OB_PUTC2 ('~', ' ');
  639.       dump_decl (TREE_OPERAND (t, 0));
  640.       return;
  641.  
  642.     case SCOPE_REF:
  643.       sprintf (inline_bufp, "%s :: ", IDENTIFIER_POINTER (TREE_OPERAND (t, 0)));
  644.       inline_bufp += sizeof ("%s :: ") + IDENTIFIER_LENGTH (TREE_OPERAND (t, 0));
  645.       dump_decl (TREE_OPERAND (t, 1));
  646.       return;
  647.  
  648.     case INDIRECT_REF:
  649.       OB_PUTC ('*');
  650.       dump_decl (TREE_OPERAND (t, 0));
  651.       return;
  652.  
  653.     case ADDR_EXPR:
  654.       OB_PUTC ('&');
  655.       dump_decl (TREE_OPERAND (t, 0));
  656.       return;
  657.  
  658.     default:
  659.       abort ();
  660.     }
  661.   inline_bufp = new_text_len (inline_bufp);
  662. }
  663.  
  664. static void
  665. dump_init_list (l)
  666.      tree l;
  667. {
  668.   while (l)
  669.     {
  670.       dump_init (TREE_VALUE (l));
  671.       if (TREE_CHAIN (l))
  672.     OB_PUTC (',');
  673.       l = TREE_CHAIN (l);
  674.     }
  675. }
  676.  
  677. static void
  678. dump_init (t)
  679.      tree t;
  680. {
  681.   int dummy;
  682.  
  683.   switch (TREE_CODE (t))
  684.     {
  685.     case VAR_DECL:
  686.     case PARM_DECL:
  687.       sprintf (inline_bufp, " %s ", IDENTIFIER_POINTER (DECL_NAME (t)));
  688.       break;
  689.  
  690.     case FUNCTION_DECL:
  691.       {
  692.     tree name = DECL_NAME (t);
  693.  
  694.     if (DESTRUCTOR_NAME_P (name))
  695.       sprintf (inline_bufp, " ~%s ",
  696.            IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t)));
  697.     else if (OPERATOR_NAME_P (name))
  698.       sprintf (inline_bufp, "operator %s ", operator_name_string (name));
  699.     else if (OPERATOR_TYPENAME_P (name))
  700.       {
  701.         dummy = 0;
  702.         OB_PUTS ("operator ");
  703.         dump_type (TREE_TYPE (name), &dummy);
  704.       }
  705. #if 0
  706.     else if (WRAPPER_NAME_P (name))
  707.       sprintf (inline_bufp, " ()%s ",
  708.            IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t)));
  709.     else if (WRAPPER_PRED_NAME_P (name))
  710.       sprintf (inline_bufp, " ()?%s ",
  711.            IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t)));
  712.     else if (ANTI_WRAPPER_NAME_P (name))
  713.       sprintf (inline_bufp, " ~()%s ",
  714.            IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t)));
  715. #endif
  716.     else sprintf (inline_bufp, " %s ",
  717.               IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t)));
  718.       }
  719.       break;
  720.  
  721.     case CONST_DECL:
  722.       dummy = 0;
  723.       OB_PUTC2 ('(', '(');
  724.       dump_type (TREE_TYPE (t), &dummy);
  725.       OB_PUTC (')');
  726.       dump_init (DECL_INITIAL (t));
  727.       OB_PUTC (')');
  728.       return;
  729.  
  730.     case INTEGER_CST:
  731.       sprintf (inline_bufp, " %d ", TREE_INT_CST_LOW (t));
  732.       break;
  733.  
  734.     case REAL_CST:
  735.       sprintf (inline_bufp, " %g ", TREE_REAL_CST (t));
  736.       break;
  737.  
  738.     case STRING_CST:
  739.       {
  740.     char *p = TREE_STRING_POINTER (t);
  741.     int len = TREE_STRING_LENGTH (t) - 1;
  742.     int i;
  743.  
  744.     check_text_len (inline_bufp + len + 2);
  745.     OB_PUTC ('\"');
  746.     for (i = 0; i < len; i++)
  747.       {
  748.         register char c = p[i];
  749.         if (c == '\"' || c == '\\')
  750.           OB_PUTC ('\\');
  751.         if (c >= ' ' && c < 0177)
  752.           OB_PUTC (c);
  753.         else
  754.           {
  755.         sprintf (inline_bufp, "\\%03o", c);
  756.         inline_bufp = new_text_len (inline_bufp);
  757.           }
  758.       }
  759.     OB_PUTC ('\"');
  760.       }
  761.       return;
  762.  
  763.     case COMPOUND_EXPR:
  764.       dump_binary_op (",", t, 1);
  765.       break;
  766.  
  767.     case COND_EXPR:
  768.       OB_PUTC ('(');
  769.       dump_init (TREE_OPERAND (t, 0));
  770.       OB_PUTS (" ? ");
  771.       dump_init (TREE_OPERAND (t, 1));
  772.       OB_PUTS (" : ");
  773.       dump_init (TREE_OPERAND (t, 2));
  774.       OB_PUTC (')');
  775.       return;
  776.  
  777.     case SAVE_EXPR:
  778.       if (TREE_HAS_CONSTRUCTOR (t))
  779.     {
  780.       dummy = 0;
  781.       OB_PUTS ("new ");
  782.       dump_type (TREE_TYPE (TREE_TYPE (t)), &dummy);
  783.       PARM_DECL_EXPR (t) = 1;
  784.     }
  785.       else
  786.     {
  787.       sorry ("operand of SAVE_EXPR not understood");
  788.       *inline_errp = '\0';
  789.       inline_bufp = inline_errp + 1;
  790.     }
  791.       return;
  792.  
  793.     case NEW_EXPR:
  794.       strcpy (inline_bufp, TYPE_NAME_STRING (TREE_TYPE (t)));
  795.       inline_bufp = new_text_len (inline_bufp);
  796.       OB_PUTC ('(');
  797.       dump_init_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  798.       OB_PUTC (')');
  799.       return;
  800.  
  801.     case CALL_EXPR:
  802.       OB_PUTC ('(');
  803.       dump_init (TREE_OPERAND (t, 0));
  804.       dump_init_list (TREE_OPERAND (t, 1));
  805.       OB_PUTC (')');
  806.       return;
  807.  
  808.     case MODIFY_EXPR:
  809.     case PLUS_EXPR:
  810.     case MINUS_EXPR:
  811.     case MULT_EXPR:
  812.     case TRUNC_DIV_EXPR:
  813.     case TRUNC_MOD_EXPR:
  814.     case MIN_EXPR:
  815.     case MAX_EXPR:
  816.     case LSHIFT_EXPR:
  817.     case RSHIFT_EXPR:
  818.     case BIT_IOR_EXPR:
  819.     case BIT_XOR_EXPR:
  820.     case BIT_AND_EXPR:
  821.     case BIT_ANDTC_EXPR:
  822.     case TRUTH_ANDIF_EXPR:
  823.     case TRUTH_ORIF_EXPR:
  824.     case LT_EXPR:
  825.     case LE_EXPR:
  826.     case GT_EXPR:
  827.     case GE_EXPR:
  828.     case EQ_EXPR:
  829.     case NE_EXPR:
  830.       dump_binary_op (opname_tab[(int) TREE_CODE (t)], t,
  831.               strlen (opname_tab[(int) TREE_CODE (t)]));
  832.       return;
  833.  
  834.     case CEIL_DIV_EXPR:
  835.     case FLOOR_DIV_EXPR:
  836.     case ROUND_DIV_EXPR:
  837.       dump_binary_op ("/", t, 1);
  838.       return;
  839.  
  840.     case CEIL_MOD_EXPR:
  841.     case FLOOR_MOD_EXPR:
  842.     case ROUND_MOD_EXPR:
  843.       dump_binary_op ("%", t, 1);
  844.       return;
  845.  
  846.     case COMPONENT_REF:
  847.       dump_binary_op (".", t, 1);
  848.       return;
  849.  
  850.     case CONVERT_EXPR:
  851.       dump_unary_op ("+", t, 1);
  852.       return;
  853.  
  854.     case ADDR_EXPR:
  855.       if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
  856.       || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
  857.     dump_init (TREE_OPERAND (t, 0));
  858.       else
  859.     dump_unary_op ("&", t, 1);
  860.       return;
  861.  
  862.     case INDIRECT_REF:
  863.       dump_unary_op ("*", t, 1);
  864.       return;
  865.  
  866.     case NEGATE_EXPR:
  867.     case BIT_NOT_EXPR:
  868.     case TRUTH_NOT_EXPR:
  869.     case PREDECREMENT_EXPR:
  870.     case PREINCREMENT_EXPR:
  871.       dump_unary_op (opname_tab [(int)TREE_CODE (t)], t,
  872.              strlen (opname_tab[(int) TREE_CODE (t)]));
  873.       return;
  874.  
  875.     case POSTDECREMENT_EXPR:
  876.     case POSTINCREMENT_EXPR:
  877.       OB_PUTC ('(');
  878.       dump_init (TREE_OPERAND (t, 0));
  879.       OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
  880.       OB_PUTC (')');
  881.       return;
  882.  
  883.     case NOP_EXPR:
  884.       dummy = 0;
  885.       OB_PUTC2 ('(', '(');
  886.       dump_type (TREE_TYPE (t), &dummy);
  887.       OB_PUTC (')');
  888.       dump_init (TREE_OPERAND (t, 0));
  889.       OB_PUTC (')');
  890.       return;
  891.  
  892.     case CONSTRUCTOR:
  893.       OB_PUTC ('{');
  894.       dump_init_list (CONSTRUCTOR_ELTS (t));
  895.       OB_PUTC ('}');
  896.       return;
  897.  
  898.       /*  This list is incomplete, but should suffice for now.
  899.       It is very important that `sorry' does not call
  900.       `report_error_function'.  That could cause an infinite loop.  */
  901.     default:
  902.       sorry ("that operation not supported for default parameters");
  903.  
  904.       /* fall through to ERROR_MARK...  */
  905.     case ERROR_MARK:
  906.       *inline_errp = '\0';
  907.       inline_bufp = inline_errp + 1;
  908.       return;
  909.     }
  910.   inline_bufp = new_text_len (inline_bufp);
  911. }
  912.  
  913. static void
  914. dump_binary_op (opstring, t, len)
  915.      char *opstring;
  916.      tree t;
  917.      int len;
  918. {
  919.   OB_PUTC ('(');
  920.   dump_init (TREE_OPERAND (t, 0));
  921.   sprintf (inline_bufp, " %s ", opstring);
  922.   inline_bufp += len + 2;
  923.   dump_init (TREE_OPERAND (t, 1));
  924.   OB_PUTC (')');
  925.   check_text_len (inline_bufp);
  926. }
  927.  
  928. static void
  929. dump_unary_op (opstring, t, len)
  930.      char *opstring;
  931.      tree t;
  932.      int len;
  933. {
  934.   OB_PUTC ('(');
  935.   sprintf (inline_bufp, " %s ", opstring);
  936.   inline_bufp += len + 2;
  937.   dump_init (TREE_OPERAND (t, 0));
  938.   OB_PUTC (')');
  939.   check_text_len (inline_bufp);
  940. }
  941.  
  942. #define OVERLOAD_MAX_LEN 1024
  943.  
  944. /* Pretty printing for announce_function.  If BUF is nonzero, then
  945.    the text is written there.  The buffer is assued to be of size
  946.    OVERLOAD_MAX_LEN.  CNAME is the TYPE_DECL for the class that FNDECL
  947.    belongs to, if we could not figure that out from FNDECL
  948.    itself.  FNDECL is the declaration of the function we
  949.    are interested in seeing.  PRINT_RET_TYPE_P is non-zero if
  950.    we should print the type that this function returns.  */
  951. char *
  952. fndecl_as_string (buf, cname, fndecl, print_ret_type_p)
  953.      char *buf;
  954.      tree cname, fndecl;
  955.      int print_ret_type_p;
  956. {
  957.   tree name = DECL_NAME (fndecl);
  958.   tree fntype = TREE_TYPE (fndecl);
  959.   tree parmtypes = TYPE_ARG_TYPES (fntype);
  960.   int p = 0;
  961.   int spaces = 0;
  962.  
  963.   inline_buffer = buf;
  964.   OB_INIT ();
  965.  
  966.   if (DECL_STATIC_FUNCTION_P (fndecl))
  967.     cname = TYPE_NAME (DECL_STATIC_CONTEXT (fndecl));
  968.   else if (! cname && TREE_CODE (fntype) == METHOD_TYPE)
  969.     cname = TYPE_NAME (TYPE_METHOD_BASETYPE (fntype));
  970.  
  971.   if (print_ret_type_p && ! OPERATOR_TYPENAME_P (name))
  972.     dump_type_prefix (TREE_TYPE (fntype), &p);
  973.   if (DECL_STATIC_FUNCTION_P (fndecl))
  974.       OB_PUTS ("static ");
  975.     
  976.   if (cname)
  977.     {
  978.       dump_type (cname, &p);
  979.       inline_bufp[-1] = ':';
  980.       *inline_bufp++ = ':';
  981.       if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
  982.     parmtypes = TREE_CHAIN (parmtypes);
  983.       if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
  984.     parmtypes = TREE_CHAIN (parmtypes);
  985.     }
  986.  
  987.   if (DESTRUCTOR_NAME_P (name))
  988.     {
  989.       OB_PUTC ('~');
  990.       parmtypes = TREE_CHAIN (parmtypes);
  991.       dump_decl (DECL_ORIGINAL_NAME (fndecl));
  992.     }
  993.   else if (OPERATOR_NAME_P (name))
  994.     {
  995.       sprintf (inline_bufp, "operator %s ", operator_name_string (name));
  996.       inline_bufp += strlen (inline_bufp);
  997.     }
  998.   else if (OPERATOR_TYPENAME_P (name))
  999.     {
  1000.       /* This cannot use the hack that the operator's return
  1001.      type is stashed off of its name because it may be
  1002.      used for error reporting.  In the case of conflicting
  1003.      declarations, both will have the same name, yet
  1004.      the types will be different, hence the TREE_TYPE field
  1005.      of the first name will be clobbered by the second.  */
  1006.       OB_PUTS ("operator ");
  1007.       dump_type (TREE_TYPE (TREE_TYPE (fndecl)), &p);
  1008.     }
  1009.   else if (DECL_CONSTRUCTOR_P (fndecl))
  1010.     {
  1011. #ifdef SOS
  1012.       if (TYPE_DYNAMIC (IDENTIFIER_TYPE_VALUE (DECL_ORIGINAL_NAME (fndecl))))
  1013.     {
  1014.       OB_PUTS ("dynamic ");
  1015.       parmtypes = TREE_CHAIN (parmtypes);
  1016.     }
  1017. #endif
  1018.       dump_decl (DECL_ORIGINAL_NAME (fndecl));
  1019.       /* Skip past "in_charge" identifier.  */
  1020.       assert (TREE_CODE (cname) == TYPE_DECL);
  1021.       if (TYPE_USES_VIRTUAL_BASECLASSES (TREE_TYPE (cname)))
  1022. #if 0
  1023.       if (TYPE_USES_VIRTUAL_BASECLASSES (IDENTIFIER_TYPE_VALUE (DECL_NAME (cname))))
  1024. #endif
  1025.     parmtypes = TREE_CHAIN (parmtypes);
  1026.     }
  1027.   else
  1028.     {
  1029. #if 0
  1030.       if (WRAPPER_NAME_P (name))
  1031.     OB_PUTC2 ('(', ')');
  1032.       if (WRAPPER_PRED_NAME_P (name))
  1033.     OB_PUTS ("()?");
  1034.       else if (ANTI_WRAPPER_NAME_P (name))
  1035.     OB_PUTS ("~()");
  1036. #endif
  1037.       dump_decl (DECL_ORIGINAL_NAME (fndecl));
  1038.     }
  1039.  
  1040.   OB_PUTC ('(');
  1041.   if (parmtypes)
  1042.     {
  1043.       in_parmlist++;
  1044.       if (parmtypes != void_list_node)
  1045.     spaces = 2;
  1046.       while (parmtypes && parmtypes != void_list_node)
  1047.     {
  1048.       dump_type (TREE_VALUE (parmtypes), &p);
  1049.       while (inline_bufp[-1] == ' ')
  1050.         inline_bufp--;
  1051.       if (TREE_PURPOSE (parmtypes))
  1052.         {
  1053.           inline_errp = inline_bufp;
  1054.           OB_PUTS (" (= ");
  1055.           dump_init (TREE_PURPOSE (parmtypes));
  1056.           OB_PUTC (')');
  1057.         }
  1058.       OB_PUTC2 (',', ' ');
  1059.       parmtypes = TREE_CHAIN (parmtypes);
  1060.     }
  1061.       in_parmlist--;
  1062.     }
  1063.   
  1064.   if (parmtypes)
  1065.     inline_bufp -= spaces;
  1066.   else
  1067.     OB_PUTS ("...");
  1068.  
  1069.   OB_PUTC (')');
  1070.  
  1071.   if (print_ret_type_p && ! OPERATOR_TYPENAME_P (name))
  1072.     dump_type_suffix (TREE_TYPE (fntype), &p);
  1073.  
  1074.   if (TREE_CODE (fntype) == METHOD_TYPE)
  1075.     dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))));
  1076.  
  1077.   OB_FINISH ();
  1078.   check_text_len (inline_bufp);
  1079.   
  1080.   if (strlen (buf) >= OVERLOAD_MAX_LEN)
  1081.     {
  1082.       fprintf (stderr, "fndecl_as_string returns something too large");
  1083.       abort ();
  1084.     }
  1085.   return buf;
  1086. }
  1087.  
  1088. /* Same, but handtype a _TYPE.  */
  1089. char *
  1090. type_as_string (buf, typ)
  1091.      char *buf;
  1092.      tree typ;
  1093. {
  1094.   int p = 0;
  1095.   int spaces = 0;
  1096.  
  1097.   inline_buffer = buf;
  1098.   OB_INIT ();
  1099.  
  1100.   dump_type(typ,&p);
  1101.  
  1102.   OB_FINISH ();
  1103.  
  1104.   return buf;
  1105. }
  1106.  
  1107. /* Move inline function defintions out of structure so that they
  1108.    can be processed normally.  CNAME is the name of the class
  1109.    we are working from, METHOD_LIST is the list of method lists
  1110.    of the structure.  We delete friend methods here, after
  1111.    saving away their inline function definitions (if any).  */
  1112.  
  1113. void
  1114. do_inline_function_hair (type, friend_list)
  1115.      tree type, friend_list;
  1116. {
  1117.   tree cname = TYPE_IDENTIFIER (type);
  1118.   tree method_vec = CLASSTYPE_METHOD_VEC (type);
  1119.   if (method_vec != 0)
  1120.     {
  1121.       tree *methods = &TREE_VEC_ELT (method_vec, 0);
  1122.       tree *end = TREE_VEC_END (method_vec);
  1123.       while (methods != end)
  1124.     {
  1125.       /* Do inline member functions.  */
  1126.       tree method = *methods;
  1127.       while (method)
  1128.         {
  1129.           struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
  1130.           if (info)
  1131.         {
  1132.           tree args;
  1133.  
  1134.           info->fndecl = method;
  1135.           args = DECL_ARGUMENTS (method);
  1136.           while (args)
  1137.             {
  1138.               DECL_CONTEXT (args) = method;
  1139.               args = TREE_CHAIN (args);
  1140.             }
  1141.  
  1142.           /* Allow this decl to be seen in global scope */
  1143.           IDENTIFIER_GLOBAL_VALUE (DECL_NAME (method)) = method;
  1144.         }
  1145.           method = TREE_CHAIN (method);
  1146.         }
  1147.       methods++;
  1148.     }
  1149.     }
  1150.   while (friend_list)
  1151.     {
  1152.       tree fndecl = TREE_VALUE (friend_list);
  1153.       struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
  1154.       if (info)
  1155.     {
  1156.       tree args;
  1157.  
  1158.       info->fndecl = fndecl;
  1159.       args = DECL_ARGUMENTS (fndecl);
  1160.       while (args)
  1161.         {
  1162.           DECL_CONTEXT (args) = fndecl;
  1163.           args = TREE_CHAIN (args);
  1164.         }
  1165.  
  1166.       /* Allow this decl to be seen in global scope */
  1167.       IDENTIFIER_GLOBAL_VALUE (DECL_NAME (fndecl)) = fndecl;
  1168.     }
  1169.  
  1170.       friend_list = TREE_CHAIN (friend_list);
  1171.     }
  1172. }
  1173.  
  1174. /* Report a argument type mismatch between the best declared function
  1175.    we could find and the current argument list that we have.  */
  1176. void
  1177. report_type_mismatch (cp, parmtypes, name_kind, err_name)
  1178.      struct candidate *cp;
  1179.      tree parmtypes;
  1180.      char *name_kind, *err_name;
  1181. {
  1182.   char buf[OVERLOAD_MAX_LEN];
  1183.   int i = cp->u.bad_arg;
  1184.   tree ttf, tta;
  1185.  
  1186.   if (i == -3)
  1187.     {
  1188.       if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes))))
  1189.     error ("call to const %s `%s' with non-const object", name_kind, err_name);
  1190.       else
  1191.     error ("call to non-const %s `%s' with const object", name_kind, err_name);
  1192.       return;
  1193.     }
  1194.   if (i == -2)
  1195.     {
  1196.       error ("too few arguments for %s `%s'", name_kind, err_name);
  1197.       return;
  1198.     }
  1199.   else if (i == -1)
  1200.     {
  1201.       error ("too many arguments for %s `%s'", name_kind, err_name);
  1202.       return;
  1203.     }
  1204.   if (i == 0)
  1205.     {
  1206.       if (TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE)
  1207.     {
  1208.       /* Happens when we have an ambiguous base class.  */
  1209.       assert (get_base_type (DECL_CONTEXT (cp->function), TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes))), 1) == error_mark_node);
  1210.       return;
  1211.     }
  1212.     }
  1213.   ttf = TYPE_ARG_TYPES (TREE_TYPE (cp->function));
  1214.   tta = parmtypes;
  1215.  
  1216.   while (i-- > 0)
  1217.     {
  1218.       ttf = TREE_CHAIN (ttf);
  1219.       tta = TREE_CHAIN (tta);
  1220.     }
  1221.   fndecl_as_string (buf, 0, cp->function, 0);
  1222.   inline_bufp = inline_buffer + strlen (inline_buffer) + 1;
  1223.   inline_buffer = inline_bufp;
  1224.  
  1225.   /* Reset `i' so that type printing routines do the right thing.  */
  1226.   if (tta)
  1227.     {
  1228.       enum tree_code code = TREE_CODE (TREE_TYPE (TREE_VALUE (tta)));
  1229.       if (code == ERROR_MARK)
  1230.     OB_PUTS ("(failed type instatiation)");
  1231.       else
  1232.     {
  1233.       i = (code == FUNCTION_TYPE || code == METHOD_TYPE);
  1234.       dump_type (TREE_TYPE (TREE_VALUE (tta)), &i);
  1235.     }
  1236.     }
  1237.   else OB_PUTS ("void");
  1238.  
  1239.   OB_FINISH ();
  1240.   sprintf (inline_bufp, "bad argument %d for function `%s' (type was %s)",
  1241.        cp->u.bad_arg - (TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE), buf, inline_buffer);
  1242.   strcpy (buf, inline_bufp);
  1243.   error (buf);
  1244. }
  1245.  
  1246. /* Here is where overload code starts.  */
  1247.  
  1248. #define OVERLOAD_MAX_LEN 1024
  1249.  
  1250. /* Array of types seen so far in top-level call to `build_overload_name'.
  1251.    Allocated and deallocated by caller.  */
  1252. static tree *typevec;
  1253.  
  1254. /* Number of types interned by `build_overload_name' so far.  */
  1255. static int maxtype;
  1256.  
  1257. /* Number of occurances of last type seen.  */
  1258. static int nrepeats;
  1259.  
  1260. /* Nonzero if we should not try folding parameter types.  */
  1261. static int nofold;
  1262.  
  1263. #define ALLOCATE_TYPEVEC(PARMTYPES) \
  1264.   do { maxtype = 0, nrepeats = 0; \
  1265.        typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
  1266.  
  1267. #define DEALLOCATE_TYPEVEC(PARMTYPES) \
  1268.   do { tree t = (PARMTYPES); \
  1269.        while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
  1270.   } while (0)
  1271.  
  1272. /* Code to concatenate an asciified integer to a string,
  1273.    and return the end of the string.  */
  1274. static
  1275. #ifdef __GNUC__
  1276. __inline
  1277. #endif
  1278. char *
  1279. icat (s, i)
  1280.      char *s;
  1281.      int i;
  1282. {
  1283.   if (i < 0)
  1284.     {
  1285.       *s++ = 'm';
  1286.       i = -i;
  1287.     }
  1288.   if (i < 10)
  1289.     {
  1290.       *s++ = '0' + i;
  1291.       return s;
  1292.     }
  1293.   s = icat (s, i / 10);
  1294.   *s++ = '0' + (i % 10);
  1295.   return s;
  1296. }
  1297.  
  1298. static
  1299. #ifdef __GNUC__
  1300. __inline
  1301. #endif
  1302. char *
  1303. flush_repeats (s, type)
  1304.      char *s;
  1305.      tree type;
  1306. {
  1307.   int tindex = 0;
  1308.   char *rval;
  1309.  
  1310.   while (typevec[tindex] != type)
  1311.     tindex++;
  1312.  
  1313.   if (nrepeats > 1)
  1314.     {
  1315.       *s++ = 'N';
  1316.       s = icat (s, nrepeats);
  1317.       if (nrepeats > 9)
  1318.     *s++ = '_';
  1319.     }
  1320.   else
  1321.     *s++ = 'T';
  1322.   nrepeats = 0;
  1323.   rval = icat (s, tindex);
  1324.   if (tindex > 9)
  1325.     *rval++ = '_';
  1326.   return rval;
  1327. }
  1328.  
  1329. char *build_overload_name ();
  1330. static char *build_overload_identifier ();
  1331.  
  1332. static char *
  1333. build_overload_nested_name (textp, context, text_end)
  1334.      char *textp, *text_end;
  1335.      tree context;
  1336. {
  1337.   tree name = DECL_NAME (context);
  1338.   if (DECL_CONTEXT (context))
  1339.     {
  1340.       context = DECL_CONTEXT (context);
  1341.       if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
  1342.     context = TYPE_NAME (context);
  1343.       textp = build_overload_nested_name (textp, context);
  1344.     }
  1345.   return build_overload_identifier (textp, name);
  1346. }
  1347.  
  1348. static char *
  1349. build_overload_value (type, value, textp, text_end)
  1350.      tree type, value;
  1351.      char *textp, *text_end;
  1352. {
  1353.   char buf[40];
  1354.   while (TREE_CODE (value) == NON_LVALUE_EXPR)
  1355.     value = TREE_OPERAND (value, 0);
  1356.   switch (TREE_CODE (type))
  1357.     {
  1358.     case INTEGER_TYPE:
  1359.       {
  1360.     assert (TREE_CODE (value) == INTEGER_CST);
  1361.     if (TYPE_MODE (value) == DImode)
  1362.       {
  1363.         static tree integer_zero;
  1364.         if (!integer_zero)
  1365.           integer_zero = build_int_2 (0, 0);
  1366.         if (tree_int_cst_lt (value, integer_zero))
  1367.           {
  1368.         *textp++ = 'm';
  1369.         value = build_int_2 (~ TREE_INT_CST_LOW (value),
  1370.                      - TREE_INT_CST_HIGH (value));
  1371.           }
  1372.         if (TREE_INT_CST_HIGH (value) != (TREE_INT_CST_LOW (value) >> 31))
  1373.           {
  1374.         /* need to print a DImode value in decimal */
  1375.         sorry ("conversion of long long as PT parameter");
  1376.           }
  1377.         /* else fall through to print in smaller mode */
  1378.       }
  1379.     /* SImode or smaller */
  1380.     return icat (textp, TREE_INT_CST_LOW (value));
  1381.       }
  1382.     default:
  1383.       sorry ("conversion of %s as PT parameter",
  1384.          tree_code_name [(int) TREE_CODE (type)]);
  1385.     }
  1386. }
  1387.  
  1388. static char *
  1389. build_overload_identifier (textp, name, text_end)
  1390.      char *textp, *text_end;
  1391.      tree name;
  1392. {
  1393.   if (IDENTIFIER_TEMPLATE (name))
  1394.     {
  1395.       tree template, parmlist, arglist, tname;
  1396.       int i, nparms;
  1397.       template = IDENTIFIER_TEMPLATE (name);
  1398.       arglist = TREE_VALUE (template);
  1399.       template = TREE_PURPOSE (template);
  1400.       tname = DECL_NAME (template);
  1401.       parmlist = DECL_ARGUMENTS (template);
  1402.       nparms = TREE_VEC_LENGTH (parmlist);
  1403.       *textp++ = 't';
  1404.       textp = icat (textp, IDENTIFIER_LENGTH (tname));
  1405.       strcpy (textp, IDENTIFIER_POINTER (tname));
  1406.       textp += IDENTIFIER_LENGTH (tname);
  1407.       textp = icat (textp, nparms);
  1408.       for (i = 0; i < nparms; i++)
  1409.     {
  1410.       tree parm = TREE_VEC_ELT (parmlist, i);
  1411.       tree arg = TREE_VEC_ELT (arglist, i);
  1412.       if (TREE_CODE (parm) == IDENTIFIER_NODE)
  1413.         {
  1414.           /* This parameter is a type.  */
  1415.           *textp++ = 'Z';
  1416.           textp = build_overload_name (arg, textp, text_end);
  1417.         }
  1418.       else
  1419.         {
  1420.           /* It's a PARM_DECL.  */
  1421.           textp = build_overload_name (TREE_TYPE (parm), textp, text_end);
  1422.           textp = build_overload_value (parm, arg, textp,
  1423.                         text_end);
  1424.         }
  1425.     }
  1426.     }
  1427.   else
  1428.     {
  1429.       textp = icat (textp, IDENTIFIER_LENGTH (name));
  1430.       strcpy (textp, IDENTIFIER_POINTER (name));
  1431.       textp += IDENTIFIER_LENGTH (name);
  1432.     }
  1433.   return textp;
  1434. }
  1435.  
  1436. /* Given a list of parameters in PARMS, and a buffer in TEXT, of
  1437.    length LEN bytes, create an unambiguous overload string. Should
  1438.    distinguish any type that C (or C++) can distinguish. I.e.,
  1439.    pointers to functions are treated correctly.
  1440.  
  1441.    Caller must deal with whether a final `e' goes on the end or not.
  1442.  
  1443.    Any default conversions must take place before this function
  1444.    is called.  */
  1445.  
  1446. char *
  1447. build_overload_name (parmtypes, text, text_end)
  1448.      tree parmtypes;
  1449.      char *text, *text_end;
  1450. {
  1451.   char *textp = text;
  1452.   int just_one;
  1453.   tree parmtype;
  1454.  
  1455.   if (just_one = (TREE_CODE (parmtypes) != TREE_LIST))
  1456.     {
  1457.       parmtype = parmtypes;
  1458.       goto only_one;
  1459.     }
  1460.  
  1461.   while (parmtypes)
  1462.     {
  1463.       if (text_end - text < 4)
  1464.     fatal ("Out of string space in build_overload_name!");
  1465.       parmtype = TREE_VALUE (parmtypes);
  1466.  
  1467.     only_one:
  1468.  
  1469.       if (! nofold)
  1470.     {
  1471.       if (! just_one)
  1472.         /* Every argument gets counted.  */
  1473.         typevec[maxtype++] = parmtype;
  1474.  
  1475.       if (TREE_USED (parmtype))
  1476.         {
  1477.           if (! just_one && parmtype == typevec[maxtype-2])
  1478.         nrepeats++;
  1479.           else
  1480.         {
  1481.           if (nrepeats)
  1482.             textp = flush_repeats (textp, parmtype);
  1483.           if (! just_one && TREE_CHAIN (parmtypes)
  1484.               && parmtype == TREE_VALUE (TREE_CHAIN (parmtypes)))
  1485.             nrepeats++;
  1486.           else
  1487.             {
  1488.               int tindex = 0;
  1489.  
  1490.               while (typevec[tindex] != parmtype)
  1491.             tindex++;
  1492.               *textp++ = 'T';
  1493.               textp = icat (textp, tindex);
  1494.               if (tindex > 9)
  1495.             *textp++ = '_';
  1496.             }
  1497.         }
  1498.           goto next;
  1499.         }
  1500.       if (nrepeats)
  1501.         textp = flush_repeats (textp, typevec[maxtype-2]);
  1502.       if (! just_one
  1503.           /* Only cache types which take more than one character.  */
  1504.           && (parmtype != TYPE_MAIN_VARIANT (parmtype)
  1505.           || (TREE_CODE (parmtype) != INTEGER_TYPE
  1506.               && TREE_CODE (parmtype) != REAL_TYPE)))
  1507.         TREE_USED (parmtype) = 1;
  1508.     }
  1509.  
  1510.       if (TREE_READONLY (parmtype))
  1511.     *textp++ = 'C';
  1512.       if (TREE_CODE (parmtype) == INTEGER_TYPE && TREE_UNSIGNED (parmtype))
  1513.     *textp++ = 'U';
  1514.       if (TYPE_VOLATILE (parmtype))
  1515.     *textp++ = 'V';
  1516.  
  1517.       switch (TREE_CODE (parmtype))
  1518.     {
  1519.     case OFFSET_TYPE:
  1520.       *textp++ = 'O';
  1521.       textp = build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), textp, text_end);
  1522.       *textp++ = '_';
  1523.       textp = build_overload_name (TREE_TYPE (parmtype), textp, text_end);
  1524.       break;
  1525.  
  1526.     case REFERENCE_TYPE:
  1527.       *textp++ = 'R';
  1528.       goto more;
  1529.  
  1530.     case ARRAY_TYPE:
  1531. #ifdef PARM_CAN_BE_ARRAY_TYPE
  1532.       {
  1533.         tree length;
  1534.  
  1535.         *textp++ = 'A';
  1536.         length = array_type_nelts (parmtype);
  1537.         if (TREE_CODE (length) == INTEGER_CST)
  1538.           textp = icat (textp, TREE_INT_CST_LOW (length));
  1539.         *textp++ = '_';
  1540.         goto more;
  1541.       }
  1542. #else
  1543.       *textp++ = 'P';
  1544.       goto more;
  1545. #endif
  1546.  
  1547.     case POINTER_TYPE:
  1548.       *textp++ = 'P';
  1549.     more:
  1550.       textp = build_overload_name (TREE_TYPE (parmtype), textp, text_end);
  1551.       break;
  1552.  
  1553.     case FUNCTION_TYPE:
  1554.     case METHOD_TYPE:
  1555.       {
  1556.         tree firstarg = TYPE_ARG_TYPES (parmtype);
  1557.         /* Otherwise have to implement reentrant typevecs,
  1558.            unmark and remark types, etc.  */
  1559.         int old_nofold = nofold;
  1560.         nofold = 1;
  1561.  
  1562.         if (nrepeats)
  1563.           textp = flush_repeats (textp, typevec[maxtype-1]);
  1564.  
  1565.         /* @@ It may be possible to pass a function type in
  1566.            which is not preceded by a 'P'.  */
  1567.         if (TREE_CODE (parmtype) == FUNCTION_TYPE)
  1568.           {
  1569.         *textp++ = 'F';
  1570.         if (firstarg == NULL_TREE)
  1571.           *textp++ = 'e';
  1572.         else if (firstarg == void_list_node)
  1573.           *textp++ = 'v';
  1574.         else
  1575.           textp = build_overload_name (firstarg, textp, text_end);
  1576.           }
  1577.         else
  1578.           {
  1579.         int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
  1580.         int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
  1581.         *textp++ = 'M';
  1582.         firstarg = TREE_CHAIN (firstarg);
  1583.  
  1584.         textp = build_overload_name (TYPE_METHOD_BASETYPE (parmtype), textp, text_end);
  1585.         if (constp)
  1586.           *textp++ = 'C';
  1587.         if (volatilep)
  1588.           *textp++ = 'V';
  1589.  
  1590.         /* For cfront 2.0 compatability.  */
  1591.         *textp++ = 'F';
  1592.  
  1593.         if (firstarg == NULL_TREE)
  1594.           *textp++ = 'e';
  1595.         else if (firstarg == void_list_node)
  1596.           *textp++ = 'v';
  1597.         else
  1598.           textp = build_overload_name (firstarg, textp, text_end);
  1599.           }
  1600.  
  1601.         /* Separate args from return type.  */
  1602.         *textp++ = '_';
  1603.         textp = build_overload_name (TREE_TYPE (parmtype), textp, text_end);
  1604.         nofold = old_nofold;
  1605.         break;
  1606.       }
  1607.  
  1608.     case INTEGER_TYPE:
  1609.       parmtype = TYPE_MAIN_VARIANT (parmtype);
  1610.       switch (TYPE_MODE (parmtype))
  1611.         {
  1612.         case TImode:
  1613.           if (parmtype == long_integer_type_node
  1614.           || parmtype == long_unsigned_type_node)
  1615.         *textp++ = 'l';
  1616.           else
  1617.         *textp++ = 'q';
  1618.           break;
  1619.         case DImode:
  1620.           if (parmtype == long_integer_type_node
  1621.           || parmtype == long_unsigned_type_node)
  1622.         *textp++ = 'l';
  1623.           else if (parmtype == integer_type_node
  1624.                || parmtype == unsigned_type_node)
  1625.         *textp++ = 'i';
  1626.           else if (parmtype == short_integer_type_node
  1627.                || parmtype == short_unsigned_type_node)
  1628.         *textp++ = 's';
  1629.           else
  1630.         *textp++ = 'x';
  1631.           break;
  1632.         case SImode:
  1633.           if (parmtype == long_integer_type_node
  1634.           || parmtype == long_unsigned_type_node)
  1635.         *textp++ = 'l';
  1636.           else if (parmtype == short_integer_type_node
  1637.                || parmtype == short_unsigned_type_node)
  1638.         *textp++ = 's';
  1639.           else
  1640.         *textp++ = 'i';
  1641.           break;
  1642.         case HImode:
  1643.           if (parmtype == integer_type_node
  1644.           || parmtype == unsigned_type_node)
  1645.         *textp++ = 'i';
  1646.           else
  1647.         *textp++ = 's';
  1648.           break;
  1649.         case QImode:
  1650.           *textp++ = 'c';
  1651.           break;
  1652.         default:
  1653.           abort ();
  1654.         }
  1655.       break;
  1656.  
  1657.     case REAL_TYPE:
  1658.       parmtype = TYPE_MAIN_VARIANT (parmtype);
  1659.       if (parmtype == long_double_type_node)
  1660.         *textp++ = 'r';
  1661.       else if (parmtype == double_type_node)
  1662.         *textp++ = 'd';
  1663.       else if (parmtype == float_type_node)
  1664.         *textp++ = 'f';
  1665.       else abort ();
  1666.       break;
  1667.  
  1668.     case VOID_TYPE:
  1669.       if (! just_one)
  1670.         {
  1671. #if 0
  1672.           extern tree void_list_node;
  1673.  
  1674.           /* See if anybody is wasting memory.  */
  1675.           assert (parmtypes == void_list_node);
  1676. #endif
  1677.           /* This is the end of a parameter list.  */
  1678.           *textp = '\0';
  1679.           return textp;
  1680.         }
  1681.       *textp++ = 'v';
  1682.       break;
  1683.  
  1684.     case ERROR_MARK:    /* not right, but nothing is anyway */
  1685.       break;
  1686.  
  1687.       /* have to do these */
  1688.     case UNION_TYPE:
  1689.     case RECORD_TYPE:
  1690.       if (! just_one)
  1691.         /* Make this type signature look incompatible
  1692.            with AT&T.  */
  1693.         *textp++ = 'G';
  1694.       goto common;
  1695.     case ENUMERAL_TYPE:
  1696.     common:
  1697.       {
  1698.         tree name = TYPE_NAME (parmtype);
  1699.         int i = 1;
  1700.  
  1701.         if (TREE_CODE (name) == TYPE_DECL)
  1702.           {
  1703.         tree context = name;
  1704.         while (DECL_CONTEXT (context))
  1705.           {
  1706.             i += 1;
  1707.             context = DECL_CONTEXT (context);
  1708.           }
  1709.         name = DECL_NAME (name);
  1710.           }
  1711.         assert (TREE_CODE (name) == IDENTIFIER_NODE);
  1712.         if (i > 1)
  1713.           {
  1714.         *textp++ = 'Q';
  1715.         textp = icat (textp, i);
  1716.         textp = build_overload_nested_name (textp, TYPE_NAME (parmtype), text_end);
  1717.           }
  1718.         else
  1719.           textp = build_overload_identifier (textp, name, text_end);
  1720.         break;
  1721.       }
  1722.  
  1723.     case UNKNOWN_TYPE:
  1724.       /* This will take some work.  */
  1725.       *textp++ = '?';
  1726.       break;
  1727.  
  1728.     default:
  1729.       abort ();
  1730.     }
  1731.  
  1732.     next:
  1733.       if (just_one) break;
  1734.       parmtypes = TREE_CHAIN (parmtypes);
  1735.     }
  1736.   if (! just_one)
  1737.     {
  1738.       if (nrepeats)
  1739.     textp = flush_repeats (textp, typevec[maxtype-1]);
  1740.  
  1741.       /* To get here, parms must end with `...'. */
  1742.       *textp++ = 'e';
  1743.     }
  1744.  
  1745.   *textp = '\0';
  1746.   return textp;
  1747. }
  1748.  
  1749. /* Change the name of a function definition so that it may be
  1750.    overloaded. NAME is the name of the function to overload,
  1751.    PARMS is the parameter list (which determines what name the
  1752.    final function obtains).
  1753.  
  1754.    FOR_METHOD is 1 if this overload is being performed
  1755.    for a method, rather than a function type.  It is 2 if
  1756.    this overload is being performed for a constructor.  */
  1757. tree
  1758. build_decl_overload (name, parms, for_method)
  1759.      char *name;
  1760.      tree parms;
  1761.      int for_method;
  1762. {
  1763.   int tmp;
  1764.   char tname[OVERLOAD_MAX_LEN];
  1765.  
  1766.   if (for_method == 2)
  1767.     /* We can divine that this is a constructor,
  1768.        and figure out its name without any extra encoding.  */
  1769.     tmp = 0;
  1770.   else
  1771.     {
  1772.       strcpy (tname, name);
  1773.       tmp = strlen (tname);
  1774.     }
  1775.   tname[tmp++] = '_';
  1776.   tname[tmp++] = '_';
  1777.   if (for_method)
  1778.     {
  1779. #if 0
  1780.       /* We can get away without doing this.  */
  1781.       tname[tmp++] = 'M';
  1782. #endif
  1783.       parms = temp_tree_cons (NULL_TREE, TREE_TYPE (TREE_VALUE (parms)), TREE_CHAIN (parms));
  1784.     }
  1785.   else
  1786.     tname[tmp++] = 'F';
  1787.  
  1788.   if (parms == NULL_TREE)
  1789.     tname[tmp++] = 'e', tname[tmp] = '\0';
  1790.   else if (parms == void_list_node)
  1791.     tname[tmp++] = 'v', tname[tmp] = '\0';
  1792.   else
  1793.     {
  1794.       ALLOCATE_TYPEVEC (parms);
  1795.       nofold = 0;
  1796.       if (for_method)
  1797.     {
  1798.       tmp = build_overload_name (TREE_VALUE (parms), tname+tmp, &tname[OVERLOAD_MAX_LEN]) - tname;
  1799.  
  1800. #ifndef LONGERNAMES
  1801.       typevec[maxtype++] = TREE_VALUE (parms);
  1802.       TREE_USED (TREE_VALUE (parms)) = 1;
  1803. #endif
  1804.  
  1805.       if (TREE_CHAIN (parms))
  1806.         build_overload_name (TREE_CHAIN (parms), tname+tmp, &tname[OVERLOAD_MAX_LEN]);
  1807.       else
  1808.         {
  1809.           tname[tmp++] = 'e';
  1810.           tname[tmp] = '\0';
  1811.         }
  1812.     }
  1813.       else
  1814.     build_overload_name (parms, tname+tmp, &tname[OVERLOAD_MAX_LEN]);
  1815.       DEALLOCATE_TYPEVEC (parms);
  1816.     }
  1817.   return get_identifier (tname);
  1818. }
  1819.  
  1820. /* Build an overload name for the type expression TYPE.  */
  1821. tree
  1822. build_typename_overload (type)
  1823.      tree type;
  1824. {
  1825.   char tname[OVERLOAD_MAX_LEN];
  1826.   int i = sizeof (OPERATOR_TYPENAME_FORMAT) - 1;
  1827.   sprintf (tname, OPERATOR_TYPENAME_FORMAT);
  1828. #if 0
  1829.   /* We can get away without doing this--it really gets
  1830.      overloaded later.  */
  1831.   tname[i++] = '_';
  1832.   tname[i++] = '_';
  1833.   tname[i++] = 'M';
  1834. #endif
  1835.   nofold = 1;
  1836.   build_overload_name (type, tname + i, &tname[OVERLOAD_MAX_LEN]);
  1837.   return get_identifier (tname);
  1838. }
  1839.  
  1840. #define T_DESC_FORMAT "TD$"
  1841. #define I_DESC_FORMAT "ID$"
  1842. #define M_DESC_FORMAT "MD$"
  1843.  
  1844. /* Build an overload name for the type expression TYPE.  */
  1845. tree
  1846. build_t_desc_overload (type)
  1847.      tree type;
  1848. {
  1849.   char tname[OVERLOAD_MAX_LEN];
  1850.   int i = sizeof (T_DESC_FORMAT) - 1;
  1851.   sprintf (tname, T_DESC_FORMAT);
  1852.   nofold = 1;
  1853.  
  1854. #if 0
  1855.   /* Use a different format if the type isn't defined yet.  */
  1856.   if (TYPE_SIZE (type) == NULL_TREE)
  1857.     {
  1858.       char *p;
  1859.       int changed;
  1860.  
  1861.       for (p = tname; *p; p++)
  1862.     if (isupper (*p))
  1863.       {
  1864.         changed = 1;
  1865.         *p = tolower (*p);
  1866.       }
  1867.       /* If there's no change, we have an innappropriate T_DESC_FORMAT.  */
  1868.       assert (changed != 0);
  1869.     }
  1870. #endif
  1871.  
  1872.   build_overload_name (type, tname + i, &tname[OVERLOAD_MAX_LEN]);
  1873.   return get_identifier (tname);
  1874. }
  1875.  
  1876. /* Build an overload name for the type expression TYPE.  */
  1877. tree
  1878. build_i_desc_overload (decl)
  1879.      tree decl;
  1880. {
  1881.   char iname[OVERLOAD_MAX_LEN];
  1882.   int i = sizeof (I_DESC_FORMAT) - 1;
  1883.   sprintf (iname, I_DESC_FORMAT);
  1884.   strcat (iname, IDENTIFIER_POINTER (build_typename_overload (DECL_CONTEXT (decl))));
  1885.   strcat (iname, "__");
  1886.   strcat (iname, IDENTIFIER_POINTER (DECL_NAME (decl)));
  1887.   return get_identifier (iname);
  1888. }
  1889.  
  1890. /* Build an overload name for the type expression TYPE.  */
  1891. tree
  1892. build_m_desc_overload (decl)
  1893.      tree decl;
  1894. {
  1895.   char mname[OVERLOAD_MAX_LEN];
  1896.   int i = sizeof (M_DESC_FORMAT) - 1;
  1897.   sprintf (mname, M_DESC_FORMAT);
  1898.   strcat (mname, IDENTIFIER_POINTER (DECL_NAME (decl)));
  1899.   return get_identifier (mname);
  1900. }
  1901.  
  1902. /* Top-level interface to explicit overload requests. Allow NAME
  1903.    to be overloaded. Error if NAME is already declared for the current
  1904.    scope. Warning if function is redundanly overloaded. */
  1905.  
  1906. void
  1907. declare_overloaded (name)
  1908.      tree name;
  1909. {
  1910. #ifdef NO_AUTO_OVERLOAD
  1911.   if (is_overloaded (name))
  1912.     warning ("function `%s' already declared overloaded",
  1913.          IDENTIFIER_POINTER (name));
  1914.   else if (IDENTIFIER_GLOBAL_VALUE (name))
  1915.     error ("overloading function `%s' that is already defined",
  1916.        IDENTIFIER_POINTER (name));
  1917.   else
  1918.     {
  1919.       TREE_OVERLOADED (name) = 1;
  1920.       IDENTIFIER_GLOBAL_VALUE (name) = build_tree_list (name, NULL_TREE);
  1921.       TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)) = unknown_type_node;
  1922.     }
  1923. #else
  1924.   if (current_lang_name == lang_name_cplusplus)
  1925.     {
  1926.       if (0)
  1927.     warning ("functions are implicitly overloaded in C++");
  1928.     }
  1929.   else if (current_lang_name == lang_name_c)
  1930.     error ("overloading function `%s' cannot be done in C language context");
  1931.   else
  1932.     abort ();
  1933. #endif
  1934. }
  1935.  
  1936. #ifdef NO_AUTO_OVERLOAD
  1937. /* Check to see if NAME is overloaded. For first approximation,
  1938.    check to see if its TREE_OVERLOADED is set.  This is used on
  1939.    IDENTIFIER nodes.  */
  1940. int
  1941. is_overloaded (name)
  1942.      tree name;
  1943. {
  1944.   /* @@ */
  1945.   return (TREE_OVERLOADED (name)
  1946.       && (! IDENTIFIER_CLASS_VALUE (name) || current_class_type == 0)
  1947.       && ! IDENTIFIER_LOCAL_VALUE (name));
  1948. }
  1949. #endif
  1950.  
  1951. /* Given a tree_code CODE, and some arguments (at least one),
  1952.    attempt to use an overloaded operator on the arguments.
  1953.  
  1954.    For unary operators, only the first argument need be checked.
  1955.    For binary operators, both arguments may need to be checked.
  1956.  
  1957.    Member functions can convert class references to class pointers,
  1958.    for one-level deep indirection.  More than that is not supported.
  1959.    Operators [](), ()(), and ->() must be member functions.
  1960.  
  1961.    We call function call building calls with nonzero complain if
  1962.    they are our only hope.  This is true when we see a vanilla operator
  1963.    applied to something of aggregate type.  If this fails, we are free to
  1964.    return `error_mark_node', because we will have reported the error.
  1965.  
  1966.    Operators NEW and DELETE overload in funny ways: operator new takes
  1967.    a single `size' parameter, and operator delete takes a pointer to the
  1968.    storage being deleted.  When overloading these operators, success is
  1969.    assumed.  If there is a failure, report an error message and return
  1970.    `error_mark_node'.  */
  1971.  
  1972. /* NOSTRICT */
  1973. tree
  1974. build_opfncall (code, flags, xarg1, xarg2, arg3)
  1975.      enum tree_code code;
  1976.      tree xarg1, xarg2;
  1977.      tree arg3;
  1978. {
  1979.   tree rval = 0;
  1980.   tree arg1, arg2;
  1981.   tree type1, type2, fnname;
  1982.   tree fields1 = 0, parms = 0;
  1983.   tree global_fn;
  1984.   int try_second;
  1985.   int binary_is_unary;
  1986.  
  1987.   if (xarg1 == error_mark_node)
  1988.     return error_mark_node;
  1989.  
  1990.   if (code == COND_EXPR)
  1991.     {
  1992.       if (TREE_CODE (xarg2) == ERROR_MARK
  1993.       || TREE_CODE (arg3) == ERROR_MARK)
  1994.     return error_mark_node;
  1995.     }
  1996.   if (code == COMPONENT_REF)
  1997.     if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE)
  1998.       return rval;
  1999.  
  2000.   /* First, see if we can work with the first argument */
  2001.   type1 = TREE_TYPE (xarg1);
  2002.  
  2003.   /* Some tree codes have length > 1, but we really only want to
  2004.      overload them if their first argument has a user defined type.  */
  2005.   switch (code)
  2006.     {
  2007.     case PREINCREMENT_EXPR:
  2008.       code = POSTINCREMENT_EXPR;
  2009.       binary_is_unary = 1;
  2010.       try_second = 0;
  2011.       break;
  2012.  
  2013.     case POSTDECREMENT_EXPR:
  2014.       code = PREDECREMENT_EXPR;
  2015.       binary_is_unary = 1;
  2016.       try_second = 0;
  2017.       break;
  2018.  
  2019.     case PREDECREMENT_EXPR:
  2020.     case POSTINCREMENT_EXPR:
  2021.     case COMPONENT_REF:
  2022.       binary_is_unary = 1;
  2023.       try_second = 0;
  2024.       break;
  2025.  
  2026.       /* ARRAY_REFs and CALL_EXPRs must overload successfully.
  2027.      If they do not, return error_mark_node instead of NULL_TREE.  */
  2028.     case ARRAY_REF:
  2029.       if (xarg2 == error_mark_node)
  2030.     return error_mark_node;
  2031.     case CALL_EXPR:
  2032.       rval = error_mark_node;
  2033.       binary_is_unary = 0;
  2034.       try_second = 0;
  2035.       break;
  2036.  
  2037.     case NEW_EXPR:
  2038.       {
  2039.     /* For operators `new' (`delete'), only check visibility
  2040.        if we are in a constructor (destructor), and we are
  2041.        allocating for that constructor's (destructor's) type.  */
  2042.  
  2043.     fnname = get_identifier (OPERATOR_NEW_FORMAT);
  2044.     if (flags & LOOKUP_GLOBAL)
  2045.       return build_overload_call (fnname, tree_cons (NULL_TREE, xarg2, arg3),
  2046.                       flags & LOOKUP_COMPLAIN, 0);
  2047.  
  2048.     if (current_function_decl == NULL_TREE
  2049.         || !DECL_CONSTRUCTOR_P (current_function_decl)
  2050.         || current_class_type != TYPE_MAIN_VARIANT (type1))
  2051.       flags = LOOKUP_COMPLAIN;
  2052.     rval = build_method_call (build1 (NOP_EXPR, xarg1, error_mark_node),
  2053.                   fnname, tree_cons (NULL_TREE, xarg2, arg3),
  2054.                   NULL_TREE, flags);
  2055.     if (rval == error_mark_node)
  2056.       /* User might declare fancy operator new, but invoke it
  2057.          like standard one.  */
  2058.       return rval;
  2059.  
  2060.     TREE_TYPE (rval) = xarg1;
  2061.     TREE_CALLS_NEW (rval) = 1;
  2062.     return rval;
  2063.       }
  2064.       break;
  2065.  
  2066.     case DELETE_EXPR:
  2067.       {
  2068.     /* See comment above.  */
  2069.  
  2070.     fnname = get_identifier (OPERATOR_DELETE_FORMAT);
  2071.     if (flags & LOOKUP_GLOBAL)
  2072.       return build_overload_call (fnname, build_tree_list (NULL_TREE, xarg1),
  2073.                       flags & LOOKUP_COMPLAIN, 0);
  2074.  
  2075.     if (current_function_decl == NULL_TREE
  2076.         || !DESTRUCTOR_NAME_P (DECL_NAME (current_function_decl))
  2077.         || current_class_type != TYPE_MAIN_VARIANT (type1))
  2078.       flags = LOOKUP_COMPLAIN;
  2079.     rval = build_method_call (build1 (NOP_EXPR, TREE_TYPE (xarg1), error_mark_node),
  2080.                   fnname, build_tree_list (NULL_TREE, xarg1),
  2081.                   NULL_TREE, flags);
  2082.     /* This happens when the user mis-declares `operator delete'.
  2083.        Should now be impossible.  */
  2084.     assert (rval != error_mark_node);
  2085.     TREE_TYPE (rval) = void_type_node;
  2086.     return rval;
  2087.       }
  2088.       break;
  2089.  
  2090.     default:
  2091.       binary_is_unary = 0;
  2092.       try_second = tree_code_length [(int) code] == 2;
  2093.       if (try_second && xarg2 == error_mark_node)
  2094.     return error_mark_node;
  2095.       break;
  2096.     }
  2097.  
  2098.   if (try_second && xarg2 == error_mark_node)
  2099.     return error_mark_node;
  2100.  
  2101.   /* What ever it was, we do not know how to deal with it.  */
  2102.   if (type1 == NULL_TREE)
  2103.     return rval;
  2104.  
  2105.   if (TREE_CODE (type1) == OFFSET_TYPE)
  2106.     type1 = TREE_TYPE (type1);
  2107.  
  2108.   if (TREE_CODE (type1) == REFERENCE_TYPE)
  2109.     {
  2110.       arg1 = convert_from_reference (xarg1);
  2111.       type1 = TREE_TYPE (arg1);
  2112.     }
  2113.   else
  2114.     {
  2115.       arg1 = xarg1;
  2116.     }
  2117.  
  2118.   if (!IS_AGGR_TYPE (type1))
  2119.     {
  2120.       /* Try to fail. First, fail if unary */
  2121.       if (! try_second)
  2122.     return rval;
  2123.       /* Second, see if second argument is non-aggregate. */
  2124.       type2 = TREE_TYPE (xarg2);
  2125.       if (TREE_CODE (type2) == OFFSET_TYPE)
  2126.     type2 = TREE_TYPE (type2);
  2127.       if (TREE_CODE (type2) == REFERENCE_TYPE)
  2128.     {
  2129.       arg2 = convert_from_reference (xarg2);
  2130.       type2 = TREE_TYPE (arg2);
  2131.     }
  2132.       else
  2133.     {
  2134.       arg2 = xarg2;
  2135.     }
  2136.  
  2137.       if (!IS_AGGR_TYPE (type2))
  2138.     return rval;
  2139.       try_second = 0;
  2140.     }
  2141.  
  2142.   if (try_second)
  2143.     {
  2144.       /* First arg may succeed; see whether second should.  */
  2145.       type2 = TREE_TYPE (xarg2);
  2146.       if (TREE_CODE (type2) == OFFSET_TYPE)
  2147.     type2 = TREE_TYPE (type2);
  2148.       if (TREE_CODE (type2) == REFERENCE_TYPE)
  2149.     {
  2150.       arg2 = convert_from_reference (xarg2);
  2151.       type2 = TREE_TYPE (arg2);
  2152.     }
  2153.       else
  2154.     {
  2155.       arg2 = xarg2;
  2156.     }
  2157.  
  2158.       if (! IS_AGGR_TYPE (type2))
  2159.     try_second = 0;
  2160.     }
  2161.  
  2162.   if (type1 == unknown_type_node
  2163.       || (try_second && TREE_TYPE (xarg2) == unknown_type_node))
  2164.     {
  2165.       /* This will not be implemented in the forseeable future.  */
  2166.       return rval;
  2167.     }
  2168.  
  2169.   if (code == MODIFY_EXPR)
  2170.     {
  2171.       tree op_id = build_opid (MODIFY_EXPR, arg3);
  2172.       fnname = build_operator_fnname (&op_id, 0, 2);
  2173.     }
  2174.   else
  2175.     {
  2176.       tree op_id = build_opid (0, code);
  2177.       if (binary_is_unary)
  2178.     fnname = build_operator_fnname (&op_id, 0, 1);
  2179.       else
  2180.     fnname = build_operator_fnname (&op_id, 0,
  2181.                     tree_code_length [(int) code]);
  2182.     }
  2183.  
  2184.   global_fn = IDENTIFIER_GLOBAL_VALUE (fnname);
  2185.  
  2186.   /* This is the last point where we will accept failure.  This
  2187.      may be too eager if we wish an overloaded operator not to match,
  2188.      but would rather a normal operator be called on a type-converted
  2189.      argument.  */
  2190.  
  2191.   if (IS_AGGR_TYPE (type1))
  2192.     fields1 = lookup_fnfields (CLASSTYPE_AS_LIST (type1), fnname, 0);
  2193.  
  2194.   if (fields1 == NULL_TREE && global_fn == NULL_TREE)
  2195.     return rval;
  2196.  
  2197.   /* If RVAL winds up being `error_mark_node', we will return
  2198.      that... There is no way that normal semantics of these
  2199.      operators will succeed.  */
  2200.  
  2201.   /* This argument may be an uncommited OFFSET_REF.  This is
  2202.      the case for example when dealing with static class members
  2203.      which are referenced from their class name rather than
  2204.      from a class instance.  */
  2205.   if (TREE_CODE (xarg1) == OFFSET_REF
  2206.       && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL)
  2207.     xarg1 = TREE_OPERAND (xarg1, 1);
  2208.   if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF
  2209.       && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL)
  2210.     xarg2 = TREE_OPERAND (xarg2, 1);
  2211.  
  2212.   if (global_fn)
  2213.     flags |= LOOKUP_GLOBAL;
  2214.  
  2215.   if (code == CALL_EXPR)
  2216.     {
  2217.       /* This can only be a member function.  */
  2218.       return build_method_call (xarg1, fnname, xarg2,
  2219.                 NULL_TREE, LOOKUP_NORMAL);
  2220.     }
  2221.   else if (tree_code_length[(int) code] == 1 || binary_is_unary)
  2222.     {
  2223.       parms = NULL_TREE;
  2224.       rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags);
  2225.     }
  2226.   else if (code == COND_EXPR)
  2227.     {
  2228.       parms = tree_cons (0, xarg2, build_tree_list (0, arg3));
  2229.       rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
  2230.     }
  2231.   else if (code == METHOD_CALL_EXPR)
  2232.     {
  2233.       /* must be a member function.  */
  2234.       parms = tree_cons (NULL_TREE, xarg2, arg3);
  2235.       return build_method_call (xarg1, fnname, parms, NULL_TREE, LOOKUP_NORMAL);
  2236.     }
  2237.   else if (fields1)
  2238.     {
  2239.       parms = build_tree_list (NULL_TREE, xarg2);
  2240.       rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
  2241.     }
  2242.   else
  2243.     {
  2244.       parms = tree_cons (NULL_TREE, xarg1,
  2245.              build_tree_list (NULL_TREE, xarg2));
  2246.       rval = build_overload_call (fnname, parms, flags & LOOKUP_COMPLAIN, 0);
  2247.     }
  2248.  
  2249.   /* If we did not win, do not lose yet, since type conversion may work.  */
  2250.   if (TREE_CODE (rval) == ERROR_MARK)
  2251.     {
  2252.       if (flags & LOOKUP_COMPLAIN)
  2253.     return rval;
  2254.       return 0;
  2255.     }
  2256.  
  2257.   return rval;
  2258. }
  2259.  
  2260. /* This function takes an identifier, ID, and attempts to figure out what
  2261.    it means. There are a number of possible scenarios, presented in increasing
  2262.    order of hair:
  2263.  
  2264.    1) not in a class's scope
  2265.    2) in class's scope, member name of the class's method
  2266.    3) in class's scope, but not a member name of the class
  2267.    4) in class's scope, member name of a class's variable
  2268.  
  2269.    NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
  2270.    VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
  2271.    yychar is the pending input character (suitably encoded :-).
  2272.  
  2273.    As a last ditch, try to look up the name as a label and return that
  2274.    address.
  2275.  
  2276.    Values which are declared as being of REFERENCE_TYPE are
  2277.    automatically dereferenced here (as a hack to make the
  2278.    compiler faster).  */
  2279.  
  2280. tree
  2281. hack_identifier (value, name, yychar)
  2282.      tree value, name;
  2283. {
  2284.   tree type;
  2285.  
  2286.   if (TREE_CODE (value) == ERROR_MARK)
  2287.     {
  2288.       if (current_class_name)
  2289.     {
  2290.       tree fields = lookup_fnfields (CLASSTYPE_AS_LIST (current_class_type), name, 0);
  2291.       if (fields)
  2292.         {
  2293.           tree fndecl;
  2294.  
  2295.           fndecl = TREE_VALUE (fields);
  2296.           assert (TREE_CODE (fndecl) == FUNCTION_DECL);
  2297.           if (DECL_CHAIN (fndecl) == NULL_TREE)
  2298.         {
  2299.           warning ("methods cannot be converted to function pointers");
  2300.           return fndecl;
  2301.         }
  2302.           else
  2303.         {
  2304.           error ("ambiguous request for method pointer `%s'",
  2305.              IDENTIFIER_POINTER (name));
  2306.           return error_mark_node;
  2307.         }
  2308.         }
  2309.     }
  2310.       if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
  2311.     {
  2312.       return IDENTIFIER_LABEL_VALUE (name);
  2313.     }
  2314.       return error_mark_node;
  2315.     }
  2316.  
  2317.   type = TREE_TYPE (value);
  2318.   if (TREE_CODE (value) == FIELD_DECL)
  2319.     {
  2320.       if (current_class_decl == NULL_TREE)
  2321.     {
  2322.       error ("request for member `%s' in static member function",
  2323.          IDENTIFIER_POINTER (DECL_NAME (value)));
  2324.       return error_mark_node;
  2325.     }
  2326.       TREE_USED (current_class_decl) = 1;
  2327.       if (yychar == '(')
  2328.     if (! ((TYPE_LANG_SPECIFIC (type)
  2329.         && TYPE_OVERLOADS_CALL_EXPR (type))
  2330.            || (TREE_CODE (type) == REFERENCE_TYPE
  2331.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  2332.            && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (type))))
  2333.         && TREE_CODE (type) != FUNCTION_TYPE
  2334.         && TREE_CODE (type) != METHOD_TYPE
  2335.         && (TREE_CODE (type) != POINTER_TYPE
  2336.         || (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
  2337.             && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)))
  2338.       {
  2339.         error ("component `%s' is not a method",
  2340.            IDENTIFIER_POINTER (name));
  2341.         return error_mark_node;
  2342.       }
  2343.       /* Mark so that if we are in a constructor, and then find that
  2344.      this field was initialized by a base initializer,
  2345.      we can emit an error message.  */
  2346.       TREE_USED (value) = 1;
  2347.       return build_component_ref (C_C_D, name, 0, 1);
  2348.     }
  2349.   if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && TREE_NONLOCAL (value))
  2350.     {
  2351.       if (DECL_CONTEXT (value) != current_class_type)
  2352.     {
  2353.       tree path;
  2354.       enum visibility_type visibility;
  2355.  
  2356.       get_base_distance (DECL_CONTEXT (value), current_class_type, 0, &path);
  2357.       visibility = compute_visibility (path, value);
  2358.       if (visibility != visibility_public)
  2359.         {
  2360.           if (TREE_CODE (value) == VAR_DECL)
  2361.         error ("static member `%s' is from private base class",
  2362.                IDENTIFIER_POINTER (name));
  2363.           else
  2364.         error ("enum `%s' is from private base class",
  2365.                IDENTIFIER_POINTER (name));
  2366.           return error_mark_node;
  2367.         }
  2368.     }
  2369.       return value;
  2370.     }
  2371.   if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
  2372.     {
  2373.       if (type == 0)
  2374.     {
  2375.       error ("request for member `%s' is ambiguous in multiple inheritance lattice",
  2376.          IDENTIFIER_POINTER (name));
  2377.       return error_mark_node;
  2378.     }
  2379.  
  2380.       return value;
  2381.     }
  2382.  
  2383.   if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && ! TREE_USED (value))
  2384.     {
  2385.       if (TREE_EXTERNAL (value))
  2386.     assemble_external (value);
  2387.       TREE_USED (value) = 1;
  2388.     }
  2389.   if (TREE_CODE (type) == REFERENCE_TYPE)
  2390.     {
  2391.       assert (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL);
  2392.       if (DECL_REFERENCE_SLOT (value))
  2393.     return DECL_REFERENCE_SLOT (value);
  2394.     }
  2395.   return value;
  2396. }
  2397.  
  2398. tree
  2399. hack_operator (op)
  2400.      tree op;
  2401. {
  2402.   if (op == NULL_TREE)
  2403.     return error_mark_node;
  2404.  
  2405.   if (TREE_CODE (op) != TYPE_EXPR)
  2406.     return grokopexpr (&op, NULL_TREE, 0, 0, 0);
  2407.  
  2408.   return op;
  2409. }
  2410.  
  2411. /* NONWRAPPER is nonzero if this call is not to be wrapped.
  2412.    TYPE is the type that the wrapper belongs to (in case
  2413.    it should be non-virtual).
  2414.    DECL is the function will will be (not be) wrapped.  */
  2415. tree
  2416. hack_wrapper (nonwrapper, type, decl)
  2417.      int nonwrapper;
  2418.      tree type, decl;
  2419. {
  2420.   if (type == NULL_TREE || is_aggr_typedef (type, 1))
  2421.     {
  2422.       if (type)
  2423.     type = TREE_TYPE (type);
  2424.  
  2425.       switch (nonwrapper)
  2426.     {
  2427.     case 0:
  2428.       return build_nt (WRAPPER_EXPR, type, decl);
  2429.     case 1:
  2430.       return build_nt (ANTI_WRAPPER_EXPR, type, decl);
  2431.     case 2:
  2432.       return build_nt (WRAPPER_EXPR, type,
  2433.                build_nt (COND_EXPR, decl, NULL_TREE, NULL_TREE));
  2434.     default:
  2435.       assert (0 <= nonwrapper && nonwrapper <= 2);
  2436.     }
  2437.     }
  2438.   return error_mark_node;
  2439. }
  2440.  
  2441. /* Return an IDENTIFIER which can be used as a name for
  2442.    anonymous structs and unions.  */
  2443. tree
  2444. make_anon_name ()
  2445. {
  2446.   static int cnt = 0;
  2447.   char buf[32];
  2448.  
  2449.   sprintf (buf, ANON_AGGRNAME_FORMAT, cnt++);
  2450.   return get_identifier (buf);
  2451. }
  2452.  
  2453. /* Given an object OF, and a type conversion operator COMPONENT
  2454.    build a call to the conversion operator, if a call is requested,
  2455.    or return the address (as a pointer to member function) if one is not.
  2456.  
  2457.    OF can be a TYPE_DECL or any kind of datum that would normally
  2458.    be passed to `build_component_ref'.  It may also be NULL_TREE,
  2459.    in which case `current_class_type' and `current_class_decl'
  2460.    provide default values.
  2461.  
  2462.    BASETYPE_PATH, if non-null, is the path of basetypes
  2463.    to go through before we get the the instance of interest.
  2464.  
  2465.    PROTECT says whether we apply C++ scoping rules or not.  */
  2466. tree
  2467. build_component_type_expr (of, component, basetype_path, protect)
  2468.      tree of, component, basetype_path;
  2469.      int protect;
  2470. {
  2471.   tree cname = NULL_TREE;
  2472.   tree tmp, last;
  2473.   tree name;
  2474.   int flags = protect ? LOOKUP_NORMAL : LOOKUP_COMPLAIN;
  2475.  
  2476.   assert (IS_AGGR_TYPE (TREE_TYPE (of)));
  2477.   assert (TREE_CODE (component) == TYPE_EXPR);
  2478.  
  2479.   tmp = TREE_OPERAND (component, 0);
  2480.   last = NULL_TREE;
  2481.  
  2482.   while (tmp)
  2483.     {
  2484.       switch (TREE_CODE (tmp))
  2485.     {
  2486.     case CALL_EXPR:
  2487.       if (last)
  2488.         TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
  2489.       else
  2490.         TREE_OPERAND (component, 0) = TREE_OPERAND (tmp, 0);
  2491.       if (TREE_OPERAND (tmp, 0)
  2492.           && TREE_OPERAND (tmp, 0) != void_list_node)
  2493.         {
  2494.           error ("operator <typename> requires empty parameter list");
  2495.           TREE_OPERAND (tmp, 0) = NULL_TREE;
  2496.         }
  2497.       last = groktypename (build_tree_list (TREE_TYPE (component),
  2498.                         TREE_OPERAND (component, 0)));
  2499.       name = build_typename_overload (last);
  2500.       TREE_TYPE (name) = last;
  2501.  
  2502.       if (of && TREE_CODE (of) != TYPE_DECL)
  2503.         return build_method_call (of, name, NULL_TREE, NULL_TREE, flags);
  2504.       else if (of)
  2505.         {
  2506.           tree this_this;
  2507.  
  2508.           if (current_class_decl == NULL_TREE)
  2509.         {
  2510.           error ("object required for `operator <typename>' call");
  2511.           return error_mark_node;
  2512.         }
  2513.  
  2514.           this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl);
  2515.           return build_method_call (this_this, name, NULL_TREE,
  2516.                     NULL_TREE, flags | LOOKUP_NONVIRTUAL);
  2517.         }
  2518.       else if (current_class_decl)
  2519.         return build_method_call (tmp, name, NULL_TREE, NULL_TREE, flags);
  2520.  
  2521.       error ("object required for `operator <typename>' call");
  2522.       return error_mark_node;
  2523.  
  2524.     case INDIRECT_REF:
  2525.     case ADDR_EXPR:
  2526.     case ARRAY_REF:
  2527.       break;
  2528.  
  2529.     case SCOPE_REF:
  2530.       assert (cname == 0);
  2531.       cname = TREE_OPERAND (tmp, 0);
  2532.       tmp = TREE_OPERAND (tmp, 1);
  2533.       break;
  2534.  
  2535.     default:
  2536.       abort ();
  2537.     }
  2538.       last = tmp;
  2539.       tmp = TREE_OPERAND (tmp, 0);
  2540.     }
  2541.  
  2542.   last = groktypename (build_tree_list (TREE_TYPE (component), TREE_OPERAND (component, 0)));
  2543.   name = build_typename_overload (last);
  2544.   TREE_TYPE (name) = last;
  2545.   if (of && TREE_CODE (of) == TYPE_DECL)
  2546.     {
  2547.       if (cname == NULL_TREE)
  2548.     {
  2549.       cname = DECL_NAME (of);
  2550.       of = NULL_TREE;
  2551.     }
  2552.       else assert (cname == DECL_NAME (of));
  2553.     }
  2554.  
  2555.   if (of)
  2556.     {
  2557.       tree this_this;
  2558.  
  2559.       if (current_class_decl == NULL_TREE)
  2560.     {
  2561.       error ("object required for `operator <typename>' call");
  2562.       return error_mark_node;
  2563.     }
  2564.  
  2565.       this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl);
  2566.       return build_component_ref (this_this, name, 0, protect);
  2567.     }
  2568.   else if (cname)
  2569.     return build_offset_ref (cname, name);
  2570.   else if (current_class_name)
  2571.     return build_offset_ref (current_class_name, name);
  2572.  
  2573.   error ("object required for `operator <typename>' member reference");
  2574.   return error_mark_node;
  2575. }
  2576.